你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F407VG Bootloader 跳转异常

[复制链接]
patch1582 提问时间:2026-7-13 15:06 / 未解决

我正在编写 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; }

收藏 评论2 发布时间:2026-7-13 15:06

举报

2个回答
butterflyspring 回答时间:前天 16:11
这个型号的升级代码,在库里面都有现成的呀。

现在的小伙伴们都参照甚至直接用的。

经典型号哦,都用了十多年了。

废鱼 回答时间:昨天 15:37

如果注释掉PerformFirmwareUpdate可以正常运行,说明PerformFirmwareUpdate的代码 有问题。在操作FLASH前,需要先解锁FLASH,建议参考FLASH的完整操作DEMO进行修改。

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版