I have been setting up a method to jump to the DFU bootloader for an STM32F405RG with the code provided in the link below (which I have received from other mbed forum posts) and the addresses should work for any STM32F4 chip based on what I have read. I have built the main.cpp and put it in the dfu-util folder for upload, but when I check for dfu devices in the command prompt, the chip doesn’t seem to go into DFU mode. There may also be a missing config in my custom_targets.json so please point anything out that causes the bootload code to not work.
i.e. set a flag on application and reset, then check it in SystemInit(), where the peripherals are not yet initialized. The problem with jumping from application is that some peripherals (e.g. clocks) are initialized in such a way, where it gets pretty hard to deinit everything.
Would you mind elaborating what needs to be done with the SystemInit() function? I don’t exactly understand the code in the link you provided. My apologies for being slightly slow.
*((unsigned long *)0x2001FFF0) = 0xDEADBEEF;
// Reset the processor
NVIC_SystemReset();
In SystemInit() I do the check and jump like this:
// Check if a software jump to the bootloader section is required
static void (*SysMemBootJump)(void);
// Check if the bootloader flag is set
if (*((unsigned long *)0x2001FFF0) == 0xDEADBEEF)
{
// Reset our trigger
*((unsigned long *)0x2001FFF0) = 0xCAFECAFE;
// Set the SP to the default value
__set_MSP(*(volatile uint32_t *)0x00000000);
// Set the PC to the System Memory reset vector (+4)
SysMemBootJump = (void (*)(void))(*((uint32_t *)0x1FFF0004));
// Jump to bootloader
SysMemBootJump();
}
Modify the flag address & value to your preference. Also the jump address might differ between STM32 models, better check the bootloader docs/datasheet for that.
Thanks for that information. I tried doing that after modifying the addresses correctly, but it still doesn’t enter DFU through the command line. I also want to use mbed os 5 to perform this and I am using a custom target for the F405 board that I created myself. Do you think there is something I’m missing in the target or in mbed that is causing this?
I believe I can’t help you further. The previous code is what I use. You have to make sure you jump into the right address before any peripherals are initialized.