How to flash firmware to STM32Fx

Some of stm32 boards have build-in USB DFU protocol support. For those you can use tools like DFuSe demo from ST or open-source dfu-util to directly upload firmware image through USB. Its obvious and i’m not going to describe it here. (You can find full list of DFU-enabled MCUs in app note AN3156).

For those MCUs without DFU support (like STM32F103C8T6 used in BluePill) you need separate hardware programmer, for example ST-Link V2 Mini

9d9cd4

You need to connect it to dev mini board and wiring is simple:

ST-Link        STM32F103C8T6
3.3V     ---       3.3V
GND      ---       GND
SWDIO    ---       DIO
SWCLK    ---       DCLK

Like this:

DSC_0473

Then you have to download from st.com and install ST-Link Utility. When you connect programmer first time, it is recommended to upgrade firmware of programmer itself. Open ST-Link Utility program and choose in menu ST-Link -> Firmware update, then click Device Connect and if newer firmware is available,  you will see something like this:

stlink_upgrade

Click Yes and newer firmware will be installed.

Then you have to open file with firmware and choose Target -> Connect. If your wiring between programmer and board is correct, you can see info about your MCU:

stlink2

The next step is necessary and it’s full chip erase. Choose Target -> Erase Chip.

STU_erasechip

Then you have to choose Target -> Program and thats all!

 

If my firmware for Pedal & Buttons controller already flashed to the board and needs to updated or reflashed than programmer will can’t connect to the board. Its because I disabled SWD and used its pins as normal GPIO. We have here 2 choices:

  1. Switch both yellow jumpers, so your board will load directly to internal bootloader
  2. Make a «Connect under Reset». So in this case you have to do:
  • choose Target -> Settings in ST-Link utility
  • choose Hardware Reset in Reset Mode
  • push and hold Reset button on the board
  • click OK in ST-Link utility
  • release Reset button

ST-Link utility should now connect to stm board and you can flash a newer firmware. (don’t forget to make full chip erase!)

 

PS. If you have another development board, for example STM32F4Discovery, you can use its build-in programmer. In this case you need to remove both CN3 jumpers and use Disco’s SWD connector this way:

STM32F4Discovery        STM32F103C8T6
3.3V              ---      3.3V
PIN2              ---      DCLK
PIN3              ---      GND
PIN4              ---      DIO

Something like this:DSC_0472

Реклама

How to flash firmware to STM32Fx: 5 комментариев

  1. Hello, Can you help me.
    I have a ST-Link V2 Mini programer and a STM32F103C8T6 board.
    When I connect ST-Link V2 to pc I can update firmware, but when I connect the STM32F103C8T6 board to ST-Link V2 and this to pc, the utility software can’t connect and when I go to target-connect, appears the message «Not ST-Link conected» .
    I revised wire connections, reinstall drivers, and use another STM32F103C8T6 board, but the problem persist.
    Thanks.

    Нравится

    1. Hi!
      At first check status of ST-Link device in windows device properties. If there are some errors like «device needs troubleshooting» than its probably drivers/hardware issue. If device state is OK than try to switch both yellow jumpers on the board and try to connect again

      Нравится

      1. Hello, thanks for the reply.
        The status in the windows device properties is correct and I tried to change the jumpers but the problem persist. I ordered another hardware programer if the problem is solved I will publish it here.

        Нравится

  2. Hi! When I go to ST-LINK—> Firmware update, —> device connect, I get the error message » ST-Link is not in the DFU mode. Please restart it» and I don’t have any firmware version.

    So I tried what you explain : erase chip, program but I do not see the device in the OSH studio . Nothin connected.

    I do not understand what I’m doing when I go to the STM32 ST-link Utility so it’s not obvious why I’m not connected. I can see the device in the windows device list.

    Thanks

    Нравится

Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:

Логотип WordPress.com

Для комментария используется ваша учётная запись WordPress.com. Выход /  Изменить )

Google+ photo

Для комментария используется ваша учётная запись Google+. Выход /  Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход /  Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход /  Изменить )

Connecting to %s