共2条
1/1 1 跳转至页
IAP 贴个程序,请教关于IAP的问题,现在无法写入。

问
__asm{ //关闭中断
MSR CPSR_c,0xdf
}
PLLCON=0; //关闭PLL
PLLFEED=0xaa;
PLLFEED=0x55;
MAMCR=0; //关闭MAM
select_sector(8,8);
erase_sector(8,8);
select_sector(8,8);
ram_to_flash(0x00010000,(uint32)text,1024);
PLLCON=1;
PLLFEED=0xaa;
PLLFEED=0x55;
while((PLLSTAT&(1<<10))==0);
PLLCON=3;
PLLFEED=0xaa;
PLLFEED=0x55; //打开PLL
MAMCR=2; //打开MAM
__asm{ //打开中断
MSR CPSR_c,0x5f
}
void select_sector(unsigned long start_sector,
unsigned long end_sector)
{
command[0]=IAP_SELSECTOR;
command[1]=start_sector;
command[2]=end_sector;
iap_entry(command,result);
}
void ram_to_flash(unsigned long flash_addr,
unsigned long ram_addr,
unsigned long count)
{
command[0]=IAP_RAMTOFLASH;
command[1]=flash_addr;
command[2]=ram_addr;
command[3]=count;
command[4]=IAP_FCCLK;
iap_entry(command,result);
}
/*************************************************
Function:erase_sector()
Description:擦除扇区
Input:start_sector,end_sector
Output:none
*************************************************/
void erase_sector(unsigned long start_sector,
unsigned long end_sector)
{
command[0]=IAP_ERASESECTOR;
command[1]=start_sector;
command[2]=end_sector;
command[3]=IAP_FCCLK;
iap_entry(command,result);
}
尝试了很多次都没有成功,重新开机后读出来的全是FF。已经在编译器里勾选了ARM/THUMB interworking (包括汇编器、ARM C编译器、THUMB C编译器)
请不吝赐教!
答 1: 有一些进展了,但是还有不明白的地方执行ram_to_flash()后返回错误代码SRC_ADDR_ERROR,即源地址text[]没有字对齐。text[]我定义成字节数组uint8 text[1024],改成uing32 text[1024]就可以IAP写入了。可是我不明白的是,调用函数的时候是(uint32)text,难道这样还不能字对齐吗?
MSR CPSR_c,0xdf
}
PLLCON=0; //关闭PLL
PLLFEED=0xaa;
PLLFEED=0x55;
MAMCR=0; //关闭MAM
select_sector(8,8);
erase_sector(8,8);
select_sector(8,8);
ram_to_flash(0x00010000,(uint32)text,1024);
PLLCON=1;
PLLFEED=0xaa;
PLLFEED=0x55;
while((PLLSTAT&(1<<10))==0);
PLLCON=3;
PLLFEED=0xaa;
PLLFEED=0x55; //打开PLL
MAMCR=2; //打开MAM
__asm{ //打开中断
MSR CPSR_c,0x5f
}
void select_sector(unsigned long start_sector,
unsigned long end_sector)
{
command[0]=IAP_SELSECTOR;
command[1]=start_sector;
command[2]=end_sector;
iap_entry(command,result);
}
void ram_to_flash(unsigned long flash_addr,
unsigned long ram_addr,
unsigned long count)
{
command[0]=IAP_RAMTOFLASH;
command[1]=flash_addr;
command[2]=ram_addr;
command[3]=count;
command[4]=IAP_FCCLK;
iap_entry(command,result);
}
/*************************************************
Function:erase_sector()
Description:擦除扇区
Input:start_sector,end_sector
Output:none
*************************************************/
void erase_sector(unsigned long start_sector,
unsigned long end_sector)
{
command[0]=IAP_ERASESECTOR;
command[1]=start_sector;
command[2]=end_sector;
command[3]=IAP_FCCLK;
iap_entry(command,result);
}
尝试了很多次都没有成功,重新开机后读出来的全是FF。已经在编译器里勾选了ARM/THUMB interworking (包括汇编器、ARM C编译器、THUMB C编译器)
请不吝赐教!
答 1: 有一些进展了,但是还有不明白的地方执行ram_to_flash()后返回错误代码SRC_ADDR_ERROR,即源地址text[]没有字对齐。text[]我定义成字节数组uint8 text[1024],改成uing32 text[1024]就可以IAP写入了。可是我不明白的是,调用函数的时候是(uint32)text,难道这样还不能字对齐吗?
共2条
1/1 1 跳转至页
回复
打赏帖 | |
---|---|
分享一种检测按键状态的方法被打赏20分 | |
周末总结一下,STM32C0系列的开发经验被打赏50分 | |
【换取手持数字示波器】MicrochipMPLABHarmony框架下定时器配置被打赏20分 | |
【换取手持数字示波器】MicrochipMPLABHarmony框架下PWM配置被打赏20分 | |
【Cortex-M】Systick Timer使用被打赏10分 | |
分享汽车防盗系统的组成与分类(一)被打赏5分 | |
VOFA+波形显示+JYD-31蓝牙发送和解析不定长数据被打赏10分 | |
【换取手持数字示波器】-STM32F4PWM控制LED灯管亮度被打赏22分 | |
【换取手持数字示波器】STM32F4驱动RPR-0521RS照度、接近一体型传感器被打赏23分 | |
宏定义和const关键字定义被打赏5分 |