在线时间302 小时
UID179403
ST金币1436
蝴蝶豆62
注册时间2015-1-9
该用户从未签到
金牌会员
- 最后登录
- 2021-12-18
|
最近研究ST芯片的内容ISP升级方法,按照官方推荐方式,需要设置BOOT引脚电平进入内容System Bootloader升级,感觉这种方式麻烦,所以查找是否可以软件方式直接跳转ISP进行升级;经过百度和各论坛查找资料,终于找到解决办法,并且经过验证大部分是可行的,少部分不行(暂时还没有搞清楚原因)
以下是软件跳转内容ISP的代码,可以直接调用即可:
/**
* Function to perform jump to system memory boot from user application
*
* Call function when you want to jump to system memory
*/
void JumpToBootloader(void) {
void (*SysMemBootJump)(void);
/**
* Step: Set system memory address.
*
* For STM32F429, system memory is on 0x1FFF 0000
* For other families, check AN2606 document table 110 with descriptions of memory addresses
*/
//volatile uint32_t addr = 0x1FFF0000;
/**
* Step: Set system memory address.
*
* For STM32F103, system memory is on 0x1FFF F000
* For other families, check AN2606 document table 110 with descriptions of memory addresses
*/
//volatile uint32_t addr = 0x1FFFF000;
/**
* Step: Set system memory address.
*
* For STM32F107, system memory is on 0x1FFF B000
* For other families, check AN2606 document table 110 with descriptions of memory addresses
*/
//volatile uint32_t addr = 0x1FFFB000;
/**
* Step: Set system memory address.
*
* For STM32F303, system memory is on 0x1FFF D800
* For other families, check AN2606 document table 110 with descriptions of memory addresses
*/
//volatile uint32_t addr = 0x1FFFD800;
/**
* Step: Set system memory address.
*
* For STM32L073, system memory is on 0x1FF0 0000
* For other families, check AN2606 document table 110 with descriptions of memory addresses
*/
volatile uint32_t addr = 0x1FF00000;
/**
* Step: Disable RCC, set it to default (after reset) settings
* Internal clock, no PLL, etc.
*/
#if defined(USE_HAL_DRIVER)
HAL_RCC_DeInit();
#endif /* defined(USE_HAL_DRIVER) */
#if defined(USE_FULL_LL_DRIVER)
LL_RCC_DeInit();
#endif
#if defined(USE_STDPERIPH_DRIVER)
RCC_DeInit();
#endif /* defined(USE_STDPERIPH_DRIVER) */
/**
* Step: Disable systick timer and reset it to default values
*/
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Disable all interrupts
*/
__disable_irq();
/**
* Step: Remap system memory to address 0x0000 0000 in address space
* For each family registers may be different.
* Check reference manual for each family.
*
* For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])
* For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])
* For others, check family reference manual
*/
//Remap by hand... {
#if defined(STM32F4)
SYSCFG->MEMRMP = 0x01;
#endif
#if defined(STM32L0)
SYSCFG->CFGR1 = 0x01;
#endif
#if defined(STM32F0)
SYSCFG->CFGR1 = 0x01;
#endif
//} ...or if you use HAL drivers
//__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you
/**
* Step: Set jump memory location for system memory
* Use address with 4 bytes offset which specifies jump location where program starts
*/
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
/**
* Step: Set main stack pointer.
* This step must be done last otherwise local variables in this function
* don't have proper value since stack pointer is located on different position
*
* Set direct address location which specifies stack pointer in SRAM location
*/
__set_MSP(*(uint32_t *)addr);
/**
* Step: Actually call our function to jump to set location
* This will start system memory execution
*/
SysMemBootJump();
/**
* Step: Connect USB<->UART converter to dedicated USART pins and test
* and test with bootloader works with STM32 Flash Loader Demonstrator software
*/
}
然后介绍下测试结果:
1、F0系列:STM32F030、STM32F051、STM32F070、STM32F071和STM32F072芯片,其中除STM32F070跳转运行ISP运行错误(发现内部ISP代码好像有问题,具体也不确定)外,均可以支持软件跳转ISP后串口方式升级;
2、F1系列:STM32F103和STM32F107芯片,均可以支持软件跳转ISP后串口方式升级;
3、F2系列:无芯片平台验证;
4、F4系列:STM32F407芯片,支持软件跳转ISP后串口方式升级;
5、L0系列:STM32L073芯片,支持软件跳转ISP后串口方式升级;
6、L4系列:STM32L4R5芯片,软件跳转ISP后运行直接跳转Hardfault(后续查找原因);
7、其它系列均无平台验证;
|
|