使用的是GD32W51x的芯片,不优化没有问题,开启O1、O2或Og优化就会单板起不来。
如果不打断点gdb跟上去,会有各种不同的错误调用栈,但都会报signal trap。
如果在rt_hw_board_init开始处打断点,gdb跟上去运行,就可以正常启动。
看了下汇编,水平有限,也没看出啥问题:
1、启动.s调用entry()函数
Zerobss:
ldr r3, = _ebss
8006cc8: 4b08 ldr r3, [pc, #32] ; (8006cec <LoopForever+0x12>)
cmp r2, r3
8006cca: 429a cmp r2, r3
bcc FillZerobss
8006ccc: d3f9 bcc.n 8006cc2
/* Call SystemInit function /
bl SystemInit
8006cce: f7fb f867 bl 8001da0
/ Call static constructors /
bl __libc_init_array
8006cd2: f00a fcbd bl 8011650 <__libc_init_array>
/ Call the application's entry point.*/
bl entry
8006cd6: f000 fbab bl 8007430
2、在entry函数中调用各初始化函数,优化掉了对rtthread_startup的调用
08007430 :
{
8007430: b508 push {r3, lr}
[url=home.php?mod=space&uid=2666770]@Brief[/url] This function will call all levels of initialization functions to complete
the initialization of the system, and finally start the scheduler.
/
int rtthread_startup(void)
{
rt_hw_interrupt_disable();
8007432: f7f8 fed1 bl 80001d8 <rt_hw_interrupt_disable>
/ board level initialization
- NOTE: please initialize heap inside board initialization.
/
rt_hw_board_init();
8007436: f7ff fc5d bl 8006cf4 <rt_hw_board_init>
/ show RT-Thread version /
rt_show_version();
800743a: f008 fbaf bl 800fb9c <rt_show_version>
/ timer system initialization */
rt_system_timer_init();
800743e: f001 fa45 bl 80088cc <rt_system_timer_init>
3、对于rt_hw_board_init函数的调用:
void icache_enable()
{
if (ENABLE != (ICACHE_CTL & ICACHE_CTL_EN))
8006cf4: 4b15 ldr r3, [pc, #84] ; (8006d4c <rt_hw_board_init+0x58>)
/**
-
This function will initial your board.
/
void rt_hw_board_init()
{
8006cf6: b510 push {r4, lr}
if (ENABLE != (ICACHE_CTL & ICACHE_CTL_EN))
8006cf8: 681a ldr r2, [r3, #0]
8006cfa: 07d2 lsls r2, r2, #31
8006cfc: d403 bmi.n 8006d06 <rt_hw_board_init+0x12>
ICACHE_CTL |= ICACHE_CTL_EN;
8006cfe: 681a ldr r2, [r3, #0]
8006d00: f042 0201 orr.w r2, r2, #1
8006d04: 601a str r2, [r3, #0]
/ Enable icache to run quickly /
icache_enable();
/ System Clock Update */
SystemCoreClockUpdate();
8006d06: f7fb f8d5 bl 8001eb4
以下是rtconfig.py中对于gcc编译选项的设置:
DEVICE = ' -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections'
CFLAGS = DEVICE + ' -Dgcc' + ' -DSOC_SERIES_' + BOARD
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
LFLAGS = DEVICE + ' -Wl,--gc-sections, -Wl,-cref,-u,Reset_Handler -T board/linker_scripts/link.ld'
CPATH = ''
LPATH = ''
distinguish debug and release version
if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2 -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
CFLAGS += ' -Wall -Wno-unused-parameter -Wno-unused-function'
不知道这个是代码写的有问题,还是编译选项设置的有问题?请各位不吝指导,谢谢!