Because the Flash cannot be read when the internal Flash is erased, otherwise the Flash will be stopped. Under normal circumstances, the interrupt vector table and the interrupt processing function are stored in Flash. Therefore, when the internal Flash is erased, the system will usually shut down the total interruption, temporarily not responding to the external interruption. In this way, the system only performs the write and erase operations, instead of reading commands in Flash. Therefore, the Flash operation is normal.
Hardware: TG STK
Software: For the purpose of testing, add the 1 ms timer generated by ick to the program. As a test condition. Used to test whether Flash operations are normal.
The specific Demo is as follows:
# Include <stdint. h>
# Include <stdio. h>
# Include <stdbool. h>
# Include "efm32.h"
# Include "efm32_chip.h"
# Include "efm32_cmu.h"
# Include "efm32_msc.h"
Volatile uint32_t msTicks;
Const unsigned char ucWriteIn [8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G ', 'H ',};
Unsigned char ucReadOut [8];
Void javasick_handler (void)
{
MsTicks ++;
}
Void main (void)
{
CHIP_Init ();
/* Ensure core frequency has been updated */
SystemCoreClockUpdate ();
// Add a timer
If (SysTick_Config (SystemCoreClock/1000) while (1 );
MSC_Init (); // initialize MSC and enable AUXHFRCO
_ Disable_irq (); // close the total interruption.
If (MSC_ErasePage (uint32_t *) 0x0fe00000) = mscReturnOk)
{
MSC_WriteWord (uint32_t *) 0x0fe00000, ucWriteIn, 8 );
}
MSC_Deinit ();
Unsigned char * point = (unsigned char *) 0x0fe00000;
For (unsigned char I = 0; I <8; I ++)
{
If (* (point + I) = ucwritein [I]) continue;
Else
{
While (1); // error occur
}
}
_ Enable_irq (); // enable the total interrupt
While (1 );
}
As you can see, the Operation has been completed normally. Since it takes about 20 ms to erase data, and at least 20 US is required for each write of 4 bytes, this method is OK if it is not affected by 1 ms interruption.