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-27 07:35 PM
Probably not simplest for the user, but certainly easier for the developer and possibly safer. Why reinvent the wheel? You should also skim through the official USB DFU specification, freely available online.
Another popular model (though not native to STM32 chips) for easily programming a board over USB is to use a UF2 bootloader. The user puts the device into the UF2 bootloader mode, and the board enumerates as a USB mass-storage device / drive on your computer. You then drag the firmware update file into the drive and this triggers the update. The Raspberry PI Pico is one major example, but I've also seen this type of update flow on some pen-style soldering irons. Here are some details from Adafruit about how they implement it on some of their Atmel SAM Based boards. I've not (yet, though I probably will now) looked at whether anything out tthere implements this for STM32.
If you want something very user friendly UF2 is a good model, but could mean much more work for you.
2024-08-27 01:08 PM - edited 2024-08-27 01:10 PM
I'm looking to implement USB DFU. The solution requires the USB DM to be pulled up to 3.3V using a 1.5k resistor.
The problem I'm facing now is that my app was already pulling up the USB DM programatically via a GPIO output. When I go into boot mode, USB DM is not pulled up so it does not get detected for USB DFU.
Is the solution to leave the pull-up resistor, and to configure the GPIO as a drain output, and ensuring it is set low when my app starts? ( it gets set high when the USB+5V is detected )
Or should I leave the 1.5k pull-up and remove the GPIO output toggle? ( then there will be no way for my app to detect when the USB cable is connected to pull the USB DM hight as per the spec )
2024-08-27 07:37 PM
That sounds like a good subject for a new thread.