cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Emulation for STM32WB55 Example missing

TGUCL.1
Associate III

Hi

I`m working on a customised STM32WB55 board and trying to implement eeprom emulation.

According to AN4894

there should be a BLE_HeartRate_EEPROM_Emul example somewhere but looking at STM32Cube_FW_WB_V1.12.0 package I can`t find it. I have also checked the STM32 github page but still no chance . Has anyone have access to this example ?

TGUCL1_0-1703057260726.png

 

I have this piece of code which is called after HAL_Init and returns EE_ERASE_ERROR after calling EE_Init(EE_FORCED_ERASE); 

 

void ReadMode() {

	uint8_t configMode[4] = { 0 };
	Flash_ReadNBytes(EEPROM_WRITE_MODE_ADDR, &configMode[0], 4);
	if (configMode[0] == 0xAA && configMode[1] == 0xBB && configMode[2] == 0xCC
			&& configMode[3] == 0xDD) {
		moduleInfo.configMode = 1;

		return 1;
	}
	moduleInfo.configMode = 0;
	return 0;
}
void Flash_ReadNBytes(uint16_t addr, uint8_t *data, uint32_t n) {

	EE_Status ee_status = EE_OK;

	HAL_FLASH_Unlock();

	if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) {

		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(PWR_FLAG_WUF) != RESET) {
			__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
		}

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

	for (int i = 0; i < n; i++) {
		ee_status = EE_ReadVariable8bits(addr + i, &data[i]);

		if (ee_status != EE_OK) {
			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();
	}

	HAL_FLASH_Lock();
}

 

 

However , there is also this code called later which works fine

void TestFlashRead(void) {
	EE_Status ee_status = EE_OK;

	HAL_FLASH_Unlock();

	if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) {

		ee_status = EE_Init(EE_FORCED_ERASE); //this works fine
		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(PWR_FLAG_WUF) != RESET) {
			__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF);
		}

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

	if ((EE_ReadVariable32bits(EEPROM_BAUDRATE_ADDR, &config.baud)
			& EE_STATUSMASK_ERROR ) == EE_STATUSMASK_ERROR) {
		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();
	}

	HAL_FLASH_Lock();
}

 

 

I would appreciate any support.

Thanks

4 REPLIES 4
STTwo-32
ST Employee

Hello @TGUCL.1 

The example exist in the X-CUBE-EEPROM Expansion Package. You can find it under: projects/STM32WB/BLE_HeartRate_EEPROM_Emul. 

PS: don't forget to read the readme file of the project before using it.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

As this is a new design perhaps consider changing the paradigm to fit how the device natively functions.

Ask yourself how much data you are writing, and how often.

If you can put your configuration data in a structure, along with integrity checking, you can journal writes across multiple flash sectors in a more robust and efficient manner.

If you program with dozens of distinct global variables, consider using structures there too.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nimaltd
Senior

install my library and enjoy

https://github.com/nimaltd/ee