So, you wrote your driver and then compiled it: now want to run it on a STM32 microcontroller. To do this, there are several ways, depending on your board's configuration.
Method 1: USB
If you are using a Discover board, you can directly plug your board to your PC with a USB cable. You will need some drivers that are available one the vendor's site. Once the PC has recognized tour board, you have two options.
1.1 Drag and Drop
Some boards support drag and drop: simply select your .bin
file and drop it into the device.
1.2 ST-Link software
If this doesn't work, you can try downloading an ST-Link utility, which is provided with a GUI. You will need to press Connect, flash your binary, verify it and then power cycle the board.
Windows
Simply install the ST-Link Utility.
Linux
STLink (Recommended)
This is a command line tool.
Here you find a guide on how to install it.
For Ubuntu you can simply do:
sudo apt install stlink-tools
And in order to flash your board:
st-flash write <path-to-binary> <flash-origin-address>
QSTLink2
sudo add-apt-repository ppa:fpoussin/ppa
sudo apt-get update
sudo apt-get install qstlink2
wget https://raw.githubusercontent.com/mobyfab/QStlink2/master/res/49-stlinkv2.rules
sudo mv 49-stlinkv2.rules /etc/udev/rules.d
sudo chown root:root /etc/udev/rules.d/49-stlinkv2.rules
Method 2: USART
If your board has at least a USART port accessible, you can also flash binaries through it. To do this, you'll need a USB-TTL module and you need to have access to the following pins of your STM32:
- BOOT0
- BOOT1
- NRST
- USART RX
- USART TX
You also need stm32flash
installed.
Procedure
- Connect BOOT0 to VDD and BOOT1 to GND
- Reset the board by pulling NRST to GND and then leave it floating
- try
stm32flash /dev/ttyUSB0
orttyS0
- if the board information is printed, flash with
stm32flash -b <BAUDRATE> -w <BINARYNAME> /dev/ttyUSB0
or whatever device the USB-TTL is attached. - once finished, restore BOOT0 and BOOT1 values and reset the board.