Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flash STM32 via Serial Port

I have an STM32F102 microcontroller and I want to program it via the Serial Port.

While there is a flasher available for windows, I want to do it on a Linux Machine. I tried doing it with this script

I have set BOOT0 = 1 and BOOT1 = 0, restarted the microcontroller. But it does not work. I get the following output

Can't init. Ensure BOOT0=1, BOOT1=0, and reset device
Traceback (most recent call last):
  File "stm32loader.py", line 552, in <module>
    bootversion = cmd.cmdGet()
  File "stm32loader.py", line 140, in cmdGet
    if self.cmdGeneric(0x00):
  File "stm32loader.py", line 137, in cmdGeneric
    return self._wait_for_ack(hex(cmd))
  File "stm32loader.py", line 88, in _wait_for_ack
    raise CmdException("No response to %s" % info)
__main__.CmdException: No response to 0x0
like image 396
RishabhHardas Avatar asked May 17 '16 05:05

RishabhHardas


People also ask

What is bootloader in STM32?

The bootloader is stored in the internal boot ROM (system memory) of STM32 devices, and is programmed by ST during production. Its main task is to download the application program to the internal Flash memory through one of the available serial peripherals (such as USART, CAN, USB, I2C, SPI).


1 Answers

Here are a few tips:

  • Connect serial cable before resetting / powering up the board. Otherwise some transients can mess the serial bootloader up.

  • Make sure you are using a TTL level USB-to-serial converter instead of a RS-232 cable. RS-232 has inverted level, and worse still, its -15V to 15V voltage range can burn your STM32.

  • Make sure RX and TX are connected correctly.

  • Try using stm32flash instead.

  • Most STM32's serial bootloader does not support baud rate higher than 115200 as I remember. The bootloader can detect baud rate automatically, the one I usually use is 57600.

like image 161
Chi Zhang Avatar answered Oct 04 '22 18:10

Chi Zhang