2023-04-05 12:02 PM
I made a mistake a few days ago that resulted in my program erasing part of itself.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
I'm doing a bare metal bootloader on a STM32F407VE and have run into some weird behaviour after erasing sector 4.
Here's the loop I use to do the erasing:
#define APP_first_sector 2
#define LAST_SECTOR 7
HAL_FLASH_Unlock();
for (uint32_t i = APP_first_sector; i <= LAST_SECTOR; i++) {
print("Erasing sector: %d\n",(uint16_t)i);
FLASH_Erase_Sector(i, VOLTAGE_RANGE_3);
print("finished sector: %d\n",(uint16_t)i);
}
HAL_FLASH_Lock();
All print statements executed after erasing sector 4 hang. The hang is in the processing of the VA_ARGS list. It never completes.
I can get around this by adding a '\0' to all print statements executed after the erase sector command. This explicitly adds the terminating code to the va_args list but gives compile warnings.
print("Erasing sector: %d\n\0",(uint16_t)i);
I've done a lot of variations on the loop and the only time there are problems is immediately after erasing sector 4. I can erase sectors 2,3,5, 6 or 7 without issues.
I'm using Ozone to debug the program. I don't see anything unusual/different in the FLASH ACR or status registers after the sector erases.
I've thrown a lot of things into and around the loop to see if anything helps. Here's some of the things I've unsucessfully tried:
The weirdest thing is this failing mode is only cleared when I use Ozone to rewrite the bootloader image. Pressing the reset button, issuing a reset via Ozone and even removing power from the board doesn't fix this. A diff of the FLASH when in the failing mode and after a new download didn't show any problems/differences.
I'm confused.
Edited by moderation team to adhere to community guidelines.
2023-04-05 12:29 PM
Please edit and expand on the details of the problem(s)
2023-04-05 05:18 PM
Is any of your code in the sector you are erasing?
Do you have the VCAP pins wired properly, with the right capacitors?
2023-04-05 06:27 PM
Bingo - I was erasing part of my program.
2023-04-06 05:12 AM
Hello @BKuhn,
The user area should be in another bank than the code.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.