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.
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.