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 II

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 */

 

 

 

 

 

 

 

3 REPLIES 3
CalebJ
Associate II

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" ?

CalebJ
Associate II

I don't have a geniune ST-Link sorry.


Yup, here are my steps:

  1. Erase entire flash using the "Full chip erase" button in the STM32CubeProgrammer.
  2. Click the "Disconnect" button in STM32CubeProgrammer.
  3. Open the STM32CubeIDE and build the project.
  4. Click the "Run" button
  5. *Code runs and the led blinks on the board.*
  6. Click the "Run" button again 
  7. *Error* below is the output.

 

STMicroelectronics ST-LINK GDB server. Version 7.8.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled
        InitWhile                  : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.17.0                  
      -------------------------------------------------------------------



Log output file:   C:\Users\caleb\AppData\Local\Temp\STM32CubeProgrammer_a09940.log
ST-LINK SN  : B55B5A1A000000001E23E701
ST-LINK FW  : V2J45S7
Board       : --
Voltage     : 3.28V
Error: No STM32 target found! If your product embeds Debug Authentication, please perform a discovery using Debug Authentication
Encountered Error when opening C:\ST\STM32CubeIDE_1.15.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.1.400.202404281720\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Shutting down...
Exit.

 

 

 

I have also done it this way, here are the steps:

  1. Erase entire flash using the "Full chip erase" button in the STM32CubeProgrammer.
  2. Click the "Disconnect" button in STM32CubeProgrammer.
  3. Open the STM32CubeIDE and build the project.
  4. Click the "Run" button, below is the output.
STMicroelectronics ST-LINK GDB server. Version 7.8.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled
        InitWhile                  : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.17.0                  
      -------------------------------------------------------------------



Log output file:   C:\Users\caleb\AppData\Local\Temp\STM32CubeProgrammer_a01032.log
ST-LINK SN  : B55B5A1A000000001E23E701
ST-LINK FW  : V2J45S7
Board       : --
Voltage     : 3.27V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x494
Revision ID : Rev Z
Device name : STM32WB1xxx
Flash size  : 320 KBytes
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : 0xB1



Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_a01032.srec
  File          : ST-LINK_GDB_server_a01032.srec
  Size          : 17.26 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 8]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:01.325



Verifying ...




Download verified successfully 


Shutting down...
Exit.

5. *Code runs and the LED blinks*
6. I unplug the ST_Link V2 and plug it back in again.
7. I change the HAL_Delay for the LED blinking to be 800 instead of 1000 and I build the project.
8. I click the "Run" button.
9. *Error* I have attached the output below.

STMicroelectronics ST-LINK GDB server. Version 7.8.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled
        InitWhile                  : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.17.0                  
      -------------------------------------------------------------------



Log output file:   C:\Users\caleb\AppData\Local\Temp\STM32CubeProgrammer_a14020.log
ST-LINK SN  : B55B5A1A000000001E23E701
ST-LINK FW  : V2J45S7
Board       : --
Voltage     : 3.27V
Error: No STM32 target found! If your product embeds Debug Authentication, please perform a discovery using Debug Authentication
Encountered Error when opening C:\ST\STM32CubeIDE_1.15.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.1.400.202404281720\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Shutting down...
Exit.