SOLVED - STM32F4 USB Error

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
doublevee
Posts: 75
Joined: Mon Jul 02, 2018 11:09 pm

SOLVED - STM32F4 USB Error

Post by doublevee » Thu Jun 03, 2021 7:35 am

Hi all,

I have a strange issue which I am struggling to fix on product of mine that uses an STM32F411CE microcontroller.

Initially I had incorrectly configured HSE in the board config files, which I subsequently fixed with a simple correction to one of the clock divider values.

The board was then working perfectly and I have been developing the software since. However, a couple of days ago, I pushed a new main.py to the board and at that point lost comms (using the USB VCP interface).

The board correctly goes into DFU mode with no issue and is listed correctly when I issue dfu-util -l. I can then reapply the original firmware image without issue, but the USB interface is not at all happy, with a variety of error messages in dmesg. The device appears intermittently in the output of lsusb.

I am very much suspecting a clock issue again, as the board is fine going into DFU but seems unstable in normal USB operation.

I wondered what the collective wisdom of the forum makes of this issue. I’m unable to proceed with software development at this stage.

I have read about VBUS sensing, clock multipliers etc but something has changed since I pushed the last software file that the same firmware won’t fix. At least, this is my view of the issue but I am not an expert on the STM32 architecture.

Below is a sample of the dmesg output with the board plugged in:

[ 194.526699] usb 1-1: new full-speed USB device number 69 using xhci_hcd
[ 194.654785] usb 1-1: Device not responding to setup address.
[ 194.862720] usb 1-1: Device not responding to setup address.
[ 195.070666] usb 1-1: device not accepting address 69, error -71
[ 195.406486] usb 1-1: new full-speed USB device number 70 using xhci_hcd
[ 195.831698] usb 1-1: unable to read config index 0 descriptor/start: -71
[ 195.831708] usb 1-1: can't read configurations, error -71
[ 195.831800] usb usb1-port1: attempt power cycle
[ 196.690673] usb 1-1: new full-speed USB device number 71 using xhci_hcd
[ 196.690709] usb 1-1: Device not responding to setup address.
[ 196.898686] usb 1-1: Device not responding to setup address.
[ 197.106642] usb 1-1: device not accepting address 71, error -71
[ 197.442734] usb 1-1: new full-speed USB device number 72 using xhci_hcd
[ 197.465018] usb 1-1: New USB device found, idVendor=f055, idProduct=9800, bcdDevice= 2.00
[ 197.465024] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 197.465027] usb 1-1: Product: Pyboard Virtual Comm Port in FS Mode
[ 197.465030] usb 1-1: Manufacturer: MicroPython
[ 197.465032] usb 1-1: SerialNumber: 357337503230
[ 197.469841] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 197.470227] scsi host1: usb-storage 1-1:1.0
[ 197.470604] cdc_acm 1-1:1.1: ttyACM0: USB ACM device
[ 197.477836] usb 1-1: USB disconnect, device number 72
[ 197.810737] usb 1-1: new full-speed USB device number 73 using xhci_hcd
[ 197.938773] usb 1-1: Device not responding to setup address.
[ 198.146539] usb 1-1: Device not responding to setup address.
[ 198.354721] usb 1-1: device not accepting address 73, error -71
[ 198.690718] usb 1-1: new full-speed USB device number 74 using xhci_hcd
[ 199.116465] usb 1-1: New USB device found, idVendor=f055, idProduct=9800, bcdDevice= 2.00
[ 199.116471] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 199.116475] usb 1-1: Product: Pyboard Virtual Comm Port in FS Mode
[ 199.116478] usb 1-1: Manufacturer: MicroPython
[ 199.118703] usb 1-1: can't set config #1, error -71
[ 199.118905] usb 1-1: USB disconnect, device number 74
[ 199.462661] usb 1-1: new full-speed USB device number 75 using xhci_hcd
[ 199.888317] usb 1-1: New USB device found, idVendor=f055, idProduct=9800, bcdDevice= 2.00
[ 199.888323] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 199.888327] usb 1-1: Product: Pyboard Virtual Comm Port in FS Mode
[ 199.888330] usb 1-1: Manufacturer: MicroPython
[ 199.888332] usb 1-1: SerialNumber: 357337503230
[ 199.890320] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 199.890786] scsi host1: usb-storage 1-1:1.0
[ 199.891163] cdc_acm 1-1:1.1: ttyACM0: USB ACM device
[ 199.937516] usb 1-1: USB disconnect, device number 75
[ 200.270543] usb 1-1: new full-speed USB device number 76 using xhci_hcd
[ 200.398569] usb 1-1: Device not responding to setup address.
[ 200.606757] usb 1-1: Device not responding to setup address.

doublevee
Posts: 75
Joined: Mon Jul 02, 2018 11:09 pm

Re: SOLVED - STM32F4 USB Error

Post by doublevee » Thu Jun 03, 2021 8:37 pm

I have no idea what happened but I suspect there was corruption of the flash memory - I did have mass storage enabled which is a known weak point.

The device was fine in DFU mode, the firmware file was correct.

After the device failed, with the loss of USB comms, I put the board into DFU mode and downloaded the firmware again using dfu-util. This did not fix the issue. I tried this several times, but it remained exactly the same with the errors seen on the USB enumeration.

I then used STM Cube Programmer to do a full flash erase, and then downloaded the firmware again. This time all was well.

Although this is solved, I would really appreciate it if someone could briefly explain what might have happened here. I assumed that dfu-util would erase the device before writing.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: SOLVED - STM32F4 USB Error

Post by dhylands » Thu Jun 03, 2021 8:52 pm

When you flash the firmware, it avoids overwriting the filesystem.

You can do a mass erase (which erases the entire flash - firmware and filsystem) using df-util by using this script:
https://github.com/dhylands/upy-example ... s-erase.sh

doublevee
Posts: 75
Joined: Mon Jul 02, 2018 11:09 pm

Re: SOLVED - STM32F4 USB Error

Post by doublevee » Thu Jun 03, 2021 10:22 pm

Thank you Dave.

So I think I had a main.py that caused a system crash, that caused the USB to keep crashing and the non-erase download actually changed nothing as it simply replaced the firmware, ready for it all to start over again.

Post Reply