Makefile 构建 rtthread 工程2-finsh
Makefile 构建 rtthread 工程2-finsh
在中,已经把 rtthread 内核成功编译通过并跑起来了,下一步就是尝试添加组件,此处以 finsh 为例。 首先修改链接脚本,此处为 STM32F429BITx_FLASH.ld ,主要是为 rtthread 添加所需的段,在 SECTIONS -> .text 修改如下:
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
/* section information for finsh shell */
. = ALIGN(4);
__fsymtab_start = .;
KEEP(*(FSymTab))
__fsymtab_end = .;
. = ALIGN(4);
__vsymtab_start = .;
KEEP(*(VSymTab))
__vsymtab_end = .;
. = ALIGN(4);
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
添加这两个段的目的也是为了实现隐式调用,比如 rtthread 的一些组件初始化函数,比如rtthread 导出到命名行的命令,他们都会被定义到一个固定的段内存里面,然后在初始化的时候根据这个段的大小就可以获知需要执行的内容多少,这样一来就可以实现函数的隐式调用,不需要在初始化函数中显式调用各个组件的初始化了。 在 rtthread 源码包中的 bsp –> stm32 -> libraries 文件夹中把官方提供的系统驱动库整个考过来,此处暂且放在工程目录 Drivers 下: 修改 Makefile 添加 finsh 和串口相关源文件: 此处我们用到了串口,也要把stm32f4xx_hal_uart.c 加入。添加头文件包含: Finsh 依赖device 框架,则需要在配置头文件 rtconfig.h 添加宏开启: 此外,记得把 RT_USING_CONSOLE 、 RT_USING_SEMAPHORE 等宏开启,此处我用的是串口1,则把控制台设置为 uart1: 再执行 make ,发现报错说没有 board.h 头文件,目测是系统驱动需要引用到硬件 hal 库。简单,直接把 main.h 拷一份改个名为 board.h 。然后发现默认还没开启串口 hal 库相关的宏,在 Inc/stm32f4xx_hal_conf.h 中把 usart 相关的宏放出来: 然后再在 board.h 添加所需的头文件,顺便指定当前系列芯片为 F4 系列: 再执行make 发现 Drivers/HAL_Drivers/drv_common.c 有重定义,进去 drv_common.c ,仅保留 reboot 和 _Error_Handler 函数,把 board.h 的 void Error_Handler(void); 声名去掉,执行 make 可以通过。回到 main.c 的 rt_hw_board_init() 中,添加初始化函数:
/**
* This function will initial STM32 board.
*/
void rt_hw_board_init()
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
static uint8_t heap_buf[40 * 1024];
rt_system_heap_init(heap_buf, heap_buf + sizeof(heap_buf) - 1);
/* USART driver initialization is open by default */
#ifdef RT_USING_SERIAL
rt_hw_usart_init();
#endif
/* Set the shell console output device */
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
/* Board underlying hardware initialization */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}
再 make ,编译通过。下载至板子上,串口连接到 secureCRT ,发现控制台已正常跑起来了,组件添加成功: 附上代码链接: https://pan.baidu.com/s/1nicZBBNRCqcp8DI91RmDDA 提取码: 27ta
