Thanks for the suggestions everyone!
I managed to do it. And it actually wasn't hard at all. Here's some of the code - for anyone with the same issue.
The actual memory "allocation" (I put it in a separate .c file):
#include "stm32f4xx.h"
#pragma location=0x800C000
volatile const uint8_t flash_data[2048] = {0xFF,0xFF,0xFF, ... ,0xFF};
And then the actual saving:
uint8_t flash_status;
void save_data_to_flash() {
flash_status = FLASH_COMPLETE;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
flash_status = FLASH_EraseSector(FLASH_Sector_3, VoltageRange_3);
if (flash_status != FLASH_COMPLETE) {
FLASH_Lock();
return;
}
uint8_t* address = &flash_data[0];
//program first run status bit
flash_status = FLASH_ProgramByte((uint32_t)address, 0x00);
address += 4;
if (flash_status != FLASH_COMPLETE) {
FLASH_Lock();
return;
}
...
}
The only thing worth mentioning is that you need to save data to the right address or else you get those ARM alignment issues and the flashing fails - that's why I used 4 bytes to save a single byte.