cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Emulation works, but to program again I have to erase the entire flash.

CalebJ
Associate

Hi,

I am using the STM32WB15CC chip in a stm32WB1mmc module on a custom pcb. I need to write to a non volatile uint8_t variable 70,000 times over the lifetime of the device. 

I have been using following guide (  https://community.st.com/t5/stm32-mcus/porting-and-using-x-cube-eeprom-with-any-stm32/ta-p/570539 )to implement emulated eeprom. When debugging, my code steps through fine and works great. When I try to restart the debugging session or program a different basic sketch I get an error. To fix this I use the STM32CubeProgrammer to erase the entire flash and then the board can program again. 

I have attached a screenshot of the error message.

Here is my eeprom_emul_conf.h variables

 

 

 

 

/* Configuration of eeprom emulation in flash, can be custom */
#define START_PAGE_ADDRESS      0x08017800U/*!< Start address of the 1st page in flash, for EEPROM emulation */
#define CYCLES_NUMBER           7U   /*!< Number of 10Kcycles requested, minimum 1 for 10Kcycles (default),
                                        for instance 10 to reach 100Kcycles. This factor will increase
                                        pages number */
#define GUARD_PAGES_NUMBER      0U   /*!< Number of guard pages avoiding frequent transfers (must be multiple of 2): 0,2,4.. */

/* Configuration of crc calculation for eeprom emulation in flash */
#define CRC_POLYNOMIAL_LENGTH   LL_CRC_POLYLENGTH_16B /* CRC polynomial lenght 16 bits */
#define CRC_POLYNOMIAL_VALUE    0x8005U /* Polynomial to use for CRC calculation */

 

 

 

 

 

 

 

2 REPLIES 2
CalebJ
Associate

I have added functionality to toggle an led in the main while loop after all the eeprom code has executed successfully. This was to check if the eeprom code still worked after a reset. It turns out it does.

I am using the 1.16.1 version of the STM32CubeIDE, and a knock off ST-Link V2 .

To get the tutorial code to work I had to add in the additional "stm32wbxx_II_crc.h" library into my STM32WBxx_HAL_Driver folder, which I found in the x-cube-eeprom zip. I also had to remove the #include to the stm32wb nucleo board library within the "flash.h" library.

 

I can work around this problem by erasing the flash everytime before programming, but I don't like the feeling of something being broken without knowing why.

Here is a section of my main.c file

/* USER CODE BEGIN PV */
#include "flash_interface.h"
#include "eeprom_emul_conf.h"
#include "eeprom_emul.h"
#include "eeprom_emul_types.h"
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* 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();

  /* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

	HAL_FLASH_Unlock();
	EE_Status status = EE_Init(EE_FORCED_ERASE);
	if (status != EE_OK) {
		Error_Handler();
	}

	uint16_t address = 0x0001;	// 16-bit virtual address between 0x0001 - 0xFFFE inclusive
	uint32_t data = 0x12345678; // Dummy Data
	status = EE_WriteVariable32bits(address, data);
	if (status != EE_OK) {
		if (status == EE_CLEANUP_REQUIRED) {
			if (EE_CleanUp() != EE_OK) {
				Error_Handler();
			}
		} else {
			Error_Handler();
		}
	}

	uint32_t read_EE_variable;
	status = EE_ReadVariable32bits(0x1, &read_EE_variable);
	if (status != EE_OK) {
		Error_Handler();
	}
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
  	HAL_GPIO_TogglePin(STATUS_LED_GPIO_Port, STATUS_LED_Pin);
  	HAL_Delay(500);
  }
  /* USER CODE END 3 */
}

 


@CalebJ wrote:

I am using the 1.16.1 version of the STM32CubeIDE, and a knock off ST-Link V2 .


Do you get the same issue when using a genuine ST-Link?

 


@CalebJ wrote:

When I try to restart the debugging session or program a different basic sketch I get an error.


Can you give some more detail on exactly what steps you take here?

Does power-cycling the board make a difference?

Physically disconnecting the knock-off "ST-Link" ?