Program STM32F4 with UART

STM32F4 devices have great feature. They can be programed with only USB to UART converter. Each device has bootloader inside, which supports UART programming. This is not very great method for Discovery boards, because they have better and faster solution on board, ST-link. But if you are working own board, then this solution can be quite nice.

In this tutorial, I will go through step-by-step how to program device with USB->UART converter. I will use FTDI’s home made converter.

This will work on all STM32F4 boards (Discovery, Nucleo). Also, if you create own board.


  1. Insert you USB to UART converter to computer.
    1. Install drivers if necessary, prepare it to work, and go to device manager and get COMx number.
    2. In my case, I put FTDI converter, and I got result below.

      USB to UART converter

      USB to UART converter

  2. Download Flash Loader Demonstrator from ST’s official site.
  3. Install loader.
    1. There is no specific settings to set. It should be understandable how to install.
  4. Open loader. You should get something like on image below.

    Flash loader demonstrator opened

    Flash loader demonstrator opened

  5. Before we can continue with loader program, we have to prepare hardware for UART bootloader.  Get your board in hands and do stuff:
    1. Find BOOT0 pin and set it to HIGH. On discovery boards, VDD pin is near BOOT0 pin, so if you have jumper, just put it on.
    2. Find PB2 (BOOT1) pin and set it LOW. On discovery boards, GND pin is near PB2 pin, so if you have jumper, just put it on.
    3. If you don’t have jumpers, you can take 2 provided on discovery board. They are on the GND, if you rotate discovery board, under ST-link.
    4. Reset device
  6. We need to connect our USB to UART converter with STM32F4 device.
    1. STM32F4 supports many UART combination.
      1. TX: PA9; RX: PA10
      2. TX: PB10; RX: PB11
      3. TX: PC10; RX: PC11 
      4. I tested with these pins, maybe there are more pins.
      5. If you are working with STM32F4-Discovery, then pins PA9 and PA10 will not work, because they have capacitor for USB connected to this pin. Use any other combination.
      6. Connect TX of STM32F4 with RX of converter and RX of STM32F4 with TX of converter.
  7. Let’s go back to out flash loader.
  8. Leave settings as they are, just change “Port Name“, to your port name. My is COM3.
    1. Hit “Next”
  9. If you have lucky, then you can go to point 11.
  10. If you are not lucky, then you will probably get an error like one below:
    Flash loader demonstrator error

    Flash loader demonstrator error

    1. If you get this, first make sure that you have correct pinout. Also, make sure that BOOT pins are set correct.
    2. Then, disconnect your board from power (USB probably on discovery) and put power back, and in program test again. It should work and you should go to the next step.
  11. When you are OK with detection, you will get window like one below. Hit “Next”.

    Flash loader demonstrator device is readable

    Flash loader demonstrator device is readable

  12. You will get a new window, where you have to select target.
    1. You have to take a value, for your device. If you have 1MB flash size, select STM32F4_1024K
    2. For STM32F4-Discovery select STM32F4_1024K
    3. STM32F429-Discovery is not supported, because there is processor with 2MB flash. This size is not supported by ST’s loader tool. This is very strange, because they didn’t update this.
    4. Hit “Next”

    Flash loader demonstrator select target

    Flash loader demonstrator select target

  13. New window will open. There you have to select your .hex, .bin or .s19 file.
    1. Select file under “Download to device” section.
    2. Leave other settings as they are.
    3. Hit “Next”. Program will automatically start with downloading data to STM32F4.

    Flash loader demonstrator select compiled file

    Flash loader demonstrator select compiled file

  14. Correct written data will be shown with window like my below.

    Flash loader demonstrator download ok

    Flash loader demonstrator download ok

  15. Hit close.
  16. Program is written to device, but if you try to reset device, it will not work.
  17. You have to remove jumpers and reset, so that program will boot from flash and not waiting for UART.
    1. Actually, only BOOT0 has to be set back to LOW
    2. PB2 (BOOT1) does not matter where it is, program will still boot.
  18. Hope it helps for you.


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • siva chandran

    I am using stm32f411-nucleo board in that UART2 (PA2-TX,PA3-RX) is enabled.
    if(USART2_getflagstatus(USART2,USART_flag_RXNE)!=RESET) my program is rotating within the loop. why…..

    • This comment has nothing to do with this post.
      Well, or you don’t have enabled USART, or you are doing something wrong.

  • Pingback: All STM32F4 tutorials - STM32F4 Discovery()

  • Khoa Tran

    17.You have to remove jumpers and reset, so that program will boot from flash and not waiting for UART.
    1.Actually, only BOOT0 has to be set back to HIGH
    2.PB2 (BOOT1) does not matter where it is, program will still boot.
    I confused “only BOOT0 has to be set back to HIGH”.I think It has to be “only BOOT0 has to be set back to LOW”

  • Kaiser

    Hi you seem to have done some great work ob STM32F4 how do I download Your Examples code I want to learn how to use UART ,GPS ,and ADC on STMF4 Discovery Board using STM32CubeMX but i cant find any down links on your website

    • Hello,

      well, to download library you want, you have download link in “All libraries” or in each library post.
      To download everything (including Keil uVision examples) you can go to my github and download entire repository and run examples directly from there.

      You can find everything with a liiitle of search.

  • Mohammad Kamel

    hi i did what you said but i have such a problem my pins are correct but i dont khow what is my problem
    thanks for helping

  • John Đường

    Hello guys i got a problem with point 10 above. Although i did the following steps to fix but i not changed. My kit is STM32F4 Discovery and it stucked with “Core is held in reset” when i tried to Earse using MDK-ARM 5

  • art

    Thanks for this post. I couldn’t get boot to work but was trying USART1 on F4 Discovery. Your post pointing out that USART1 won’t work saved me! Also, I used stm32flash (from sourceforge) rather than the STM flashloader. Simple but complete command-line application.

  • saikrishna

    How to program STM32F103C8T6 with embeddec-c…please suggest me a good textbook ..plsss sir

  • saikrishna

    How to program STM32F103C8T6 with embeddec-c…please suggest me a good textbook ..plsss sir …my email id is

  • selim dumlu

    My MCU is locked while I programming it due to from my fail power supply Now Core is locked . PC assigns a port for it but the programmer doesnt see the STM32F407 and STM32 ST-LINK Utility give the failure massage ” Please make sure that your chip is properly connected ” would it be usefull for my issue ? Or would you prefere me any other solution for this problem .Thanks in advance for your guides

    • In stlink utility simply use connect under reset. In case you locked it with level 2 protection, you cannot program it anymore.