stm32l4 usb device debug

196 views
Skip to first unread message

Arjun Hary

unread,
Aug 9, 2018, 8:59:39 PM8/9/18
to nu...@googlegroups.com
Hi,

I am working on the nucleo-ll452re board. I am trying to get USB device with mass storage on this board. I did the following.

1) I did a register comparison between the stm32l452 and stm32f303 which are usb device chips. The registers are exactly the same between them with addition of  battery charging registers on the stm32l4.
2) I ported the stm_usbdev.c from stm32 folder to the stm32l4 and fixed the interrupts and code and all the compile issues.
3) I compiled the USB msc driver with debug on nuttx and ran msconn and msdis. I am attaching the output from nsh. I don't see any mass storage device appear on the windows PC.

sh> mkrd -m 0 -s 512 64
nsh> mkfatfs /dev/ram0
nsh> msconn
mcsonn_main: Creating block drivers
After boardctl(BOARDIOC_USBDEV_CONTROL):
              total       used       free    largest
Before:     137376      45184      92192      69632
After:      137376      45184      92192      69632
mcsonn_main: Configuring with NLUNS=1
mcsonn_main: handle=100027e0
After usbmsc_configure():
              total       used       free    largest
Before:     137376      45184      92192      69632
After:      137376      45472      91904      69632
Change:        288 allocated
mcsonn_main: Bind LUN=0 to /dev/ram0
After usbmsc_bindlun():
              total       used       free    largest
Before:     137376      45472      91904      69632
After:      137376      46000      91376      69632
Change:        528 allocated
After usbmsc_exportluns():
              total       used       free    largest
Before:     137376      46000      91376      69632
After:      137376      50160      87216      69632
Change:       4160 allocated
mcsonn_main: Connected
After MS connection:
              total       used       free    largest
Before:     137376      50160      87216      69632
After:      137376      50160      87216      69632
DCD register         : Registered                               0000
Class bind           : Bind class                               0000
nsh> msdis
Since MS connection:
              total       used       free    largest
Before:     137376      50160      87216      69632
After:      137376      50160      87216      69632
msdis: Disconnected
After usbmsc_disconnect():
              total       used       free    largest
Before:     137376      50160      87216      69632
After:      137376      45184      92192      69632
Change:       4976 freed

Final memory usage:
              total       used       free    largest
Before:     137376      45184      92192      69632
After:      137376      45184      92192      69632
Class error        ae: USBMSC_TRACEERR_IDLERDREQLISTEMPTY       0000
DCD un-register      : Un-registered                            0000
Class disconnect     : Disconnect class                         0000
Class unbind         : Un-bind class                            0000
nsh>

Can you please point me to what is wrong or missing here and how to continue the debug. 

--
Arjun Hary
________________________________________
 : zGlue Inc., Mountain View, CA
________________________________________

Alan Carvalho de Assis

unread,
Aug 10, 2018, 5:16:48 AM8/10/18
to nu...@googlegroups.com
Hi Arjun,

Did you see some activity from the host side?

What does dmesg show when you run msconn?

Try to enable USB debug on NuttX.

The Linux kernel also have support for USB monitoring. It could give you hints about what is failing.

BR,

Alan
--
You received this message because you are subscribed to the Google Groups "NuttX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nuttx+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Sidrane

unread,
Aug 10, 2018, 8:52:33 AM8/10/18
to NuttX
Arjun,

Check the polarity of the bit that activates the pull up. ST changed this in later versions of the USB controler.

See the delta in the stm32 USB devices driver for the STM32F446

David


--
You received this message because you are subscribed to the Google Groups "NuttX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nuttx+un...@googlegroups.com.

patacongo

unread,
Aug 10, 2018, 8:12:23 PM8/10/18
to NuttX

Can you please point me to what is wrong or missing here and how to continue the debug. 

As Alan suggests, enabling USB debug might give some insight (but careful, USB debug output also often breaks the USB driver).

In my experience, anything but the most trivial USB bug is impossible to debug without a USB analyzer.

ar...@zglue.com

unread,
Aug 10, 2018, 8:46:42 PM8/10/18
to NuttX
Thanks guys for the inputs. I fixed a few more bugs. Got little further along. I am now seeing this message when i run msconn

EP allocreq          : Allocate endpoint request                0000
DCD allocep          : Allocate endpoint                        0083
DCD allocep          : Allocate endpoint                        0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
DCD selfpowered      : Self-powered                             0001
DCD pullup           : Soft connect                             0001
DCD pullup           : Soft connect                             0001


I still do not see the device on PC. Next step is a linux kernel monitor or usb analyzer. But does this prints make sense. Sorry for these question but i am new to the nuttx USB driver. 

Regards
Arjun

patacongo

unread,
Aug 10, 2018, 8:58:51 PM8/10/18
to NuttX

mcsonn_main: Connected
,,,

This is the device enumeration.  The device connection was  recognized by the host, the host sent some setup packets, the board provided its device and configuration descriptors.  The MSC class has been started and it initializing its endpoints.  All good.

DCD register         : Registered                               0000
Class bind           : Bind class                               0000
EP allocreq          : Allocate endpoint request                0000
DCD allocep          : Allocate endpoint                        0083
DCD allocep          : Allocate endpoint                        0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0002
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
EP allocreq          : Allocate endpoint request                0003
DCD selfpowered      : Self-powered                             0001

I don't understand this (not without looking at the code).  The enumeration would not have occurred unless the pullup were in the right state  The device should be invisible until it pulls up the data lines.  The host side should pull the data lines down (weakly), and the device should pull them up.  Then the host should recognize that something is connected and perform the enumeration.

DCD pullup           : Soft connect                             0001
DCD pullup           : Soft connect                             0001


I still do not see the device on PC. Next step is a linux kernel monitor or usb analyzer. But does this prints make sense. Sorry for these question but i am new to the nuttx USB driver. 

Yes, something seems backward.  The enumeration occurred BEFORE the pullup.  The communications stopped after the pullup.  Kind of seems reversed, right?  You should re-read David Sidrane's comment about the polarity of the pull-up control.

David Sidrane

unread,
Aug 11, 2018, 6:56:27 AM8/11/18
to NuttX
Arjun,

If it is that same sort of issue we had on the new USB block (F466,F469, F7 etc) It can be seen in nuttx/arch/arm/src/stm32/stm32_otgfsdev.c 

static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) look for code wrapped in 

#if defined(CONFIG_STM32_STM32F446) || defined(CONFIG_STM32_STM32F469)

Compare and contrast the bits, bit positions and their polarities in STM32_OTGFS_GCCFG and  STM32_OTGFS_GOTGCTL to what you see in the manual for the SoC you are using. 

David

ar...@zglue.com

unread,
Aug 13, 2018, 6:47:51 PM8/13/18
to NuttX
Turns out stupidity has no bounds. Thanks for the inputs David and Alan

1) I have the nucleo l452re board. I re-read the schematic and turns out the USB connector on that board is only connected to the stm32f013 or the st-link MCU. There is no USB connection to the stm32l452 chip. I ordered a breakout USB to test the USB connection
I will get the USB breakout try it and out and let you know how it goes.

@David: The stm32l452 is a USB device only chip. It has no OTG. 

Regards
Arjun

Juha Niskanen (Haltian)

unread,
Mar 29, 2019, 4:37:34 AM3/29/19
to NuttX


Hi Arjun,

Did you get this working? Is your code available somewhere? Could you please send patches to Mr. Greg? I might start with USB FS for STM32L452 soon and it would be waste of effort to do the register definitions and comparisons between STM32 subarchitectures again.

Best Regards,
   Juha Niskanen



From: nu...@googlegroups.com <nu...@googlegroups.com> on behalf of David Sidrane <david....@gmail.com>
Sent: Friday, August 10, 2018 3:52 PM
To: NuttX
Subject: Re: [nuttx] stm32l4 usb device debug
 
Reply all
Reply to author
Forward
0 new messages