Upload to stm32 through uart

I’d like to upload firmware through the UART but the dfu-util seems to only support certain USB devices while I would like to upload through an FTDI chip.

Would I have to write my own DFU software or is there anything that will just upload through a generic serial port?

Looking at my old notes I uploaded through the serial port after adding the following to ‘platformio.ini’ file:

upload_protocol = serial

From what I can tell that invokes this tool GitHub - rogerclarkmelbourne/Arduino_STM32: Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
It seems aimed at arduino and two families of MCU which I’m using none of, unfortunately.

No, upload_protocol = serial will invoke stm32flash which is explicitly written to interact with the UART bootloader found on STM32 devices. For that to work, the device has to enter bootloader mode (“system memory”) by setting the BOOT0 and possibly BOOT1 pin as shown here. Then, with the UART pins as documented for each device, e.g., PA9 and PA10 for STM32F10x devices.

Okay, it was a bit confusing then as the link I gave above was printed when I tried to use serial
This is the text I saw in the terminal

stm32flash Arduino_STM32_0.9
 
http://github.com/rogerclarkmelbourne/arduino_stm32

But my manual attempts haven’t worked any better so I’m wondering if I might have damaged the MCU as I’m not getting any response. I’m going to try replacing it.

Does it connect when using the STM32CubeProgrammer set to UART/Serial?

https://www.st.com/en/development-tools/stm32cubeprog.html

I haven’t tried that because I realized I’m using alternate pins for the UART so it doesn’t work with the bootloader. But I have the correct pins available through a connector and will do some wiring and try again.

If that doesn’t work I’ll try your tip.

I’ve got some wires to the correct pins now and with a simply python script I can at least get an ACK from the bootloader when trying to read the version.

stm32flash seems to somehow exclude the serial port from being valid before trying to send anything. I don’t see the UART LEDs active when it’s trying to upload so I’m sure nothing is sent on the port. I thought before that it was expecting an ACK too but didn’t get it and therefore threw the error but that doesn’t seem to be the case.

stm32flash Arduino_STM32_0.9
Error probing interface "serial_posix"

http://github.com/rogerclarkmelbourne/arduino_stm32

Using Parser : Raw BINARY

Cannot handle device "/dev/serial/by-id/usb-FTDI_devboard_d-if00-port0"
Failed to open port: /dev/serial/by-id/usb-FTDI_devboard_d-if00-port0
*** [upload] Error 1

Or am I setting the upload_port incorrectly? I’m on Ubuntu.

upload_protocol = serial
upload_port = /dev/serial/by-id/usb-FTDI_devboard_d-if00-port0

Does this also occur when you use just the /dev/ttyUSB0 (or similiar) name? Or, when you delete the upload_port line?

Yeah, without setting upload_port it somehow picks a serial port, it picked ttyUSB1 but gave the same error. If i use the ttyUSBX name I get the same, that stm32flash “Cannot handle device”. I’m not sure how it determines that, if it’s just seeing the FTDI manufacturer/description/serial and comparing to some list.

Alright, kind of solved it. Silly issue as expected. stm32flash didn’t have permission to open the port. I really wish the error messages would have been a bit more clear and actually used the return values. It took me cloning the code and adding printouts to realize the issue.

I just went to confirm it works with pio as well but there I’m hitting another issue. It says my device is unknown/unsupported…?

Unknown/unsupported device (Device ID: 0x435)

Pretty odd considering it worked great when I compiled it and ran it myself

$ sudo ./stm32flash -g 0x08000000 -b 9600 -w "../../projects/pio_apps/applications/st7735_test/.pio/build/stm32l431rc/firmware.bin" "/dev/ttyUSB0"
stm32flash STM32duino_0.5.1

https://github.com/stm32duino/stm32flash

Using Parser : Raw BINARY
Interface serial_posix: 9600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Write to memory
Erasing memory
Wrote address 0x0800f598 (100.00%) Done.

Starting execution at address 0x08000000... done.

Same device ID and no problem… Well I won’t be using the bootloader too much, I’m just exploring the functionality so no breaking issue for me.

I notice a difference
From PIO

stm32flash Arduino_STM32_0.9

The version I compiled

stm32flash STM32duino_0.5.1