3

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

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.

4

2 回答 2

2

我认为用户@JF002 所指的“备份寄存器”是STM32 板载的SRAM。以下对我有用:

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

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

在您的程序期间使用以下命令写入A_VALUE备份寄存器:

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

OFFSET要写入 SRAM 的地址在哪里。用于0第一个地址。

使用 发出软复位命令NVIC_SystemReset()

在启动时,阅读(*(__IO uint32_t *) (BKPSRAM_BASE + OFFSET))并检查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();
}
于 2017-05-26T14:21:38.660 回答
-1

我对男人的回答有一个小问题。我的问题是,当您打开系统电源时,您选择的任何内存位置的值与 A_VALUE 相同的概率非零。如果发生这种情况,则软件无法判断它读取的值 (A_VALUE) 是由于它在软复位之前已写入内存位置,还是仅由于随机机会。

如果 OP 采用前者,则系统会不恰当地启动引导加载,并有可能破坏软件。如果他/她假设后者,则将错过所需的引导加载。两者都不可接受。

一个改进是拥有更安全的身份验证,其中随机模式被写入内存块,只要系统通电,该内存块就会保存,并且 CRCC(循环冗余码校验)在该块上竞争。然后在软重启时,再次计算 CRCC。如果答案仍然有效,则该块完好无损,并且可以假定引导是由软重启引起的。

完美吗?不,但是内存字节块中的所有位碰巧产生正确的 CRCC 值的概率比一些少量位导致值 A_VALUE 被读取的概率要小得多。

于 2019-09-04T20:39:55.423 回答