2026-03-02 3:42 AM
Greetings!
So I have a personal project, using a STM32U585 MCU, with a self-designed board, in which I have a bootloader and the main firmware.
So basically I implemented a protocol for communicating with the board, I have a C program that sends a command and the board sends data (around 20Kb), using USB.
The scenario is the following: I flash the firmware with the bootloader, after flashing, the bootloader jumps into the main program and starts running, I send a command (via host) to get data and the board sends me data and everything is running smoothly. The problem starts when I unplug the board and plug it again, when I send the command to get data, the board starts to send it and then it completely freezes.
Another curiosity, this situation only happens when I plug the board in a USB hub... if I plug the board directly to the laptop, I won't have any problem.
Any clue of what can be the problem? Power related? Is there any issue with the jump to the main program?
Best regards!
Solved! Go to Solution.
2026-03-02 4:11 AM
> The problem starts when I unplug the board and plug it again, when I send the command to get data, the board starts to send it and then it completely freezes.
Sounds like a program bug.
Debug your program to find out what is happening. You can connect to a chip without resetting it if you modify the debug configuration to not download or reset the chip.
2026-03-02 4:11 AM
> The problem starts when I unplug the board and plug it again, when I send the command to get data, the board starts to send it and then it completely freezes.
Sounds like a program bug.
Debug your program to find out what is happening. You can connect to a chip without resetting it if you modify the debug configuration to not download or reset the chip.
2026-03-02 4:13 AM
@j_filipe wrote:I have a C program that sends a command
Are you sure that your program copes correctly with its COM port disappearing and reappearing?
2026-03-02 4:15 AM
@Andrew Neil I forgot to mention, I also close the program from the host and connect again. The thing is, this only happens when I connect the board to an USB hub...
2026-03-02 5:03 AM
1. Make sure you are calling the Transmit from an ISR of the same priority as the USB interrupt, NOT from main() or any function called form main().
2. Make sure you don't attempt to transmit anything until the connection is established - this is not exactly an easy thing with ST USB stack, cause Disconnect callback is called after the device is connected for the second time, not when it's disconnected. Also, you should ensure that CDC connection is established by handling the class requests.
2026-03-02 6:06 AM
@j_filipe wrote:this only happens when I connect the board to an USB hub...
Instrument your code so that you can see what happens differently between the working & non-working cases.
As @TDK said, you can connect to a running target without having to download or reset - see here.
2026-03-10 5:19 AM
@TDK
Yes, it was a program bug related to the jump from the bootloader to the main program. I was de-initialising some stuff that I shouldn't. Thank you anyway.
Best regards!