cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Uart flash loader program

Jdogk
Associate II

I am trying to create a uart flash loader program.
Currently, the stm32f103rct6 chip is being used, and cp201x is being used for serial communication with the PC.
1. Successfully downloaded bootload and application code using existing bootload mode with UART (CubeProgrammer).
2. I succeeded in uploading the code to the board using IAP (In-application programming) mode with uart.
However, IAP mode requires the use of the ymodem protocol and is inconvenient from the user's perspective.

Based on these
After uploading the bootloader, I would like to create a simple, custom UART Flash Loader program instead of CubeProgrammer. Are there any materials or methods that I can refer to?

 

Thanks,

6 REPLIES 6
TDK
Guru

What part do you need help with?

UART bootloader protocol is detailed in AN3155.

https://www.st.com/resource/en/application_note/an3155-usart-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

Using a serial port from Python, for example, should have a ton of hits online. Similar for other languages. Here is one link of many:

https://www.tutorialspoint.com/how-do-i-access-the-serial-rs232-port-in-python

 

If you feel a post has answered your question, please click "Accept as Solution".

What languages and windowing environments are you comfortable with?

There are several examples of programming via the serial port, but the protocol isn't particularly burdensome.

The IAP could presumably use some more common protocol like X-MODEM / Y-MODEM 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Why so complicated?

As I know, many of the STM MCUs provide a bootloader via UART: check the pin config table and often it says: if you close BOOT pin (tied high, not default to ground), there is one UART (e.g. UART1 pins, besides other options like SPI, I2C, even USB) to activate the bootloader (R/O in chip), so that you can flash MCU via UART (STM32CureeProgrammer should see which bootloader device is active, when BOOT pin is tied high).

Other option: I guess, you can call the bootloader from your own code (no need to have a jumper on BOOT). I assume, the bootloader activated now, will check all the (BOOT) config options (SPI, UART, I2C, USB), if a host device is cannot there. Just check what is mentioned as "boot pin".

If you want to implement your own bootloader procedure: it can be very tricky:

  • you need at least so much space to receive the new image as your flash is:
    imagine 2 MB flash but just 1 MB RAM: how to store 2 MB before you start flashing your MCU?
    (OK, you could think about to handle in packet bursts)
  • the biggest problem!:
    when you have your own bootloader/flash code - it runs from the MCU flash. But you want to erase and overwrite the MCU flash. You kill yourself! The code will crash when you try to erase (and overwrite) the region where you are still executing code.

Try to understand how the Bootloader in STM MCU work, how to use the features already provided (e.g. via this BOOT pin).

At least: call the internal bootloader provided. Do not try to provide your own bootloader when you are still running at the same memory which you want to program when "still in use" (it cannot work).

Thank you for relpy.

I think it'll be easy enough if you do it the way you said it

But the HW system is already built and the goal is to modify and develop it.

Thank you.

Jdogk
Associate II

I'll refer to it and proceed with it.

 

thank you

It's the same thing that most of the samples said. Thank you.