STM32F4 Go to bootloader via SoftReset and without BOOT0 and BOOT1 Pin

I am asking because of an answer to a similar quastion which can be found here: Go to bootloader in STM32 using an application i.e. use Boot 0 and Boot 1 Pins in User flash boot mode

User "JF002" @ JF002 replied "When I want to go to the bootloader, I write a byte in one of the reserved registers and then issue a soft-reset. Then, when the processor reboots, at the very beginning of the program, it will read that register. This register contains a value indicating that it should be rebooted in bootloader mode. This makes the transition to the bootloader much easier. "

Can someone explain this solution to me step by step or show some example code? At this time, I am writing my exam, and I really rely on help with this, because this is only a small part with programming and I have no experience with it.

+3


source to share


2 answers


What I think user @ JF002 is referring to "reserve register" is SRAM onboard STM32. The following worked for me:

Set up spare 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);

      

Write A_VALUE

to the fallback register during your program using:

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



where OFFSET

is the address to write to SRAM. Use 0

for the first address.

Execute a soft reset command using NVIC_SystemReset()

.

When downloading, read (*(__IO uint32_t *) (BKPSRAM_BASE + OFFSET))

and check 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();
}

      

+2


source


I have a little problem with the male answer. My problem is that there is a non-zero chance that the value of whatever memory area you choose will be the same as A_VALUE when the system is turned on. If this happens, then the program will not be able to determine whether the read value (A_VALUE) was due to the fact that it was written to the memory location before the soft reset, or only because of a random selection.

If the OP assumes the former, then the system starts the boot system inappropriately with the possibility of software overload. If he / she accepts the latter, then the requested download will be skipped. Neither one nor the other is acceptable.



An improvement would be to have a more secure authentication in which a random pattern was written to a block of memory that is retained as long as the system is powered on and a CRCC (Cyclic Redundancy Check) competed for that block. Then, on a soft reset, the CRCC is calculated again. If the answer is still valid, the block is not corrupted, and it can be assumed that the download was caused by a soft restart.

It's perfect? No, but the probability that all the bits in a block of memory bytes result in the correct CRCC value is much less than the probability of a small number of bits causing the A_VALUE value to be read.

0


source







All Articles