搜索
查看: 3649|回复: 2

[分享] STM32L4R5ZIT6软件跳转ISP运行Hardfault问题

[复制链接]

该用户从未签到

6

主题

547

帖子

62

蝴蝶豆

金牌会员

最后登录
2021-12-18
发表于 2019-11-14 14:08:47 | 显示全部楼层 |阅读模式
最近研究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、其它系列均无平台验证;


回复

使用道具 举报

该用户从未签到

1

主题

346

帖子

2

蝴蝶豆

金牌会员

最后登录
2021-4-7
发表于 2019-11-19 08:51:33 | 显示全部楼层
签到
回复

使用道具 举报

该用户从未签到

0

主题

1

帖子

0

蝴蝶豆

新手上路

最后登录
2021-3-2
发表于 2020-7-11 12:17:31 | 显示全部楼层
请问你一下,SMT32L4R5ZIT6如何进入system bootloader?这个芯片只有BOOT0,在官网提供的开发板上,无论是置高还是置低,用那个demonstrator工具,也不能进行升级呢。
我用的开发板是官方的nucleo开发板,连接串口用的是lpuart1
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-5-8 18:28 , Processed in 0.148988 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表