STM32F4通过SoftReset跳转到Bootloader且没有BOOT0和BOOT1引脚 [英] STM32F4 Jump to Bootloader via SoftReset and without BOOT0 and BOOT1 Pin

查看:636
本文介绍了STM32F4通过SoftReset跳转到Bootloader且没有BOOT0和BOOT1引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之所以问是因为有一个类似问题的答案,可以在这里找到:

i ask because of an answer to a similar quastion which can be found here: Jump to Bootloader in STM32 through appliction i.e using Boot 0 and Boot 1 Pins in Boot mode from User flash

用户"JF002" @ JF002回答当我想跳到引导加载程序时,我在备份寄存器之一中写入一个字节,然后进行软复位.然后,当处理器重新启动时,程序开始时,它将读取该寄存器.该寄存器包含指示应在引导加载程序模式下重新启动的值.然后,跳转到引导加载程序会容易得多".

The User "JF002" @JF002 answered "When I want to jump to the bootloader, I write a byte in one of the backup register and then issue a soft-reset. Then, when the processor will restart, at the very beginning of the program, it will read this register. This register contains the value indicating that it should reboot in bootloader mode. Then, the jump to the bootloader is much easier"

有人可以向我逐步说明该解决方案或显示代码示例吗? 这时候我写了我的考试,我真的很乐意提供帮助,因为它只是编程的一小部分,我对此没有经验.

Can someone explain that solution to me step-by-step or show a code example? At this time i write my exam and i am really reliant to help about this because it is only a little part with programming and i have no experience in that.

推荐答案

我认为用户@ JF002通过备份寄存器"所指的是STM32板上的SRAM.以下对我有用:

What I think User @JF002 is referring to by "backup register" is the SRAM onboard the STM32. The following has worked for me:

在程序的开头使用以下命令配置备份寄存器:

Configure backup registers at the beginning of the program using:

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
PWR_BackupRegulatorCmd(ENABLE);

在程序执行期间使用以下方法将A_VALUE写入备份寄存器:

Write A_VALUE to a backup register during your program using:

(*(__IO uint32_t *) (BKPSRAM_BASE + OFFSET)) = A_VALUE;

其中,OFFSET是要写入SRAM的地址.使用0作为第一个地址.

where OFFSET is the address to write in SRAM. Use 0 for first address.

使用NVIC_SystemReset()发出软重置命令.

在启动时,阅读(*(__IO uint32_t *) (BKPSRAM_BASE + OFFSET))并检查A_VALUE:

On boot, read (*(__IO uint32_t *) (BKPSRAM_BASE + OFFSET)) and check for A_VALUE:

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
PWR_BackupRegulatorCmd(ENABLE);    

void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x1FFF0000; // For STM32F4 Discovery

if((*(__IO uint32_t *) (BKPSRAM_BASE + 0)) == A_VALUE) 
{
  (*(__IO uint32_t *) (BKPSRAM_BASE + 0)) = 0; // Reset memory, if desired.

  SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4))); // Set Bootloader address

  __set_MSP(*(uint32_t *)addr); // Move Stack Pointer

  SysMemBootJump(); // Execute Bootloader
}
else
{
  RunYourApplication();
}

这篇关于STM32F4通过SoftReset跳转到Bootloader且没有BOOT0和BOOT1引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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