ChibiOS-Contrib USB_MSD testhal example crashes Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Location: Netherlands
Been thanked: 15 times
Contact:

ChibiOS-Contrib USB_MSD testhal example crashes

Postby piers » Tue Feb 02, 2021 4:42 pm

I'm building a (open source) bootloader using the USB MSD mass storage device driver from ChibiOS-Contrib.

However the MSD driver crashes when connecting to a MacOS or Windows machine. This happens both in the STM32F4 and the STM32H7 example (ChibiOS-Contrib/testhal/STM32/STM32F4xx/USB_MSD and ChibiOS-Contrib/testhal/STM32/STM32H7xx/USB_MSD).

The USB driver crashes in the EP0 setup because it's already transmitting:

Code: Select all

#1  0x08000f2a in usbStartTransmitI (usbp=0x800f6e8 <__func__.9137>, usbp@entry=0x2000d408 <USBD1>, ep=ep@entry=0 '\000', buf=0x800f734 <active_status> "", n=2) at ../../../../../ChibiOS/os/hal/src/hal_usb.c:498
498     osalDbgAssert(!usbGetTransmitStatusI(usbp, ep), "already transmitting");


Backtrace:

Code: Select all

#0  chSysHalt (reason=reason@entry=0x800f6e8 <__func__.9137> "usbStartTransmitI") at ../../../../../ChibiOS/os/rt/src/chsys.c:205
#1  0x08000f2a in usbStartTransmitI (usbp=0x800f6e8 <__func__.9137>, usbp@entry=0x2000d408 <USBD1>, ep=ep@entry=0 '\000', buf=0x800f734 <active_status> "", n=2) at ../../../../../ChibiOS/os/hal/src/hal_usb.c:498
#2  0x080011c2 in _usb_ep0setup (usbp=0x2000d408 <USBD1>, ep=<optimized out>) at ../../../../../ChibiOS/os/hal/src/hal_usb.c:834
#3  0x080024b2 in otg_epout_handler (ep=ep@entry=0 '\000', usbp=0x2000d408 <USBD1>) at ../../../../../ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:427
#4  0x080027ca in usb_lld_serve_interrupt (usbp=0x2000d408 <USBD1>) at ../../../../../ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:611
#5  Vector14C () at ../../../../../ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:685
#6  <signal handler called>
#7  0x55555554 in ?? ()


My own project (on STM32H7) crashes in a similar way in EP0, but because it's already receiving:

Code: Select all

#1  0x08001d86 in usbStartReceiveI (usbp=0x24000448 <USBD1>, ep=0 '\000', buf=0x0, n=0) at ./ChibiOS/os/hal/src/hal_usb.c:459
459     osalDbgAssert(!usbGetReceiveStatusI(usbp, ep), "already receiving");


Backtrace:

Code: Select all

#0  0x08005224 in chSysHalt (reason=0x8009910 <__func__.10090> "usbStartReceiveI") at ./ChibiOS/os/rt/src/chsys.c:198
#1  0x08001d86 in usbStartReceiveI (usbp=0x24000448 <USBD1>, ep=0 '\000', buf=0x0, n=0) at ./ChibiOS/os/hal/src/hal_usb.c:459
#2  0x0800241e in _usb_ep0in (usbp=0x24000448 <USBD1>, ep=0 '\000') at ./ChibiOS/os/hal/src/hal_usb.c:909
#3  0x08003a76 in otg_epin_handler (usbp=0x24000448 <USBD1>, ep=0 '\000') at ./ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:399
#4  0x0800403e in usb_lld_serve_interrupt (usbp=0x24000448 <USBD1>) at ./ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:641
#5  0x080040f2 in Vector1D4 () at ./ChibiOS/os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:685
#6  <signal handler called>
#7  0x55555554 in ?? ()


With linux the MSD driver does work, only 'sudo lsusb -v -d 0483:5740' gives errors for the string descriptors and gives the following errors:

Code: Select all

can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
cannot read device status, Resource temporarily unavailable (11)


I'm using gcc version 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (15:9-2019-q4-0ubuntu1)

Any ideas what might be wrong?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS-Contrib USB_MSD testhal example crashes

Postby Giovanni » Tue Feb 02, 2021 5:07 pm

Hi,

Those assertions are triggered if the MSD driver tries to do something in the wrong moment, see that "already transmitting", not sure about the reason. It is possible that the code is very old and some change broke it.

Giovanni

User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Location: Netherlands
Been thanked: 15 times
Contact:

Re: ChibiOS-Contrib USB_MSD testhal example crashes

Postby piers » Tue Feb 02, 2021 5:22 pm

Thanks for your quick answer. To me it seems that the EP0 code is all handled in ChibiOS, in hal_usb.c. So I don't understand how the MSD code (which uses EP1) could cause an EP0 related crash? Any ideas?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: ChibiOS-Contrib USB_MSD testhal example crashes  Topic is solved

Postby Giovanni » Tue Feb 02, 2021 6:18 pm

The EP0 state machines calls handlers that are part of upper layers that handle protocol messages, it is possible there is a problem in those handlers.

Giovanni

User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Location: Netherlands
Been thanked: 15 times
Contact:

Re: ChibiOS-Contrib USB_MSD testhal example crashes

Postby piers » Wed Feb 03, 2021 10:04 am

Ah, I see. The problem probably is in msd_request_hook then. If I comment that out is usbcfg.c it doesn't crash, I'll look into that further.

lsusb still gives errors for the device qualifier and debug qualifier. I'm not sure if that can be a problem, but it seems nice to not have errors. Any ideas on how to prevent those errors?

User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Location: Netherlands
Been thanked: 15 times
Contact:

Re: ChibiOS-Contrib USB_MSD testhal example crashes

Postby piers » Fri Feb 05, 2021 5:42 pm

Ok, it is fixed in ChibiOS-Contrib now, I reimplemented the msd_request_hook function, though the default reaction without custom request handler seems valid also. Stalling on get_max_lun at least. The Bulk-Only Mass Storage Reset is not commonly used apparently, so I'm not sure about that.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 25 guests