PROGRAM STM32 WITH UART
Program STM32F4 with UART
STM32F3 devices have a great feature. They can be programmed with the only USB to UART converter. Each device has a bootloader inside, which supports UART programming. This is not a very great method for Discovery boards, because they have a better and faster solution onboard, ST-link. But if you are working on your own board, then this solution can be quite nice.
In this tutorial, I will go through step-by-step how to program the 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.
- Insert your USB to the UART converter to the computer.
- Install drivers if necessary, prepare it to work, and go to devise manager and get COMx number.
- In my case, I put the FTDI converter, and I got the below mentioned result.
- Download Flash Loader Demonstrator from ST’s official site.
- Install loader.
- There are no specific settings to set. It should be understanding how to install it.
- Open loader. You should get something like in the image below.
Hardware connection requirements
- Before we can continue with the loader program, we have to prepare hardware for the UART bootloader.
- Get your board in your hands and do stuff.
- Connect the respected connection as follow:
- Find BOOT0 pin and set it to HIGH as show in below figure 1. On discovery boards, VDD pin is near BOOT0 pin, so if you have jumper, just put it on.
- To use the USART bootloader, the host must be connected to the RX and TX pins of the desired USARTx interface via a serial cable.
Figure1. USART connection
- A pull-up resistor must be added if the pull-up resistor is not connected in the host-side connect pull up resistor.
- Note: +Vtypically is 3.3 V and R typically 100 KΩ.These values depend upon the application and the used hardware.
- An RS232 transceiver must be connected to adapt voltage level (3.3 to 12 V) between the STM32 device and host.
- To use the DFU, connect the microcontroller USB interface to a USB host (i.e. a PC).
- Find PB2 (BOOT1) pin and set it LOW. On discovery boards, the GND pin is near the PB2 pin, so if you have a 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 STM32F3 device.
- STM32F3 supports many UART combination.
- TX: PA9; RX: PA10
- TX: PB10; RX: PB11
- I tested with these pins, maybe there are more pins.
- If you are working with STM32F3-Discovery, then pins PA9 and PA10 will work.
If you’re programming with respect to I2C connection connect the respected connection as shown below figure.
If you’re programming with respect to SPI connection connect the respected connection as shown below figure.
If you’re programming with respect to CAN connection connect the respected connection as shown below figure.
Note: When a bootloader firmware supports DFU, it is mandatory that no USB Host is connected to the USB peripheral during the selection phase of the other interfaces. After selection phase, the user can plug a USB cable without impacting the selected bootloader execution except commands which generate a system reset.
It is recommended to keep the RX pins of unused bootloader interfaces (USART_RX, SPI_MOSI, CAN_RX and USB D+/D- lines if present) at a known (low or high) level at the start up of the bootloader (detection phase). Leaving these pins floating during the detection phase might lead to activating unused interfaces.
Figure6. Exit Secure Memory function usage
Before starting bootloader look this below table then we can find list of communication ports available for bootloader.
- Let’s go back to our flash loader.
- If you get this, first make sure that you have the 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 a window like the 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.
- No response from the target the boot loader can not be started.
- Unrecognized devices… please reset your device then try again.
- No response from the target the boot loader cannot be started.
- If you getting this kind of error.
- Change RX & TX and boot mode connected to pull-up resistor.
Note: connect boot pin to ground or VCC its depend of board it change
Still you getting this kind of error.
Note: after completion of connection as shown above figure.
After that you have to reset the board if you’re not doing this then you’re going to face this problem.