on 2024-12-09 02:30 AM
When working with the STM32H5 series microcontrollers, understanding the behavior of reading unwritten One-Time Programmable (OTP) or flash high-cycle area data is crucial. This article addresses the feasibility and implications of such read operations.
According to RM0481 section 7.3.4, if the application reads an OTP data or flash high-cycle data not previously written, a double ECC error is reported and only a word full of set bits is returned. The ECC correction reports a double-error detection (ECCD) and ECCD implies an NMI raised.
To handle ECC errors, the solution involves checking inside the NMI handler whether the error is a real data error or an access error due to uninitialized memory.
By reading the value of the FLASH_ECCDR register, the handler can determine the nature of the error. If the memory is empty, the ECC error is due to access to uninitialized memory, and the ECCD flag should be cleared. If the error is a true data failure, appropriate error handling should be implemented.
Below is an example of an NMI handler for this scenario:
void NMI_Handler(void)
{
if((FLASH->ECCDR && 0xFF))
{
//the memory is empty
//ECC error due to access to uninitialized memory
//Clear the ECCD flag
FLASH->ECCDETR |= (1<<31);
}
else
{
//ECC error detected a true failure
while (1)
{
}
}
}