mcu_ab568x/userboot240328/app/projects/AB5681G_320/main.c
2025-05-30 18:03:10 +08:00

136 lines
4.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "include.h"
#define TRACE_EN 0
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
extern u32 code_area_addr;
extern u32 res_area_addr;
extern bool cache_init_flag;
const uint8_t *bt_rf_get_inq_param(void)
{
return NULL;
}
const uint8_t *bt_rf_get_param(void)
{
return (const uint8_t *)&xcfg_cb.rf_pa_gain;
}
#define CODE_BASE_ADDR (USERBOOT_SIZE + 0x2000)
#define RES_BASE_ADDR (CODE_BASE_ADDR + CODE_SIZE)
//库里面初始化调用,弱定义,设置代码启动地址
u8 rsp_adv_data[31];
void cache_addr_init()
{
code_area_addr = CODE_BASE_ADDR;
res_area_addr = RES_BASE_ADDR;
u8 sot_flag = 0;
os_spiflash_read(&sot_flag, OTA_FLAG_ADDR, 1);
os_spiflash_read(rsp_adv_data, OTA_FLAG_ADDR + 1, 32);
printf("SOT_FLAG[%x][%x][%x][%x]\n", sot_flag,OTA_FLAG_ADDR,RES_BASE_ADDR,FLASH_UI_BASE);
printf("rsp_adv_data\n");
print_r(rsp_adv_data, 31);
if(rsp_adv_data[0] != 0x1e && rsp_adv_data[1] != 0xff)
{
sot_flag = 0xff;
}
//是否进用户主程序标志位
cache_init_flag = sot_flag;//(bool)sot_flag; //0xff表示重启后进主程序0x00表示重启后进升级驱动
}
/*******************bin文件更新code示例工程*********************
*此例程事先将升级程序储存在flash读取升级数据进行程序更新
*实际使用无需app无线发送需要替换数据传输接口***\
*升级文件分三部分(app.bin/res.bin/ui.bin)
*app.bin代码区 ----起始地址CODE_BASE_ADDR
*res.bin提示音/EQ资源----起始地址RES_BASE_ADDR
*ui.bin 表盘/字库资源 ----起始地址UI_BASE_ADDR
*升级步骤详见ota_demo
*1.write_code_init(); //写入code前需初始化相关buf
*2.write_code_start(0,CODE_BASE_ADDR, file_len); //设置app.bin区域地址和大小CODE_BASE_ADDR初始地址file_len文件大小需512byte对齐
*3.write_code(test_buf); //循环写入app.bin数据
*4.write_code_verify(); //校验数据是否正确
*5.write_code_init(); //写入code前需初始化相关buf
*6.write_code_start(0,RES_BASE_ADDR, res_len); //设res.bin区域地址和大小RES_BASE_ADDR初始地址res_len文件大小需512byte对齐
*7.write_code(test_buf); //循环写入app.bin数据
*8.write_code_verify(); //校验数据是否正确
*9.以上步骤为app.bin和res.bin升级步骤flash擦读写操作已经整合函数10.以下为ui升级步骤
*10.ui升级区域不设值加解密用标准flash擦读写接口即可详见api_flash.h
*擦void os_spiflash_erase(u32 addr);
*读uint os_spiflash_read(void *buf, u32 addr, uint len);
*写void spiflash_program(void *buf, u32 addr, uint len);
*/
u8 test_buf[512] AT(.buf.test);
AT(.com_text.spiflash)
bool ota_demo(void)
{
//升级文件中app.bin存放位置和大小
int file_addr = 0x100000;
int file_len = 0x61400;
//升级文件中res.bin存放位置和大小
int res_addr = 0x100000;
int res_len = 0x0;
int i;
//buf初始化
write_code_init();
//写入code区数据
TRACE("write_code\n");
//设置app.bin初始存放地址
write_code_start(0, CODE_BASE_ADDR, file_len);
//读取升级数据写入app.bin数据
for (i=0; i<file_len; i+=512) {
WDT_CLR();
spiflash_read_dis(test_buf, file_addr, 512);
if (!write_code(test_buf)) {
return false;
}
file_addr += 512;
}
//校验code区数据
TRACE("write_code_verify\n");
if (!write_code_verify()) {
return false;
}
//写入res区数据
TRACE("write_res\n");
//设置res.bin初始存放地址
write_code_start(1, RES_BASE_ADDR, res_len);
//读取升级数据写入res.bin数据
for (i=0; i<res_len; i+=512) {
WDT_CLR();
spiflash_read(test_buf, res_addr, 512, 0, 0xff);
if (!write_code(test_buf)) {
return false;
}
res_addr += 512;
}
//校验res区数据
TRACE("write_res_verify\n");
if (!write_code_verify()) {
return false;
}
TRACE("ota ok\n");
return true;
}
//正常启动Main函数启动升级流程
int main(void)
{
printf("Hello AB5680: %08x\n", (LVDCON & 0x1ff0000));
bsp_sys_init();
func_run();
return 0;
}