U盘 iap功能:使用U盘进行程序升级,成功正确的将BIN文件写入了指定的地址,但程序跳转后无法执行。代码如下
#define FLASH_APP_ADDR 0x08040000
if(f_open(&file,"0:stm32.bin",FA_OPEN_ALWAYS|FA_READ) == FR_OK)
{
APP_Sector = file.fsize / 512;
APP_Byte = file.fsize % 512;
for(i = 0;i < APP_Sector;i++)
{
f_read (&file,ReadAppBuffer,512,(void *)&bytesread);
for(j = 0;j < 256;j++)
{
ChangeBuffer[j] = (ReadAppBuffer[j * 2 + 1] << 8) + ReadAppBuffer[j * 2];
}
for(k=0;k<50;k++);
GPIO_ToggleBits(GPIOC,GPIO_Pin_12);
uiFLASH_Write(FLASH_APP_ADDR + i * 512,ChangeBuffer,256);
}
if(APP_Byte != 0)
{
f_read (&file,ReadAppBuffer,APP_Byte,(void *)&bytesread);
for(j = 0;j < (APP_Byte / 2);j++)
{
ChangeBuffer[j] = (ReadAppBuffer[j * 2 + 1] << 8) + ReadAppBuffer[j * 2];
}
uiFLASH_Write(FLASH_APP_ADDR + i * 512,ChangeBuffer,APP_Byte / 2);
}
f_close(&file);
f_mount(NULL,"USB1",1); //f_mount(0, NULL);
}
if (((*(__IO uint32_t*)FLASH_APP_ADDR) & 0x2FFE0000 ) == 0x20000000)
{ /* Jump to user application */
JumpAddress = *(__IO uint32_t*) (FLASH_APP_ADDR + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) FLASH_APP_ADDR);
Jump_To_Application();
}
请教原子哥,可能导致问题的原因。万分感谢。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>