cancel
Showing results for 
Search instead for 
Did you mean: 

Update Firmware over USB Virtual Comm Port

LMorr.3
Senior II

Hello,

I am using the STM32F373's virtual USB port successfully.  I can connect and send packets to the uC from a web browser.  I now want to allow the user to update the firmware from the web browser by uploading a file, instead of the traditional method involving the ST flash software.  

It would need to happen via WebSerial API so over the USB virtual port.  What is the best way to accomplish this?  Is there an appnote I should look at?  I'm looking at AN2606 [bootloader] and AN3156 [DFU] and AN3156 now.

Thank you,

7 REPLIES 7
BarryWhit
Senior III

I can't recall ever coming across the notion of "Virtual USB port" before. Can you explain what you mean? Perhaps you meant "Virtual COM port" aka VCP, instead?

- If someone's post helped resolve your issue, thank them by clicking "Accept as Solution".
- Once you've solved your issue, please post an update with any further details.

Yes, I meant the virtual com port.  I changed the title.  Does the booloader automatically set the USB port ( PA11 and PA12 ) to DFU mode even though I have set the CubeMX config for USB to 'Virtual Comm Port'?

I could then try using WebUSB to upload the firmware and see there are a couple of such projects on github...

BarryWhit
Senior III

CubeMX generates configuration code for your user application. The bootloader is firmware already burned into a special region of the chip's flash at the factory. The former does not affect the latter. Once you boot into the bootloader code, it tries to detect which interface you're communicating through, and configures the device peripherals accordingly. It's all well-documented in the appnotes.

- If someone's post helped resolve your issue, thank them by clicking "Accept as Solution".
- Once you've solved your issue, please post an update with any further details.

Is there a way to put the device into boot mode from the web browser?  ( i did not see anything about that in the docs )

The only way I can think of is to have a user button to set Boot0 and Boot1 to high while turning on the device.

I've seen apps where the browser shows a notice when the firmware needs to be udpated.  If you click to update, the browser refreshes after uploading a file in the background via javascript.  It must somehow put the device in boot mode.  It's can't be using the USB+5 signal since that is always present.  ( the same PA11 and PA12 DM/DP USB pins are used as a Virtual Comm Port and use it to detect a USB connection. )  I"m trying to envision how the whole process would flow.

I suppose it should be possible, while your user application is running, to accept a command from the client, and then go through some sort of state cleanup followed by a jump to the bootloader. Might work.

But i'm not sure it's good from a usability standpoint to go this route, since it would mean that a failed update might brick your device, as far as the user is concerned. If you want to hide all STM32-like details from the user, you probably want to have more control over the update process and error recovery (i.e. a fail-safe update procedure).

Otherwise, once you'll inevitably get some percentage of failures in the field, you'll have to document a manual recovery procedure anyway. At which point, you might as well just skip the whole thing and just do all the updates via this manual procedure + the bootloader to begin with.

- If someone's post helped resolve your issue, thank them by clicking "Accept as Solution".
- Once you've solved your issue, please post an update with any further details.
LMorr.3
Senior II

Is the simplest way for the user to update firmware on the end-product to connect a USB cable, hold a button on the device while powering it on, and then using the ST app to upload the file?

Since it's a web app, I could include instructions for the user when there is a new firmware update detected.

I'm wondering how that wold work on a mobile device too.

Probably not simplest for the user, but certainly simplest for the developer. Why reinvent the wheel?

 

Some USB gadgets' have you hold a buttonduring reset to put the device into update mode and this then makes the device enumerate as a USB mass-storage device / drive on your computer. You drag the firmware update file into the drive and this triggers the update. That's fairly user friendly. IIRC the RPI pico is one example. I think they have good docs about it. I've also seen this type of update flow on some pen-style soldering irons.

 

USB-DFU is actually an official, published, specification. I can't remember if this mass-storage thing is a part of it or not. Look it up.

- If someone's post helped resolve your issue, thank them by clicking "Accept as Solution".
- Once you've solved your issue, please post an update with any further details.