Thank you.
I tried this just now.
Turns out, when everything is in SRAM, no lockup happens (at least not within seconds after startup like it was before). The only code that's still in flash is everything that happens before main() is called.
But as soon as a function like main() or only a small function like this:
void SWI_vCloseSwitch(void) {
GPIOD_PSOR = PORT_PD5;
}
(which is executed periodically between the flash writes) is moved back into the flash, the lockup happens.
Even though this function is only called before my flash write function, and never in interrupts.
By the way, currently I compile with -O0, so I doubt this is some compiler function rearangement problem.
Could it be that I made a mistake in interacting with the CCIF flag?
I now have this function in RAM:
__attribute__ ((section(".custom_ramfunctions")))
void vStartFlashCommand(void) {
//Start command
FTFA_FSTAT = FTFA_FSTAT_CCIF;
//Wait for completion
while (!(FTFA_FSTAT & FTFA_FSTAT_CCIF));
}
From what I understand, the first line initiates the flash write (or whatever I set in the control registers beforehand). When this happens the CCIF flag should be 0 until the operation is completed.
Therefore the while loop should prevent the execution of any non-interrupt code while the flash operation is in progress.
Am I mistaken here?
However, if I wrap those two lines with
__asm volatile ("cpsid i" : : : "memory");
__asm volatile ("cpsie i" : : : "memory");
then again no lockup happens, but then obviously some UART bytes get lost due to disabled interrupts.