cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Emulated Timing (x-cube-eeprom)

Nikolaj_TL
Associate III

I am running a bluetooth application using freeRTOS on a Nucleo-WB55 (STM32WB55RG). I am in the process of implementing Emulated EEPROM (X-Cube-EEPROM) to store som data. 
After implementing eeprom emulated in a ble_heartrate_freertos example I have had problems understanding the execution of the Emulated EEPROM operation after a pagetransfer + cleanup (obs. for simplicity I use EE_CleanUp here)


Without BLE activated (in SingleCore mode) EEPROM Emulated write and pagetransfer+cleanup looks just fine:

Nikolaj_TL_0-1737036301238.png

Pagetransfer + cleanup takes ~40-50ms
 Nikolaj_TL_1-1737036338860.png

With BLE activated (in DualCore Mode) the following EEPROM operation occupies much more time than expected:
Nikolaj_TL_2-1737036512206.png

Pagetransfer + cleanup still takes ~40-50ms, but a long delay is introduced in the next EEPROM operation:

Nikolaj_TL_0-1737037736034.png

 

 

Here is an example of the additional delay introduced in the following EEPROM (after a pagetransfer + cleanup) operation: 
Nikolaj_TL_3-1737036590271.png


Here is the code:

 

 

int main(void)
{
  ...

  osKernelInitialize();
  defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  APPE_Init();
  
  EEPROM_Emul_Init();  
  EEPROMTimer_Id = osTimerNew(EEPROM_Emul_Simple, osTimerPeriodic, (void *)0, NULL);
  osTimerStart(EEPROMTimer_Id, 50);  
  
  /* Start scheduler */
  osKernelStart();
 
  /* We should never get here as control is now taken by the scheduler */
  while (1) {  }
}

 

 

 

 

 

static void EEPROM_Emul_Simple()
{
  HAL_GPIO_TogglePin(DEBUG1_Gpio_Port, DEBUG1_Pin);
  static uint32_t VarValue = 1;
  static uint32_t Index = 1;
  static EE_Status ee_status = EE_OK;
  
  taskENTER_CRITICAL();   // Exit of critical section in FreeRTOS (disables interrupts)
    
  /*  Wait for the flash semaphore to be free */    
  if (HAL_HSEM_IsSemTaken(CFG_HW_FLASH_SEMID)) {
    taskEXIT_CRITICAL();  // exit of critical section in FreeRTOS
    
    HAL_GPIO_TogglePin(DEBUG3_Gpio_Port, DEBUG3_Pin);
    return;
  }
  if (HAL_HSEM_Take(CFG_HW_FLASH_SEMID, HSEM_PROCESS_1) != HAL_OK) {
    taskEXIT_CRITICAL();  // exit of critical section in FreeRTOS
    
    HAL_GPIO_TogglePin(DEBUG3_Gpio_Port, DEBUG3_Pin);
    return;
  }
  
  HAL_FLASH_Unlock(); /* Unlock the Flash Program Erase controller */
  
  /* ----------- WRITE ----------- */
  /* Toggle LED to show the EEPROM operations are effectively running */
  BSP_LED_Toggle(LED_BLUE);

  ee_status = EE_WriteVariable32bits(Index, Index*VarValue);
  /* If flash is used by CPU2 */
  if (ee_status == EE_FLASH_USED) {
    /* Lock the Flash Program Erase controller and release the semaphore */
    HAL_FLASH_Lock();
    HAL_HSEM_Release(CFG_HW_FLASH_SEMID, HSEM_PROCESS_1);
    taskEXIT_CRITICAL();  // exit of critical section in FreeRTOS
    
    HAL_GPIO_TogglePin(DEBUG3_Gpio_Port, DEBUG3_Pin);
    return;
  }    
    
  /* Start cleanup 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();}
        
  /* Prepare the static parameters for the next time next the function is called by the FreeRTOS */
  Index++;
  if (Index >= (NB_OF_VARIABLES + 1)) {
    VarValue++;
    Index = 1;
  }
  
  /* Lock the Flash Program Erase controller and release flash semaphore if needed */
  HAL_FLASH_Lock();
  HAL_HSEM_Release(CFG_HW_FLASH_SEMID, HSEM_PROCESS_1);
  taskEXIT_CRITICAL();  // exit of critical section in FreeRTOS
  
  HAL_GPIO_TogglePin(DEBUG1_Gpio_Port, DEBUG1_Pin);
  return;
}

 

 

 

 

 

 

 

0 REPLIES 0