前面我谈到刷flash卡死的原因,我用官方提供的RA4M2\r20an0608eu0121-ek-ra4m2-exampleprojects\ek_ra4m2\flash_hp\flash_hp_ek_ra4m2_ep
例子测试了刷写flash是对的。
然后我再回头到U盘升级的例子里面用log来打印,发现刷写的函数是不是有问题:
修改代码如下:
for (address = FLASH_CODE_AREA_START
{
status = g_flash0.p_api->blankCheck(g_flash0.p_ctrl, address, FLASH_BLOCK_SIZE, &result)
APP_PRINT("__BKPT %d address:%x\n", status, address)
if (status) __BKPT()
APP_PRINT("check status %d check address: %X end address: %x \n", status, address, FLASH_CODE_AREA_END)
if (FLASH_RESULT_NOT_BLANK == result)
{
APP_PRINT("start disable_irq \n ")
__disable_irq()
APP_PRINT("start status = g_flash0 \n")
status = g_flash0.p_api->erase(g_flash0.p_ctrl, address, 1)
APP_PRINT(" status %d \n ", status)
if (status) __BKPT()
APP_PRINT("end if (status) __BKPT() \n ")
__enable_irq()
}
}
打印的LOG如下:
start StartFlashProgramming
__BKPT 0 address:20000
check status 0 check address: 20000 end address: FFFFF
__BKPT 0 address:28000
check status 0 check address: 28000 end address: FFFFF
__BKPT 0 address:30000
check status 0 check address: 30000 end address: FFFFF
__BKPT 0 address:38000
check status 0 check address: 38000 end address: FFFFF
__BKPT 0 address:40000
check status 0 check address: 40000 end address: FFFFF
__BKPT 0 address:48000
check status 0 check address: 48000 end address: FFFFF
__BKPT 0 address:50000
check status 0 check address: 50000 end address: FFFFF
__BKPT 0 address:58000
check status 0 check address: 58000 end address: FFFFF
__BKPT 0 address:60000
check status 0 check address: 60000 end address: FFFFF
__BKPT 0 address:68000
check status 0 check address: 68000 end address: FFFFF
__BKPT 0 address:70000
check status 0 check address: 70000 end address: FFFFF
__BKPT 0 address:78000
check status 0 check address: 78000 end address: FFFFF
__BKPT 0 address:80000
check status 0 check address: 80000 end address: FFFFF
start disable_irq
start status = g_flash0
status 25
我发现刷写结尾的地址是#define FLASH_CODE_AREA_END (0xFFFFF) 这应该不对吧。。。。查看数据手册:
我试着把最后的地址修改为80000。
然后重新下载,打开RTT View就可以看到刷写成功的代码:
但是重新上电后还是没有跳转到正确的程序中,再次查看源码:
Address = (uint32_t)strtol(addr,&p, 16);
if ((Address < FLASH_CODE_AREA_START) || (Address >= FLASH_CODE_AREA_END))
{
if (Address >= RAM_AREA_START) break;
APP_PRINT("EndFlashProgramming \n");
EndFlashProgramming();
f_close(&SrecFile);
return (2);
}
这里的APP_PRINT("EndFlashProgramming \n");还没有执行过。
等于说固件还没有刷进去。
我再加进LOG日志:
打印的日志如下:
中间省省略N个1:
我看源代码中的1是直接break的,这说明没有把源代码刷进去呀!
然后直接打印出来
最好我重新格式化了U盘,再把固件拷进去,最后成功运行了:
【经验教训】因为我是第一次做U盘升级,学习了官方提供的demo,因为拿到的FSP是3.2.0,而我现在用的是4.2.0可能官方还是在原来的固件上写的,有兼容性的原因。
最后大家一定要先格式化U盘,再拷固件进去。这样就会少走弯路。还有那个固件的结速地址,不是知道官方这样写是不是对的。总之,我还是学会了U盘升级。这样大家在升级固件时,就不用串口或者下载器了,只要把固件用U盘拷进去,重启,就可以升级固件了。
晚上1:00,希望明天更美好吧!