2024-07-10 07:39 AM
Hi,
I have been trying to trigger a RAM ECC error for testing. I have referenced the code Here. However, I cant trigger an ecc error.
The plan is to read uninitialized ram as mentioned in AN5342. I am using SRAM(1-3) (Mem address 0x30000000 - 0x30047FFF). Please find the code snippet below.
RAMECC_HandleTypeDef hramecc2_m1;
RAMECC_HandleTypeDef hramecc2_m2;
RAMECC_HandleTypeDef hramecc2_m3;
RAMECC_HandleTypeDef hramecc2_m4;
RAMECC_HandleTypeDef hramecc2_m5;
#define SRAM_3_START (char*)0x30040000
#define SRAM_3_END (char*)0x30047FFF
#define SRAM_2_START (char*)0x30020000
#define SRAM_2_END (char*)0x3003FFFF
#define SRAM_1_START (char*)0x30000000
#define SRAM_1_END (char*)0x3001FFFF
static void MX_RAMECC_Init(void)
{
/* USER CODE BEGIN RAMECC_Init 0 */
/* USER CODE END RAMECC_Init 0 */
/* USER CODE BEGIN RAMECC_Init 1 */
/* USER CODE END RAMECC_Init 1 */
/** Initialize RAMECC2 M1 : SRAM1_0
*/
hramecc2_m1.Instance = RAMECC2_Monitor1;
if (HAL_RAMECC_Init(&hramecc2_m1) != HAL_OK)
{
Error_Handler();
}
/** Initialize RAMECC2 M2 SRAM1_1
*/
hramecc2_m2.Instance = RAMECC2_Monitor2;
if (HAL_RAMECC_Init(&hramecc2_m2) != HAL_OK)
{
Error_Handler();
}
/** Initialize RAMECC2 M3 : SRAM2_0
*/
hramecc2_m3.Instance = RAMECC2_Monitor3;
if (HAL_RAMECC_Init(&hramecc2_m3) != HAL_OK)
{
Error_Handler();
}
/** Initialize RAMECC2 M4 : SRAM2_1
*/
hramecc2_m4.Instance = RAMECC2_Monitor4;
if (HAL_RAMECC_Init(&hramecc2_m4) != HAL_OK)
{
Error_Handler();
}
/** Initialize RAMECC2 M5 : SRAM3
*/
hramecc2_m5.Instance = RAMECC2_Monitor5;
if (HAL_RAMECC_Init(&hramecc2_m5) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RAMECC_Init 2 */
INIT_RAMECC(&hramecc2_m1);
INIT_RAMECC(&hramecc2_m2);
INIT_RAMECC(&hramecc2_m3);
INIT_RAMECC(&hramecc2_m4);
INIT_RAMECC(&hramecc2_m5);
/* NVIC configuration for RAMECC interrupt */
/* Priority: high-priority */
HAL_NVIC_SetPriority(ECC_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(ECC_IRQn);
/* USER CODE END RAMECC_Init 2 */
}
void INIT_RAMECC(RAMECC_HandleTypeDef* hramecc){
/* Enable monitor notifications */
/* ECC single error notification and ECC double error notification */
if (HAL_RAMECC_EnableNotification(hramecc, (RAMECC_IT_MONITOR_SINGLEERR_R | RAMECC_IT_MONITOR_DOUBLEERR_R))!= HAL_OK)
{
Error_Handler();
}
/* Start Monitor : Enable latching failing information
Failing information : * Failing address
* Failing Data Low
* Failing Data High
* Hamming bits injected
*/
if (HAL_RAMECC_StartMonitor(hramecc) != HAL_OK)
{
Error_Handler();
}
}
int main(void)
{
/* USER CODE BEGIN 1 */
CPU_CACHE_Enable();
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RAMECC_Init();
/* USER CODE BEGIN 2 */
/* Analyse all memory */
volatile uint32_t* mem_pointer = (volatile uint32_t*)SRAM_1_START;
while(1){
CurrentData = *mem_pointer;
mem_pointer++;
if(mem_pointer >= (volatile uint32_t*)SRAM_1_END){
break;
}
}
mem_pointer = (volatile uint32_t*)SRAM_2_START;
while(1){
CurrentData = *(mem_pointer);
mem_pointer++;
if(mem_pointer >= (volatile uint32_t*)SRAM_2_END){
break;
}
}
mem_pointer = (volatile uint32_t*)SRAM_3_START;
while(1){
CurrentData = *(mem_pointer);
mem_pointer++;
if(mem_pointer >= (volatile uint32_t*)SRAM_3_END){
break;
}
}
HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_13);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(HAL_RAMECC_IsECCSingleErrorDetected(&hramecc2_m1) |
HAL_RAMECC_IsECCSingleErrorDetected(&hramecc2_m2) |
HAL_RAMECC_IsECCSingleErrorDetected(&hramecc2_m3) |
HAL_RAMECC_IsECCSingleErrorDetected(&hramecc2_m4) |
HAL_RAMECC_IsECCSingleErrorDetected(&hramecc2_m5)){
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_2, GPIO_PIN_RESET);
}
if(HAL_RAMECC_IsECCDoubleErrorDetected(&hramecc2_m1) |
HAL_RAMECC_IsECCDoubleErrorDetected(&hramecc2_m2) |
HAL_RAMECC_IsECCDoubleErrorDetected(&hramecc2_m3) |
HAL_RAMECC_IsECCDoubleErrorDetected(&hramecc2_m4) |
HAL_RAMECC_IsECCDoubleErrorDetected(&hramecc2_m5)){
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_2, GPIO_PIN_RESET);
}
}
/* USER CODE END 3 */
}
Something I noticed is that even after a cold boot, the SRAM is still set to 0. Which would explain why an ecc error isn't triggered.
Any idea what Im missing? Thanks!