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.
Step-by-step
- Insert you USB to UART converter to computer.
- Install drivers if necessary, prepare it to work, and go to device manager and get COMx number.
- In my case, I put FTDI converter, and I got result below.
- Download Flash Loader Demonstrator from ST’s official site.
- Install loader.
- There is no specific settings to set. It should be understandable how to install.
- Open loader. You should get something like on image below.
- Before we can continue with loader program, we have to prepare hardware for UART bootloader. Get your board in hands and do stuff:
- 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.
- 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.
- 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.
- Reset device
- We need to connect our USB to UART converter with STM32F4 device.
- STM32F4 supports many UART combination.
- TX: PA9; RX: PA10
- TX: PB10; RX: PB11
- TX: PC10; RX: PC11
- I tested with these pins, maybe there are more pins.
- 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.
- Connect TX of STM32F4 with RX of converter and RX of STM32F4 with TX of converter.
- STM32F4 supports many UART combination.
- Let’s go back to out flash loader.
- Leave settings as they are, just change “Port Name“, to your port name. My is COM3.
- Hit “Next”
- If you have lucky, then you can go to point 11.
- If you are not lucky, then you will probably get an error like one below:
- If you get this, first make sure that you have correct pinout. Also, make sure that BOOT pins are set correct.
- 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.
- When you are OK with detection, you will get window like one below. Hit “Next”.
- You will get a new window, where you have to select target.
- You have to take a value, for your device. If you have 1MB flash size, select STM32F4_1024K
- For STM32F4-Discovery select STM32F4_1024K
- 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.
- Hit “Next”
- New window will open. There you have to select your .hex, .bin or .s19 file.
- Select file under “Download to device” section.
- Leave other settings as they are.
- Hit “Next”. Program will automatically start with downloading data to STM32F4.
- Correct written data will be shown with window like my below.
- Hit close.
- Program is written to device, but if you try to reset device, it will not work.
- You have to remove jumpers and reset, so that program will boot from flash and not waiting for UART.
- Actually, only BOOT0 has to be set back to LOW
- PB2 (BOOT1) does not matter where it is, program will still boot.
- Hope it helps for you.
Recent comments