cancel
Showing results for 
Search instead for 
Did you mean: 

while i was executeing eeprom emulation code on stm32g0b1cbt6n ,while running I'm getting EE_TRANSFER_ERROR.

predd.21
Associate II

 MX_GPIO_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 HAL_NVIC_SetPriority(FLASH_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(FLASH_IRQn);

  /* Unlock the Flash Program Erase controller */

  HAL_FLASH_Unlock();

  /* Enable Power Control clock */

  __HAL_RCC_PWR_CLK_ENABLE();

  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);

  /* Configure Programmable Voltage Detector (PVD) (optional) */

  /* PVD interrupt is used to suspend the current application flow in case

    a power-down is detected, allowing the flash interface to finish any

    ongoing operation before a reset is triggered. */

  PVD_Config();

  /* Configure LED_KO & LED_OK */

//  HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);

  /* Activate NMI generation when two errors are detected */

  __HAL_FLASH_ENABLE_IT(FLASH_IT_ECCC);

  /* Set EEPROM emulation firmware to erase all potentially incompletely erased

    pages if the system came from an asynchronous reset. Conditional erase is

    safe to use if all Flash operations where completed before the system reset */

  if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET)

  {

   /* Blink LED_OK (Green) twice at startup */

  HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

   HAL_Delay(100);

   HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

   HAL_Delay(100);

   HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

   HAL_Delay(100);

   HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

   /* System reset comes from a power-on reset: Forced Erase */

   /* Initialize EEPROM emulation driver (mandatory) */

  

ERROR AT

 ee_status = EE_Init(EE_FORCED_ERASE);

   if(ee_status != EE_OK) {Error_Handler();}

  }

  //else

 {

   /* Clear the Standby flag */

   __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);

   /* Check and Clear the Wakeup flag */

   if (__HAL_PWR_GET_FLAG(FLAG_WUF) != RESET)

   {

    __HAL_PWR_CLEAR_FLAG(FLAG_WUF);

   }

   /* Blink LED_OK (Green) upon wakeup */

  HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

  HAL_Delay(100);

  HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

   /* System reset comes from a STANDBY wakeup: Conditional Erase*/

   /* Initialize EEPROM emulation driver (mandatory) */

   ee_status = EE_Init(EE_FORCED_ERASE);

    ee_status = EE_Init(EE_CONDITIONAL_ERASE);

   if(ee_status != EE_OK) {Error_Handler();}

  }

  /* Store 10 values of all variables in EEPROM, ascending order */

   for (Index = 1; Index <10/*NB_OF_VARIABLES+1*/; Index++)

   {

    /* Wait any cleanup is completed before accessing flash again */

    while (ErasingOnGoing == 1) { }

    ee_status = EE_WriteVariable32bits(Index, 15);

    //ee_status|= EE_ReadVariable32bits(Index, &a_VarDataTab[Index-1]);

    //if (Index*VarValue != a_VarDataTab[Index-1]) {Error_Handler();}

    /* Start cleanup IT mode, if cleanup is needed */

    if ((ee_status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP) {ErasingOnGoing = 1;ee_status|= EE_CleanUp_IT();}

    if ((ee_status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR) {Error_Handler();}

   }

  /* Read all the variables */

  for (Index = 1; Index < 10; Index++)

  {

   ee_status = EE_ReadVariable32bits(Index, &VarValue);

   store[Index-1]=VarValue;

   //if (VarValue != a_VarDataTab[Index-1]) {Error_Handler();}

   //if (ee_status != EE_OK) {Error_Handler();}

  }

  /* Store 1000 values of Variable1,2,3 in EEPROM */

  /* for (VarValue = 1; VarValue <= 1000; VarValue++)

  {

   while (ErasingOnGoing == 1) { }

   ee_status = EE_WriteVariable32bits(1, VarValue);

   ee_status|= EE_ReadVariable32bits(1, &a_VarDataTab[0]);

   if (VarValue != a_VarDataTab[0]) {Error_Handler();}

   ee_status|= EE_WriteVariable32bits(2, ~VarValue);

   ee_status|= EE_ReadVariable32bits(2, &a_VarDataTab[1]);

   if (~VarValue != a_VarDataTab[1]) {Error_Handler();}

   ee_status|= EE_WriteVariable32bits(3, VarValue << 1);

   ee_status|= EE_ReadVariable32bits(3, &a_VarDataTab[2]);

   if ((VarValue << 1) != a_VarDataTab[2]) {Error_Handler();}*/

   /* Start cleanup polling mode, if cleanup is needed */

  /* if ((ee_status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP) {ErasingOnGoing = 0;ee_status|= EE_CleanUp();}

   if ((ee_status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR) {Error_Handler();}

  }*/

  /* Read all the variables */

  /* for (Index = 1; Index < NB_OF_VARIABLES+1; Index++)

  {

   ee_status = EE_ReadVariable32bits(Index, &VarValue);

   if (VarValue != a_VarDataTab[Index-1]) {Error_Handler();}

   if (ee_status != EE_OK) {Error_Handler();}

  }*/

  /* Test is completed successfully */

  /* Lock the Flash Program Erase controller */

  HAL_FLASH_Lock();

 /* USER CODE END 2 */

0 REPLIES 0