I analyzed the problem in detail and would like to present the result of my measurements.
I developed two programs. The first uses the CTIMER0 timer interrupt to toggle a CPU pin with a period of 20 microseconds (10 microseconds OFF and 10 microseconds ON).
The clock source for CTIMER0 is the Main CLOCK at 96MHz. As seen in the image, the period does not change both before and after the write operation. (see the A1-A2 and B1-B2 cursors)
This means that the 96MHz clock doesn't change, but, as can be noted, interrupts are disabled for approximately 500 microseconds during the flash write phase. (see the C1-C2 cursors)
// PROGRAM 1
uint8_t buffer[128];
volatile int32_t OnOff = 1;
int main(void) {
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
// BOARD_InitDebugConsole();
#endif
memoryFlash.init();
for(int i=0;i<128;i++) {
buffer[i]=(uint8_t)i;
}
SDK_DelayAtLeastUs(100, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
memoryFlash.flashWrite(buffer,128);
SDK_DelayAtLeastUs(100, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
while(1);
return 0;
}
// INTERRUPT ROUTINE
void TestBit(uint32_t flg)
{
GPIO_PinWrite(BOARD_INITPINS_RS485_TX_GPIO, BOARD_INITPINS_RS485_TX_GPIO_PIN, OnOff);
OnOff = !OnOff;
}
Image 1
_Ferrari__0-1761556500148.png
The second program toggles the CPU pin 10 times using a dedicated routine (togglePin).
As seen in the image, before the write operation, the period is approximately 640 nanoseconds (320 OFF and 320 ON).
(see the A1-A2 cursor on the image 2)
After the flash write operation, the half-period lengthens by about three times (from 320 nanoseconds to 1.52 microseconds) (wait states are probably being added). (see the B1-B2 cursor on the image 3)
This obviously slows down the program execution.
// PROGRAM 2
flash memoryFlash;
uint8_t buffer[128];
volatile int32_t OnOff = 1;
static void togglePin()
{
for(int i=0;i<10;i++) {
GPIO_PinWrite(BOARD_INITPINS_RS485_TX_GPIO, BOARD_INITPINS_RS485_TX_GPIO_PIN, OnOff);
OnOff = !OnOff;
}
}
int main(void) {
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
// BOARD_InitDebugConsole();
#endif
memoryFlash.init();
for(int i=0;i<128;i++) {
buffer[i]=(uint8_t)i;
}
togglePin();
memoryFlash.flashWrite(buffer,128);
togglePin();
while(1);
return 0;
}
Image 2
_Ferrari__1-1761557055673.png
Image 3
_Ferrari__2-1761557100481.png
Therefore:
1) How can I prevent interrupts from being disabled during the flash write operation?
2) How can I prevent the program from slowing down after the flash write operation?
Thank you very much for your help and cooperation
regards