2020-05-21 10:16 PM
Hello,
I have an application where I would like to switch the STM32G431KB into the built-in bootloader (using USB DFU) by sending a specific byte through the CDC Virtual COM port. I was able to get the unit into DFU mode by running the "USB_BootloaderInit" function below when a button is pressed, however when I try running the function upon reception of data from the CDC port, Windows either does not see the device or gives me a "Device Descriptor Request Failed" notification.
I get the feeling the USB port is still doing some work or there are interrupts still running, but I am not sure how to go about checking what is going on or properly clearing any pending interrupts, or what exactly is going on and I wanted to see if anyone could help point me in the right direction.
This is the function that allows me to enter into the bootloader:
void USB_BootloaderInit()
{
volatile uint32_t addr = 0x1FFF0000;
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4))); //Point the PC to the System Memory reset vector
HAL_RCC_DeInit(); //Reset the system clock
SysTick->CTRL = 0; //Reset the SysTick Timer
SysTick->LOAD = 0;
SysTick->VAL = 0;
__set_MSP(*(uint32_t *)addr);
SysMemBootJump();
while(1);
}
It is being called when the correct character is received through the CDC_Receive_FS function as part of the CubeIDE USB Device Middleware.
Currently, I have tried running the USBD_DeInit and USBD_Stop functions before the USB_BootloaderInit function, along with putting some delay (5ms - 1Second using timers) between the DeInit/Stop and BootloaderInit functions, with no avail.
Any help is appreciated
Solved! Go to Solution.
2020-06-09 12:01 AM
That was exactly it :)
The USB_BootloaderInit() really has to come as first statement after main()
Now I get:
Jun 9 08:57:44 blender kernel: [ 6316.198195] usb 11-4.4.2: new full-speed USB device number 7 using xhci_hcd
Jun 9 08:57:44 blender kernel: [ 6316.311684] usb 11-4.4.2: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 2.00
Jun 9 08:57:44 blender kernel: [ 6316.311687] usb 11-4.4.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 9 08:57:44 blender kernel: [ 6316.311688] usb 11-4.4.2: Product: STM32 Virtual ComPort
Jun 9 08:57:44 blender kernel: [ 6316.311689] usb 11-4.4.2: Manufacturer: STMicroelectronics
Jun 9 08:57:44 blender kernel: [ 6316.311690] usb 11-4.4.2: SerialNumber: 209F38943136
Jun 9 08:57:44 blender mtp-probe: checking bus 11, device 7: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 08:57:44 blender mtp-probe: bus: 11, device: 7 was not an MTP device
Jun 9 08:57:44 blender kernel: [ 6316.362221] cdc_acm 11-4.4.2:1.0: ttyACM1: USB ACM device
Jun 9 08:57:44 blender mtp-probe: checking bus 11, device 7: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 08:57:44 blender mtp-probe: bus: 11, device: 7 was not an MTP device
And then after 10 seconds as it should be:
Jun 9 08:57:56 blender kernel: [ 6328.522463] usb 11-4.4.2: USB disconnect, device number 7
Jun 9 08:57:56 blender kernel: [ 6328.786335] usb 11-4.4.2: new full-speed USB device number 8 using xhci_hcd
Jun 9 08:57:56 blender kernel: [ 6328.899373] usb 11-4.4.2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice= 2.00
Jun 9 08:57:56 blender kernel: [ 6328.899376] usb 11-4.4.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 9 08:57:56 blender kernel: [ 6328.899377] usb 11-4.4.2: Product: DFU in FS Mode
Jun 9 08:57:56 blender kernel: [ 6328.899378] usb 11-4.4.2: Manufacturer: STMicroelectronics
Jun 9 08:57:56 blender kernel: [ 6328.899379] usb 11-4.4.2: SerialNumber: 209F38943136
Jun 9 08:57:56 blender mtp-probe: checking bus 11, device 8: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 08:57:56 blender mtp-probe: bus: 11, device: 8 was not an MTP device
Jun 9 08:57:56 blender mtp-probe: checking bus 11, device 8: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 08:57:56 blender mtp-probe: bus: 11, device: 8 was not an MTP device
So trigger this via USB CDC should be a breeze then...
Now checking if it works on Nucleo-F070RB as well as this is the final target...
2020-06-09 01:02 AM
Great..also works now on my Nucleo-F070RB board....
The memory remapping is not needed though....so this is enough:
void USB_TriggerBootloader()
{
switchToBootloader = 0x11; //Set the noinit variable to be read by startup code
NVIC_SystemReset(); //Reset the system
}
And then I get after 10 seconds (forced by a RTC counter).
Jun 9 10:00:31 blender kernel: [10083.788685] usb 11-4.4.2: USB disconnect, device number 26
Jun 9 10:00:32 blender kernel: [10084.053214] usb 11-4.4.2: new full-speed USB device number 27 using xhci_hcd
Jun 9 10:00:32 blender kernel: [10084.166031] usb 11-4.4.2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice=22.00
Jun 9 10:00:32 blender kernel: [10084.166034] usb 11-4.4.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jun 9 10:00:32 blender kernel: [10084.166035] usb 11-4.4.2: Product: STM32 BOOTLOADER
Jun 9 10:00:32 blender kernel: [10084.166036] usb 11-4.4.2: Manufacturer: STMicroelectronics
Jun 9 10:00:32 blender kernel: [10084.166037] usb 11-4.4.2: SerialNumber: FFFFFFFEFFFF
Jun 9 10:00:32 blender mtp-probe: checking bus 11, device 27: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 10:00:32 blender mtp-probe: bus: 11, device: 27 was not an MTP device
Jun 9 10:00:32 blender mtp-probe: checking bus 11, device 27: "/sys/devices/pci0000:40/0000:40:07.1/0000:43:00.3/usb11/11-4/11-4.4/11-4.4.2"
Jun 9 10:00:32 blender mtp-probe: bus: 11, device: 27 was not an MTP device