I am working on UTest programming on the S32K311 Microcontroller, and I am encountering a Read-While-Write Error (RWE) along with a controller crash during flash programming.
Issue:
After triggering the UTest programming sequence:
The controller jumps to the default handler (crash)
The RWE (Read While Write Error) flag is set
Context:
Application is executing from PFlash @ 0x00480000
UTest programming is initiated while running from PFlash
The actual trigger function (EHV set + polling) is executed from RAM
Implementation Flow:
1. Initialization & Preparation (FLASH_gSetPublicKey_Prepare)
Unlock UTest sector: PFLASH.PFCBLKU_SPELOCK[0].R &= ~(1U << 0);
Reset operation mode bits:EHV = 0,PGM = 0,ERS = 0
Clear status flags
Load target address: PFLASH.PFCPGM_PEADR_L.R = 0x1B000100U;
Load data into flash registers:
for (i = 0U; i < FLASH_lNumOfWords; i++)
{
FLASH.DATA[i].R = FLASH_pSrc[i];
}
Enable program mode: FLASH.MCR.B.PGM = 1U;
2. Programming Execution (from RAM) (FLASH_gSetPublicKey_Trigger)
Start programming: FLASH.MCR.B.EHV = 1U;
Poll until completion: Wait for DONE = 1
Stop programming:
FLASH.MCR.B.EHV = 0U;
FLASH.MCR.B.PGM = 0U;
Re-lock UTest sector
Observations:
Even though the trigger function runs from RAM, the system still:
Encounters RWE error & Jumps to default handler
Based on the above flow, I would appreciate if you could help identify the exact cause of the RWE fault and suggest the necessary corrections to ensure reliable UTest programming.
Thanks.