2024-08-26 11:42 AM - edited 2024-08-26 03:20 PM
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,
2024-08-26 03:17 PM - edited 2024-08-26 03:17 PM
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?
2024-08-26 03:22 PM
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...
2024-08-26 03:31 PM - edited 2024-08-26 03:36 PM
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.
2024-08-26 03:52 PM - edited 2024-08-26 03:53 PM
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.
2024-08-26 04:03 PM - edited 2024-08-26 04:06 PM
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.
2024-08-26 04:32 PM - edited 2024-08-26 04:35 PM
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.
2024-08-26 04:51 PM - edited 2024-08-26 04:55 PM
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.