I am using the PIC24FJ128GA306 microcontroller and trying to reserve a block in flash memory to store persistent data. Here is the code snippet I am using to define and allocate the persistent data:
volatile const __prog__ __attribute__((space(prog), aligned(_FLASH_PAGE))) union {
uint16_t words[_FLASH_PAGE * 2];
persistent_struct persistent_data_alloc;
} persistent_data_allocation;
According to the datasheet, the smallest block I can erase and write to is 512 instructions, which is 1536 bytes. However, aligning my data in 1536-byte blocks is problematic because 1536 is not a power of 2.
I need to reserve this block of flash memory for my data, ensuring the rest of the program does not overwrite it. Additionally, when I erase the reserved block, I want to make sure the rest of the code is not affected.
My questions are:
- How can I correctly reserve a block of 1536 bytes in flash memory?
- How do I ensure the reserved block is not overwritten by other parts of my program?
- What is the best approach to handle the alignment and ensure the program does not interfere with the reserved block during erase operations?
Any advice or examples on handling this situation would be greatly appreciated.
Thank you!
.