在编译过程中有很多错误产生,有的是不注意写错代码,有的是忘记添加相应的变量,这里列举一些常见的错误。
一、命名错误
文件夹名跟Makefile文件中的变量名对应不上,错误如下
make[1]: Entering directory 'xxx/LiteOS/arch/arm/cortex_m'
<command-line>: fatal error: xxx/LiteOS/targets/STM32F401_CCU6/include/menuconfig.h: No such file or directory
compilation terminated.
更改文件夹名字即可。
二、警告错误
由于LiteOS开启了-Werror选项,因此会把警告当作错误处理,如下错误
../../lib/libc/src/prng/seed48.c:5:40: error: argument 1 of type 'short unsigned int *' declared as a pointer [-Werror=array-parameter=]
5 | unsigned short *seed48(unsigned short *s)
LiteOS/lib/libc/src/include/../../include/stdlib.h:695:25: note: previously declared as an array 'short unsigned int[3]'
695 | unsigned short *seed48 (unsigned short [3]);
这时候只需要到lib/libc/src/prng/seed48中把unsigned short *s改成unsigned short s[3]即可。
usart.c警告,如下错误
Src/usart.c: In function 'UsartHwi':
Src/usart.c:139:11: error: implicit declaration of function 'LOS_HwiCreate' [-Werror=implicit-function-declaration]
139 | (VOID)LOS_HwiCreate(NUM_HAL_INTERRUPT_UART, 0, 0, UartHandler, NULL);
| ^~~~~~~~~~~~~
在Src/usart.c中引入头文件
#include "los_hwi.h"
三、未定义错误
如果在写代码的时候忘记写一些变量名或者忘记定义或者写错变量名,都会引起该问题,如下错误
Src/tim.c: In function 'GetTimerCycles':
Src/tim.c:143:38: error: 'TIMER3_RELOAD' undeclared (first use in this function)
143 | cycles = swCycles + cycleTimes * TIMER3_RELOAD;
这个错误只需要在Src/tim.c中定义一个变量即可
#define TIMER3_RELOAD 50000
即定时器溢出的数值。
四、链接错误
gcc-arm/bin/../lib/gcc/arm-none-eabi/11.2.1/../../../../arm-none-eabi/bin/ld: /home/chen/Desktop/LiteOS/out/STM32F401_CCU6/lib/libbase.a(mempt_shellcmd.o): in function `OsShellCmdFree':
mempt_shellcmd.c:(.text.OsShellCmdFree+0x174): undefined reference to `__bss_start'
collect2: error: ld returned 1 exit status
Makefile:73: recipe for target 'Huawei_LiteOS' failed
这个__bss_start之类的错误是在targets/STM32F401_CCU6下面的liteos.ld链接文件中未定义这个变量,LiteOS这个变量和STM32CubeMX生成的变量少了两根下划线即__bss_start__ -> __bss_start
类似的错误还有__text_start,__text_end相似的报错,如果不了解的话,可以照着别的项目的.ld文件进行添加相应的字段即可。
五、编译成功后无法使用shell
编译时选择shell,结果在调试中没法使用shell进行交互,提示System Memory Failed,经过排查,发现LiteOS对cmd表的取值是通过LOS_HAL_TABLE_BEGIN这个宏定义实现的,在源代码中查找相应的实现如下
#define LOS_HAL_TABLE_BEGIN(label, name) \
__asm__(".section \".liteos.table." X_STRING(name) ".begin\",\"aw\"\n" \
".globl " X_STRING(LOS_LABEL_DEFN(label)) "\n" \
".type " X_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
".p2align " X_STRING(LOSARC_P2ALIGNMENT) "\n" \
X_STRING(LOS_LABEL_DEFN(label)) ":\n" \
".previous\n" \
)
发现是通过取.setion段里面.liteos.table,在链接文件中实现,对照其他文件发现缺了一个字段,如下代码
.data ALIGN(0x1000):
{
...
//缺了这个字段
KEEP(*( SORT (.liteos.table.*)));
...
} >RAM AT> FLASH
重新编译后,成功进入LiteOS自带shell交互中。