2025-10-28 1:40 AM
Hello everyone.
How do I update the firmware via VCP on STM32F407VET6? Is it possible to do so? If so, what needs to be changed and added? Do I have to recreate the bootloader?
I don't know where to start here.
Thank you :)
Solved! Go to Solution.
2025-10-29 10:55 AM - edited 2025-10-29 11:22 AM
.
2025-10-29 11:26 AM
@No_Name wrote:In AN2606, I couldn't find anything about VCP.
Indeed not - I think @Shirley.Ye was mistaken or misunderstood the question there.
@No_Name wrote:I have watched this YouTube video: https://youtu.be/wirNEpE6Dd4?si=0Lg5UnYFfRsD4mT8, where he customizes the bootloader to enable DFU.
That's a custom bootloader - not the System bootloader.
@No_Name wrote:my application on the host is built with a VCP driver for this purpose, and I'm looking for a way to update the firmware without having to switch the driver to DFU.
That makes sense.
So, as suggested earlier, you could look at AN4657, and just change the transport from UART to VCP.
Or look at the ST Open Bootloader.
Or any 3rd-party bootloader.
2025-10-29 12:25 PM
It seems that I have to create a protocol and a special bootloader for firmware updates via VCP using HAL Flash for firmware updates. I have never tried HAL Flash before, but is HAL Flash safe for updating firmware larger than 400> kb via a custom bootloader 0x8000000 64kb?
2025-10-29 3:16 PM - edited 2025-10-29 3:17 PM
You'd likely need to code the VCP Device, and pipe the connection to an IAP implementation running concurrently.
While the X/Y-MODEM protocol provides for some pacing/flow-control, the bigger problem I see with doing this with USB is that the FLASH stalls the processor in a way very unfriendly to real-time USB servicing. You might be able to side-step this via running the VCP/IAP in RAM, but would take a lot of work.
Normally IAP can use a UART directly, or use SD Card, Ethernet, etc
ST has examples of a USB-DFU device, but you have to use their Windows side application.
If you have enough RAM your could use a USB-MSC to create a ramdisk to hold the new image.
The STM32F4 sector erase times are very high.
2025-10-29 3:56 PM
I found a repository on GitHub https://github.com/Karim-Bouanane/Custom-Bootloader-for-STM32-Black-Pill-using-USB-CDC about custom bootloaders and protocols for updating firmware via USB CDC VCP. It matches what I had previously thought about whether HAL_Flash could be used to update firmware, and the answer provided in this repository is very satisfying. I will try it and see what happens if the main application is complex enough.
Thank you :)
2025-10-30 1:49 AM
@No_Name wrote:It seems that I have to create a protocol and a special bootloader for firmware updates via VCP
Correct.
Although, as noted, you don't have to do all that from scratch - there are plenty of existing building blocks you can use.
@No_Name wrote:It seems that I have to ... using HAL Flash ?
You don't have to use HAL
@No_Name wrote:is HAL Flash safe for updating firmware larger than 400> kb via a custom bootloader 0x8000000 64kb?
No more nor less "safe" than any other way of doing it.
And, as @Tesla DeLorean said, beware that you can't be executing code from the same flash that you're erasing/programming...