0
\$\begingroup\$

I'm trying to write bootloader code and I needed to be able to use an address in flash memory as a flag to the bootloader to let it know if it should enter bootloader or the application. I'm able to write a value into the flash address but I'm having issue with the bootloader clearing that flag at that flash address. I was wondering if there's a way to erase a certain address rather a sector in flash or if there was another way to use a register or flash address as a flag that can be set and cleared. The mcu I'm using is STM32F407vgt6.

\$\endgroup\$
  • \$\begingroup\$ No, that isn't really the way that flash works. Since I assume the user app sets the flag and then reboots, why not use a RAM address instead? It shouldn't be cleared out in the reboot (as long as its a power-on reset) and should easily be cleared... \$\endgroup\$ – Ron Beyer Feb 14 at 13:55
  • \$\begingroup\$ some flashes you erase a block but then can write and overwrite the same locations individual, for example an erase makes everything ones and you can for the same location change bits to zeros without an erase. another option though is essentially a linked list or array, starting at some address in flash walk through memory one byte at a time until you hit the erased value , the last one before that is the last write the last desired option. so maybe 01, 02, 01, 02, 01, 01, ff and 01 would be the option. then you rarely have to erase the block to start over. \$\endgroup\$ – old_timer Feb 14 at 16:15
  • \$\begingroup\$ for that scheme 1) have the erase value default to one of the options in case that is the first value found, 2) you need to dedicate a whole erase block to this flag. so you cant just halve and ping pong the flash or something like that, and I didnt look to see how this part erases blocks if you can leave one unerased but erase others. \$\endgroup\$ – old_timer Feb 14 at 16:18
  • \$\begingroup\$ some parts have eeproms some parts have flash pretending to be eeproms for sorta these kinds of things but as pointed out be VERY careful about the overall number of erase cycles. erasing the flash in general should be a rare thing. \$\endgroup\$ – old_timer Feb 14 at 16:19
1
\$\begingroup\$

Assuming a NOR flash you have to erase entire sector everytime when you have to update the contents of it, even if it is. Single byte.

If the bootloader seldom does the wrote operation, it is okay to reserve the whole sector to store your flag. When you need to clear it, you have to erase the whole sector and wait until it is complete.

I would like to also add that, please take care to see that the maximum number of allowed flash erase operations isn't crossed.
You can find that information in the datasheet. Probably I would not cross not even 10 percent of what datasheet claims as maximum supported number of flash writes/erases.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks, guess I'll have to have the bootloader ask a server if an update is available in order to decide if it should jump to an application or run the bootloader. \$\endgroup\$ – doge Feb 14 at 14:38
  • \$\begingroup\$ The STM32F70x also has 4Kb of backup SRAM which is protected, and is maintained in Standby or VBAT mode. \$\endgroup\$ – Ron Beyer Feb 14 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.