Write/Erase flash results in hard faults in BLE application
Dear ST community
I've been trying to implement the BLE_RfWithFlash example from the STM32WBCube package into my BLE application.
When trying to write/erase flash, the MCU disconnects the BLE client and triggers a hard fault. If I run the application in debug mode, it works sometimes when stepping through the code.
The basic idea is that a BLE characteristic callback triggers the MCU the save configuration data into flash page 85/0x08055000
Information:
MCU: STM32WB55CE (& CG)
STM32WBCube package: ver. 1.12.0
Firmware: BLE full stack
BLE interface: Arduino BLE for stm32wb
OS: Freertos alongside BLE callbacks
Application:
I've used the flash_driver.c/.h from the package example (only added HW semaphore IDs to header since I have no editable hw_conf.h).
I've wrapped the flash driver in a C++ class for readability. The function interacting with the driver:
#define FLASH_PAGE_NUMBER 0x55 // 85
#define FLASH_BASE_ADDRESS 0x08055000
// _eeprom_buffer is an std::array
...
void EEPROM::commit_buffer() {
if (this->_dirtyBuffer) {
// erase flash page 85
FD_EraseSectors(FLASH_PAGE_NUMBER, 1);
// write new data into flash page 85
FD_WriteData(
FLASH_BASE_ADDRESS, (uint64_t *)this->_eeprom_buffer.data(), FLASH_PAGE_SIZE / sizeof(uint64_t));
this->_dirtyBuffer = false;
}
}(inspired by https://github.com/khoih-prog/FlashStorage_STM32)
Things I've tried without luck:
- play around with connection and advertising interval
- Use SHCI_C2_SetFlashActivityControl(FLASH_ACTIVITY_CONTROL_SEM7)
- Add task delays in driver.
- play around with WaitedSemStatus_t FD_WaitForSemAvailable(WaitedSemId_t WaitedSemId); in driver.
Hope someone can point me in the right direction - I've been stuck on application note AN5289 for some time now as well as the related issues on the forum.
