Install the compiler
If you have not installed the compiler, install:
sudo apt install gcc-arm-none-eabi
sudo apt install gdb-arm-none-eabi
sudo apt install binutils-arm-none-eabi
Install cmake and libusb
- CMake (version greater than v2.8.7)
- Libusb 1.0 (version greater than v1.0.9)
sudo apt update
sudo apt install cmake
sudo apt install libusb-1.0-0 libusb-1.0-0-dev libusb-1.0-0-dbg
Installation stlink
Download the open source driver code STLink
git clone https://github.com/texane/stlink.git
Compile, install
cd stlink/
make
make install
The default path for the installation /usr/local/
, the installation path can be specified as desired, e.g.make install DESTDIR=$HOME
After successful installation, the system adds the following several tools:
tool | Features |
---|---|
st-flash |
The cured binary file to the device STM32 |
st-info |
Query STM32 device information of the connected STLink |
st-util |
Run GDB STM32 devices to interact with the service |
stlink-gui |
STlink graphical tool, as shown below |
Connection Test
Just hand me a piece of STM32 NUCLEO-F411R, the following we will use it to make a simple experiment.
Boards are connected using a USB cable and computer, perform lsusb
can be seen to have been identified ST-LINK / v2.1 device.
Execution st-info --probe
View STLink device information.
Compile bsp engineering
We've already downloaded rt-thread-4.0.1 source code, enter stm32f411-st-nucleo of BSP directory, compile it and see directly.
cd /bsp/stm32/stm32f411-st-nucleo/
source ~/.env/env.sh
scons
Not compile, because cross-compiler tool is not configured. Open rtconfig.py file, find the corresponding compiler options EXEC_PATH
variables, it will modify the directory where the native compiler, I am here /usr/bin
.
Implementation of scons
building projects, there are mistakes:
......
/home/rudy/workspace_hd/Draft/RTTB/rt-thread-4.0.1/bsp/stm32/libraries/HAL_Drivers/drv_usart.c: In function 'rt_hw_usart_init':
/home/rudy/workspace_hd/Draft/RTTB/rt-thread-4.0.1/bsp/stm32/libraries/HAL_Drivers/drv_usart.c:662:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int i = 0; i < obj_num; i++)
^
/home/rudy/workspace_hd/Draft/RTTB/rt-thread-4.0.1/bsp/stm32/libraries/HAL_Drivers/drv_usart.c:662:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
scons: *** [/home/rudy/workspace_hd/Draft/RTTB/rt-thread-4.0.1/bsp/stm32/libraries/HAL_Drivers/drv_usart.o] Error 1
scons: building terminated because of errors.
Obviously, because the code in variables defined style is more than the standard C99 is supported, so you need to specify C99 or C11 compiler modes. Rtconfig.py open the file in the corresponding compiler options CFLAGS
variables added at the end -std=c99
parameter.
Re-execute the scons
command, wait a moment appeared scons: done building targets.
prompted to indicate successful compilation. You can see more rtthread.elf and rtthread.bin two binary files in the current directory.
Download Test
Open applications / main.c file, add a line printing in the main function:
int main(void)
{
int count = 1;
/* set LED0 pin mode to output */
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
rt_kprintf("\nI am running RT-Thread in STM32 NUCLEO-F411RE.\n\n");
while (count++)
{
rt_pin_write(LED0_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED0_PIN, PIN_LOW);
rt_thread_mdelay(500);
}
return RT_EOK;
}
Rebuild Project
The next execution sudo st-flash write rtthread.bin 0x8000000
, the programmer rtthread.bin file to 0x8000000 address the board.
It seems programmed success!
minicom virtual serial port connection
We also need to connect STLink virtual serial port, see if there is print out the information we want. First determination device node, here /dev/ttyACM0
, then execute the following command set:
sudo minicom -s
Select "Serial port setup", set serial device to / dev / ttyACM0, 115200 baud rate.
Select "Save setup as ..." to configure named stlink, the configuration file is saved in /etc/minicom/minirc.stlink.
Exit and re-enter the minicom stlink
command, you can open the ST-LINK debug virtual serial port.
See the information we want it! It also shows that we built in the Linux STM32 development environment to OK!