RTEMS 4.11已經支持STM32F4系列的BSP了,因此移植還是相當的簡單。移植過程如下:
(1)開發環境的建立:使用官方的工具鏈直接生成RTEMS 4.11的工具鏈(gcc 4.9.3)。
https://github.com/RTEMS/rtems-source-builder
(2)下載RTEMS 4.11的內核源碼(分支:4.11)。
https://github.com/RTEMS/rtems/tree/4.11
(3)修改內核源碼與stm32f429相關的配置文件。(默認為:stm32f407 168MHz 我使用stm32f429 180MHz)。
修改: rtems-4.11/c/src/lib/libbsp/arm/stm32f4/configure.ac
AC_PREREQ([2.69])
AC_INIT([rtems-c-src-lib-libbsp-arm-stm32f4],[_RTEMS_VERSION],[https://devel.rtems.org/newticket])
AC_CONFIG_SRCDIR([bsp_specs])
RTEMS_TOP(../../../../../..)
RTEMS_CANONICAL_TARGET_CPU
AM_INIT_AUTOMAKE([no-define nostdinc foreign 1.12.2])
RTEMS_BSP_CONFIGURE
RTEMS_PROG_CC_FOR_TARGET
RTEMS_CANONICALIZE_TOOLS
RTEMS_PROG_CCAS
RTEMS_CHECK_NETWORKING
AM_CONDITIONAL(HAS_NETWORKING,test "$HAS_NETWORKING" = "yes")
RTEMS_BSPOPTS_SET([STM32F4_FAMILY_F4XXXX],[stm32f4*],[1])
RTEMS_BSPOPTS_HELP([STM32F4_FAMILY_F4XXXX],[Chip belongs to the STM32F4XXXX family.])
RTEMS_BSPOPTS_SET([STM32F4_HSE_OSCILLATOR],[*],[8000000])
RTEMS_BSPOPTS_HELP([STM32F4_HSE_OSCILLATOR],[HSE oscillator frequency in Hz])
RTEMS_BSPOPTS_SET([STM32F4_SYSCLK],[*],[180000000])
RTEMS_BSPOPTS_HELP([STM32F4_SYSCLK],[SYSCLK frequency in Hz])
RTEMS_BSPOPTS_SET([STM32F4_HCLK],[*],[180000000])
RTEMS_BSPOPTS_HELP([STM32F4_HCLK],[HCLK frequency in Hz])
RTEMS_BSPOPTS_SET([STM32F4_PCLK1],[*],[45000000])
RTEMS_BSPOPTS_HELP([STM32F4_PCLK1],[PCLK1 frequency in Hz])
RTEMS_BSPOPTS_SET([STM32F4_PCLK2],[*],[90000000])
RTEMS_BSPOPTS_HELP([STM32F4_PCLK2],[PCLK2 frequency in Hz])
RTEMS_BSPOPTS_SET([STM32F4_USART_BAUD],[*],[115200])
RTEMS_BSPOPTS_HELP([STM32F4_USART_BAUD],[baud for USARTs])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_1],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_1],[enable USART 1])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_2],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_2],[enable USART 2])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_3],[*],[1])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_3],[enable USART 3])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_UART_4],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_UART_4],[enable UART 4])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_UART_5],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_UART_5],[enable UART 5])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_6],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_6],[enable USART 6])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_I2C1],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_I2C1],[enable I2C 1])
RTEMS_BSPOPTS_SET([STM32F4_ENABLE_I2C2],[*],[])
RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_I2C2],[enable I2C 2])
RTEMS_BSP_CLEANUP_OPTIONS(0, 0)
RTEMS_BSP_LINKCMDS
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
(4)修改啟動部分的初始化函數:
/rtems-4.11/c/src/lib/libbsp/arm/stm32f4/startup/bspstart.c
/* APB1 prescaler, APB1 clock must be < 45MHz */
apbpre1 = ( sys_clk * 100 ) / 45;
if ( apbpre1 <= 100 ) {
apbpre1 = RCC_CFGR_PPRE1_BY_1;
} else if ( apbpre1 <= 200 ) {
apbpre1 = RCC_CFGR_PPRE1_BY_2;
} else if ( apbpre1 <= 400 ) {
apbpre1 = RCC_CFGR_PPRE1_BY_4;
} else if ( apbpre1 <= 800 ) {
apbpre1 = RCC_CFGR_PPRE1_BY_8;
} else if ( apbpre1 ) {
apbpre1 = RCC_CFGR_PPRE1_BY_16;
}
/* APB2 prescaler, APB2 clock must be < 90MHz */
apbpre2 = ( sys_clk * 100 ) / 90;
if ( apbpre2 <= 100 ) {
apbpre2 = RCC_CFGR_PPRE2_BY_1;
} else if ( apbpre2 <= 200 ) {
apbpre2 = RCC_CFGR_PPRE2_BY_2;
} else if ( apbpre2 <= 400 ) {
apbpre2 = RCC_CFGR_PPRE2_BY_4;
} else if ( apbpre2 <= 800 ) {
apbpre2 = RCC_CFGR_PPRE2_BY_8;
} else {
apbpre2 = RCC_CFGR_PPRE2_BY_16;
}
rcc->cr |= RCC_CR_HSION; /* turn on HSI */
while ( ( !( rcc->cr & RCC_CR_HSIRDY ) ) ) ;
(5) 目前修改這麼多,就可以了,後期還需要繼續修改。
然後在rtmes-4.11主目錄,執行編譯相關的命令。
# ./bootstrap -c
#./boostrap -p
#./bootstrap
#cd ..
#mkdir stm32f4
#cd stm32f4
# ../rtems-4.11/configure --target=arm-rtems4.11 --disable-posix --disable-itron --disable-cxx --disable-networking --enable-rtemsbsp="stm32f4" --prefix=/home/RTEMS/stm32f4
#make
#make install
(6)這樣,在 stm32f4/arm-rtems4.12/c/stm32f4/testsuites/samples/hello目錄下,就能生成測試文件
(7)編譯stlink 的工具,生成st-flash等工具
(8)arm-rtems-objcopy -O binary hello.exe hello.bin可以生成bin文件,
st-flash write hello.bin 0x8000000即可下載到開發板。
(9)連接串口為:串口3 TTL電平,需要USB轉TTL(3.3V TTL)等工具看一下輸出效果。
如果成功打印,說明STM32F429 RTEMS BSP基本上正常了,可以再試一下ticker fileio等測試程序,基本上可以驗證RTEMS是否成功運行。
我移植的下載地址到Linux公社1號FTP服務器下載
------------------------------------------分割線------------------------------------------
FTP地址:ftp://ftp1.linuxidc.com
用戶名:ftp1.linuxidc.com
密碼:www.linuxidc.com
在 2016年LinuxIDC.com/11月/基於STM32F429-Discovery RTEMS 4.11的移植/
下載方法見 http://www.linuxidc.com/Linux/2013-10/91140.htm
------------------------------------------分割線------------------------------------------