使用STM32的HAL庫移植RTEMS操作系統

編譯運行RTEMS操作系統下STM32F4的BSP

STEP 1: 編譯rtems工具鏈

  1. 下載工具鏈編譯工具
rtems$ git clone https://github.com/RTEMS/rtems-source-builder.git
正克隆到 'rtems-source-builder'...
remote: Enumerating objects: 107, done.
remote: Counting objects: 100% (107/107), done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 9897 (delta 54), reused 76 (delta 35), pack-reused 9790
接收對象中: 100% (9897/9897), 4.15 MiB | 456.00 KiB/s, 完成.
處理 delta 中: 100% (6564/6564), 完成.
  1. 檢查編譯環境
rtems$ cd rtems-source-builder
rtems/rtems-source-builder$ ./source-builder/sb-check
RTEMS Source Builder - Check, 5 (d48abf49ab0a modified)
error: exe: not found: (__bison) /usr/bin/bison
error: exe: not found: (__flex) /usr/bin/flex
error: exe: not found: (__makeinfo) /usr/bin/makeinfo
Environment is not correctly set up

rtems/rtems-source-builder$
  1. 安裝需要的包,直到出現“Environment is ok”;
rtems/rtems-source-builder$ sudo apt-get install bison flex u-boot-tools texinfo
rtems/rtems-source-builder$ ./source-builder/sb-check 
RTEMS Source Builder - Check, 5 (d48abf49ab0a modified)
Environment is ok
  1. 進入rtems目錄,開始編譯
rtems/rtems-source-builder$ cd rtems
rtems/rtems-source-builder/rtems$ ../source-builder/sb-set-builder --log=arm.log \
--prefix=$HOME/opt/rtems/5  5/rtems-arm.bset
參數名 參數值 參數解釋
–log arm.log 在當前目錄下創建arm.log,記錄編譯過程生成的log
–prefix $HOME/opt/rtems/5 當編譯成功後,arm-rtems5-gcc所在的目錄
配置文件 5/rtems-arm.bset 配置文件rtems/config/5/rtems-arm.bset,本質上就是爲arm構建編譯工具鏈
  1. 將$HOME/opt/rtems/5/bin目錄添加到系統的PATH環境變量當中,運行下面命令,出現以下結果則安裝成功.
$ arm-rtems5-gcc -v
Using built-in specs.
COLLECT_GCC=arm-rtems5-gcc
COLLECT_LTO_WRAPPER=/home/messi/opt/rtems/5/libexec/gcc/arm-rtems5/7.5.0/lto-wrapper
Target: arm-rtems5
Configured with: ../gcc-7.5.0/configure --prefix=/home/messi/opt/rtems/5 --bindir=/home/messi/opt/rtems/5/bin --exec_prefix=/home/messi/opt/rtems/5 --includedir=/home/messi/opt/rtems/5/include --libdir=/home/messi/opt/rtems/5/lib --libexecdir=/home/messi/opt/rtems/5/libexec --mandir=/home/messi/opt/rtems/5/share/man --infodir=/home/messi/opt/rtems/5/share/info --datadir=/home/messi/opt/rtems/5/share --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-rtems5 --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --verbose --with-newlib --disable-nls --without-included-gettext --disable-win32-registry --enable-version-specific-runtime-libs --disable-lto --enable-newlib-io-c99-formats --enable-newlib-iconv --enable-newlib-iconv-encodings=big5,cp775,cp850,cp852,cp855,cp866,euc_jp,euc_kr,euc_tw,iso_8859_1,iso_8859_10,iso_8859_11,iso_8859_13,iso_8859_14,iso_8859_15,iso_8859_2,iso_8859_3,iso_8859_4,iso_8859_5,iso_8859_6,iso_8859_7,iso_8859_8,iso_8859_9,iso_ir_111,koi8_r,koi8_ru,koi8_u,koi8_uni,ucs_2,ucs_2_internal,ucs_2be,ucs_2le,ucs_4,ucs_4_internal,ucs_4be,ucs_4le,us_ascii,utf_16,utf_16be,utf_16le,utf_8,win_1250,win_1251,win_1252,win_1253,win_1254,win_1255,win_1256,win_1257,win_1258 --enable-threads --disable-plugin --enable-libgomp --enable-languages=c,c++
Thread model: rtems
gcc version 7.5.0 20191114 (RTEMS 5, RSB 5 (d48abf49ab0a modified), Newlib d14714c69) (GCC) 

注:

  1. 下載的源代碼在rtems/sources 目錄下面,如果網絡不好,可以根據終端顯示的路徑手動下載下來,放在該目錄即可
  2. 編譯後的在rtems/build/ 目錄下面

STEP 2: 編譯RTEMS源碼

  1. 下載源碼
rtems$ git clone https://github.com/RTEMS/rtems.git rtems-src
正克隆到 'rtems-src'...
remote: Enumerating objects: 970, done.
remote: Counting objects: 100% (970/970), done.
remote: Compressing objects: 100% (698/698), done.
remote: Total 560996 (delta 411), reused 479 (delta 251), pack-reused 560026
接收對象中: 100% (560996/560996), 96.58 MiB | 583.00 KiB/s, 完成.
處理 delta 中: 100% (442188/442188), 完成.
  1. 構建
rtems$ cd rtems-src
rtems/rtems-src$ ./bootstrap -c && ./bootstrap
  1. 編譯BSP
rtems/rtems-src$ cd ../
rtems$ mkdir arm-bsp
rtems$ cd arm-bsp
rtems/arm-bsp$ ../rtems-src/configure --target=arm-rtems5 --enable-rtemsbsp="stm32f407" \
--enable-cxx --prefix=$HOME/opt/rtems/5 --disable-networking --disable-itron
rtems/arm-bsp$ make all -j12
rtems/arm-bsp$ make install

STEP 3: 燒寫測試程序"hello",並下載

rtems$ cd arm-bsp/arm-rtems5/c/stm32f407/testsuites/samples
samples$ make

會生成hello.exe,
轉換成bin文件,並且使用stlink燒寫

samples$ arm-none-eabi-objcopy -O binary -S hello.exe hello.bin

燒寫程序

samples$ st-flash write hello.bin 0x08000000

STEP 4:使用GDB調試

第1步:先下載bin文件到flash裏面
samples$ st-flash write hello.bin 0x08000000st-flash 1.5.1-50-g3690de9
2020-02-13T17:11:54 INFO common.c: Loading device parameters....
2020-02-13T17:11:54 INFO common.c: Device connected is: F4 device, id 0x10076413
2020-02-13T17:11:54 INFO common.c: SRAM size: 0x30000 bytes (192 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 16384 bytes
2020-02-13T17:11:54 INFO common.c: Attempting to write 74636 (0x1238c) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08010000 erasedEraseFlash - Sector:0x4 Size:0x10000 
2020-02-13T17:11:56 INFO common.c: Finished erasing 5 pages of 65536 (0x10000) bytes
2020-02-13T17:11:56 INFO common.c: Starting Flash write for F2/F4/L4
2020-02-13T17:11:56 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32768
size: 32768
size: 9100
2020-02-13T17:11:57 INFO common.c: Starting verification of write complete
2020-02-13T17:11:58 INFO common.c: Flash written and verified! jolly good!

燒寫二進制文件
結果顯示
在這裏插入圖片描述

第2步:運行openocd
samples$ openocd -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfgOpen On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: target/stm32f4x_stlink.cfg is deprecated, please switch to target/stm32f4x.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v34 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.215273
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

使用openocd調試

第3步:開啓一個新終端,運行gdb
samples$ arm-none-eabi-gdb hello.exe
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章