STM32L073RZ(rev Z)IAP跳转到引导加载程序(系统内存) [英] STM32L073RZ (rev Z) IAP jump to bootloader (system memory)

查看:415
本文介绍了STM32L073RZ(rev Z)IAP跳转到引导加载程序(系统内存)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用STM32L073RZ(Nucleo 64板).

I use the STM32L073RZ (Nucleo 64 board).

我想跳入应用程序编程(IAP)的系统内存中.

I would like to jump into the system memory in application programming (IAP).

我的代码适用于STM32L073微控制器的修订版B,但不适用于最新的修订版Z.

My code works on the revision B of the STM32L073 microcontroller but fails on the latest revision, rev Z.

我阅读了勘误表,没有给出任何详细信息,只是根据BFB2位,将双引导机制限制在系统内存中.

I read the errata sheet, no details are given, just a limitation fixed on the dual boot mechanism into system memory according to the BFB2 bit.

系统内存是否不再支持IAP跳转来执行其代码(通过USB或UART而不使用BOOT0引脚来刷新固件)?

Is the system memory no longer supports an IAP jumping to execute its code (to flash firmwares through USB or UART without using the BOOT0 pin) ?

该函数是主程序的第一行,它测试代码是否必须跳转到booloader:

The function is the first line of my main program, it tests if the code has to jump to the booloader:

void jumpBootLoader(void)
{
    /* to do jump? */
    if ( *((unsigned long *)0x20003FF0) == 0xDEADBEEF  ) 
    {
        /* erase the label */
        *((unsigned long *)0x20003FF0) = 0xCAFEFEED;

        /* set stack pointer to the bootloader start address */
        __set_MSP(*((uint32_t*)(0x1FF00000)));

        /* system memory mapped at 0x00000000 */
        __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

        /* jump to @bootloader + 4 */
        ((void (*)(void))(*((uint32_t*)(0x1FF00004))))();
    }
}   

在重置µC后,只要按下BP1按钮以触发跳转操作,我就会调用这两行:

I call these two lines as soon as the BP1 button is pressed to trig the jump operation after resetting the µC:

*((unsigned long *)0x20003FF0) = 0xDEADBEEF;
NVIC_SystemReset();

我使用HSI 16Mhz时钟源.

I use the HSI 16Mhz clock source.

推荐答案

解决方案是两次跳转到系统内存. 首先跳转到启动引导程序启动,以初始化RAM中的数据,直到程序计数器由Dualbank管理返回到Flash. 第二次跳转:跳转到Dualbank绕过的地址

The solution is to jump twice to the system memory. First Jump to bootloader startup to initialize Data in RAM until the Program counter will returned to Flash by the Dualbank management. Second Jump: Jump to the Dualbank bypassed address

使用方法:用户必须首先在Flash中初始化变量"Data_Address"(必须为Flash扇区对齐的偏移地址),以区分第一个/第二个Jump.

How to use: User has first to initialize a variable " Data_Address" (must be an offset Flash sector aligned address) in Flash to distinguish between first/second Jump.

EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = Data_Address;
EraseInitStruct.NbPages     = 1;


    First_jump = *(__IO uint32_t *)(Data_Address);

    if (First_jump == 0) {  
        HAL_FLASH_Unlock();
        HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Data_Address, 0xAAAAAAAA);
        HAL_FLASH_Lock();

        /* Reinitialize the Stack pointer and jump to application address */ 
        JumpAddress = *(__IO uint32_t *)(0x1FF00004);
    }
    if (First_jump != 0) {  
        HAL_FLASH_Unlock();
        HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);
        HAL_FLASH_Lock();

        /* Reinitialize the Stack pointer and jump to application address */ 
        JumpAddress =  (0x1FF00369);
    }

    Jump_To_Application = (pFunction) JumpAddress;
    __set_MSP(*(__IO uint32_t *)(0x1FF00000));
    Jump_To_Application(); 

这篇关于STM32L073RZ(rev Z)IAP跳转到引导加载程序(系统内存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆