|
我正在编写 Bootloader,参考了论坛大量帖子完成跳转代码。 如果注释掉固件升级函数PerformFirmwareUpdate(),跳转运行完全正常。 typedef void (*pFunction)(void); pFunction appEntry; uint32_t appStack; HAL_Init(); / Get the application stack pointer (First entry in the application vector table) / appStack = (uint32_t) ((__IO uint32_t)EXEC_ZONE_ADDR); / Get the application entry point (Second entry in the application vector table) / appEntry = (pFunction) (__IO uint32_t) (EXEC_ZONE_ADDR);// + 4); if (CheckFirmwareUpdate) //PerformFirmwareUpdate(); HAL_DeInit(); / Reconfigure vector table offset register to match the application location / SCB->VTOR = EXEC_ZONE_ADDR; / Set the application stack pointer / __disable_irq(); __set_MSP(appStack); __DSB(); / Start the application / appEntry(); when i uncomment the function which copies the program in the execution sector (5), then i get the problem: the appEntry gets the value of sector 6 instead of sector 5 which is the real value assigned. void PerformFirmwareUpdate(void) { if (FlashErase(FLASH_SECTOR_5))//(FLASH_SECTOR_5); { uint32_t data_ptr = (uint32_t )PROG_ZONE_ADDR; HAL_FLASH_Unlock(); for(uint32_t i = 0; i < (SECTOR_SIZE); i += sizeof(uint32_t), data_ptr++ ) { if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EXEC_ZONE_ADDR + i, *data_ptr) != HAL_OK) { //WORD = 32bits break; } FLASH_WaitForLastOperation (4000); //in ms, max time to erase whole sector; see datasheet } HAL_FLASH_Lock(); } return; } |
微信公众号
手机版
现在的小伙伴们都参照甚至直接用的。
经典型号哦,都用了十多年了。
如果注释掉PerformFirmwareUpdate可以正常运行,说明PerformFirmwareUpdate的代码 有问题。在操作FLASH前,需要先解锁FLASH,建议参考FLASH的完整操作DEMO进行修改。