cancel
Showing results for 
Search instead for 
Did you mean: 

How to update firmware via VCP

No_Name
Associate III

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 :)

1 ACCEPTED SOLUTION

Accepted Solutions

@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...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

View solution in original post

15 REPLIES 15
Andrew Neil
Super User

@No_Name wrote:

Do I have to recreate the bootloader?


Yes.

The built-in System Bootloader uses DFU on USB - see: Application note AN2606Introduction to system memory boot mode on STM32 MCUs.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
john15
Associate

Yes, it’s possible but you’ll need a custom bootloader that supports updates over the virtual COM port. You can base it on ST’s USB CDC examples, just make sure your bootloader can receive the new firmware over USB and write it to flash memory. You don’t have to start from zero, get USB CDC communication working first, then add the flash write logic to handle the firmware update.
author : john wick
Founder: simulated game

 
 
 
Andrew Neil
Super User

As @john15 said, you don't have to start from zero.

As well as USB CDC examples, there is Application Note AN4657, STM32 in-application programming (IAP) using the USART,  which shows you the flash write logic, and suggests a suitable protocol (YMODEM) to use over the comms link - just replace the UART transport with your USB CDC...

 

PS:

X-CUBE-IAP-USART is the supporting code for AN4657.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Andrew Neil @john15 

Yes, I am using USB CDC for VCP. In which file is the bootloader system code stored?
syscalls.c?
sysmem.c?
system_stm32f4xx.c?

There is no ready-to-use VCP bootloader. You need to write it by yourself. Probably the easier option is to use DFU bootloader built into your MCU. Read AN2606 for more info.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

@No_Name wrote:

In which file is the bootloader system code stored?


as @gbm said, it's not in any source file - it's programmed into ROM at the factory.

Do you have a particular reason to do this via VCP rather than use the built-in DFU - which is, surely, the standard way to do firmware updates over USB?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Shirley.Ye
ST Employee

Hello,

you can use the bootloader inside the System memory to update the FW via VCP.

 

Read AN2606 to configure for the bootloader. usually need to configure the boot pin.

then in the cubeprogrammer choose UART,connected. VCP is communicating in UART communication.

then you can update the firmware.

ShirleyYe_0-1761733792395.png

 


@Shirley.Ye wrote:

you can use the bootloader inside the System memory to update the FW via VCP.


Can you? 

 


@Shirley.Ye wrote:

Read AN2606 to configure for the bootloader.


There is no mention in AN2606 of configuring the USB bootloader to use VCP.

Are you thinking of using an external VCP (USB-to-UART converter) to connect to the STM32's UART bootloader?

I don't think that's what @No_Name is asking about?

I think @No_Name wants to implement VCP on the STM32F40's USB, and update the firmware via that?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User

There's also the ST Open Bootloader: How to use the ST Open Bootloader for STM32 Microcontrollers.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.