从github
下了rt-thread
的最新版本rt-thread 4.0.3
,发现其中对LS1B的支持太匮乏,并且在板子无法正常运行。好在对LS1C的支持还算完善,遂参考LS1C采用新框架移植串口驱动到LS1B上,在移植的过程中遇到了一些坑,现踩坑过程记录如下。
移植完串口驱动后一运行就送大礼了,报错误信息如下:
initialize rti_board_start:0 done
current sr: 0x1000fc00
\ | /
- RT - Thread Operating System
/ | \ 4.0.3 build Feb 1 2021
2006 - 2020 Copyright by rt-thread team
Unknown Exception, EPC: 0x802030b0, CAUSE: 0x0000002c
Exception Name:Coprocessor Unit Invalid
ExeCode = 0x0000000b
根据出错信提示为cp
协处理器单无效,即无初始化然后就使用的意思。 查看libcpu\mips\common\exception.c
中rt_hw_exception_init
中发现有使能cp0
的操作。 根据flygoat
大神的提示,查看exccode
的值结合see mips run
中的exccode
类型表,找到0x000000b
是cp1
即FPU
没有使能但编译的程序中有浮点指令从而触发。而ls1b
中貌似没有FPU
或是FPU
无法使用。所以可以通过使用soft fpu
的方式绕过它。
修改ls1b
的编译参数,指定采用soft fpu
, 修改rtconfig.py
中DEVICE
成如下
DEVICE = ' -mips32 -msoft-float -mfp32'
修改完之后编译运行出现如下的错误:
initialize rti_board_start:0 done
current sr: 0x1000fc00
\ | /
- RT - Thread Operating System
/ | \ 4.0.3 build Feb 1 2021
2006 - 2020 Copyright by rt-thread team
timer iniit .
scheduler init.
application iniit .
timer thread init .
idle init .
scheduler start.
do components initialization.
initialize rti_board_end:0 done
initialize dfs_init:0 done
initialize libc_system_init:0 done
initialize finsh_system_init:0 done
msh />Unknown Exception, EPC: 0x80214ca8, CAUSE: 0x00000014
Exception Name:Address Write Exception
ExeCode = 0x00000005
ST0: 0x1000fc03 ErrorPC: 0x00000000
0: 0x00000000, 1: 0x80214d44, 2: 0x8022dea4, 3: 0x00000002,
4: 0x0000000f, 5: 0x00000001, 6: 0x00000001, 7: 0x00000003,
8: 0x00000008, 9: 0xdeadbeef, 10: 0xdeadbeef, 11: 0x80214ed0,
12: 0x80231bd0, 13: 0x00000000, 14: 0x00000010, 15: 0x00000010,
16: 0x80214ca8, 17: 0x00000014, 18: 0x40008014, 19: 0x40008014,
20: 0x00000000, 21: 0xdeadbeef, 22: 0xdeadbeef, 23: 0x80215130,
24: 0x80231bd0, 25: 0x1000fc03, 26: 0x0000000a, 27: 0x8020f5f0,
28: 0x00000014, 29: 0x00000014, 30: 0x00000005, 31: 0x802005fc,
shutdown...
反汇编rtthread.elf
文件,根据EPC
找到是什么触发了此异常。
/opt/mips-2016.05/bin/mips-sde-elf-objdump -S rtthread.elf > rtt.s
通过分析汇编和对比LS1C
的配置,最终定位在idle
线程栈的大小。通过scons --menuconfig
将idle
线程的栈大小从默认的256
改为1024
。即IDLE_THREAD_STACK_SIZE
设置为1024
.
重新编译后运行正常
current sr: 0x1000bc00
\ | /
- RT - Thread Operating System
/ | \ 4.0.3 build Feb 2 2021
2006 - 2021 Copyright by rt-thread team
msh />ps
thread pri status sp stack size max used left tick error
-------- --- ------- ---------- ---------- ------ ---------- ---
tshell 20 running 0x00000310 0x00001000 24% 0x00000009 000
tidle0 31 ready 0x000001c0 0x00000400 44% 0x00000005 000