‎2020-02-13 08:42 AM
I am using a P-NUCLEO-WB55 board and trying to delete flash from within a BLE app. I have used the p2p_server project as the basis for my project.(github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_p2pServer)
When a certain BLE command is called within the P2P_Server.c file, the function below is called to delete a certain area of flash. The erase operation works but the BLE connection is broken. The connection can be reestablished but ideally I do not want the BLE connection to be broken. Is this possible? What is causing the connection to break?
Thanks for any help,
FInlay
oid Flash_Wipe(uint32_t Data_Start_Point, uint32_t Timestamp_Start_Point)
{
uint32_t DataFirstPage = 0, DataNbOfPages = 0, TimestampFirstPage = 0, TimestampNbOfPages = 0;
uint32_t PageError = 0;
/*Variable used for Erase procedure*/
static FLASH_EraseInitTypeDef DataEraseInitStruct;
static FLASH_EraseInitTypeDef TimestampEraseInitStruct;
// Unlock the Flash to enable the flash control register access
HAL_FLASH_Unlock();
// Clear OPTVERR bit set on virgin samples
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
//if non-zero input then perform the data flash area erase
if(Data_Start_Point != 0U)
{
// Get the 1st page to erase
DataFirstPage = (Data_Start_Point - FLASH_BASE) / FLASH_PAGE_SIZE;
// Get the number of pages to erase from 1st page
DataNbOfPages = ((SPEECH_DATA_END_ADDRESS - FLASH_BASE) / FLASH_PAGE_SIZE) - DataFirstPage + 1;
// Fill EraseInit structure
DataEraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
DataEraseInitStruct.Page = DataFirstPage;
DataEraseInitStruct.NbPages = DataNbOfPages;
if (HAL_FLASHEx_Erase(&DataEraseInitStruct, &PageError) != HAL_OK)
{
while (1)
{
// Turn on Red LED
HAL_GPIO_WritePin(LEDG_GPIO_Port, LEDG_Pin, SET);
}
}
}
//if non-zero input then perform the timestamp flash area erase
if(Timestamp_Start_Point != 0U)
{
//Get the 1st page to erase
TimestampFirstPage = (Timestamp_Start_Point - FLASH_BASE) / FLASH_PAGE_SIZE;
// Get the number of pages to erase from 1st page
TimestampNbOfPages = ((SPEECH_TIMESTAMP_END_ADDRESS - FLASH_BASE) / FLASH_PAGE_SIZE) - TimestampFirstPage + 1;
// Fill EraseInit structure
TimestampEraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
TimestampEraseInitStruct.Page = TimestampFirstPage;
TimestampEraseInitStruct.NbPages = TimestampNbOfPages;
if (HAL_FLASHEx_Erase(&TimestampEraseInitStruct, &PageError) != HAL_OK)
{
while (1)
{
// Turn on Red LED
HAL_GPIO_WritePin(LEDG_GPIO_Port, LEDG_Pin, SET);
}
}
}
// Lock the Flash to disable the flash control register access (recommended to protect the FLASH memory against possible unwanted operation)
HAL_FLASH_Lock(); //we can eventually lock and unlock before and after operations
}
‎2020-02-13 09:00 AM
Hi,
"STM32 MPUs" topic is dedicated to microprocessor family STM32MP1x
Reassigned ticket to "STM32 MCUs", "STM32WB" to reach pertinent community ;)
BR,
Olivier
‎2020-02-14 01:11 AM
Erasing a flash block takes a lot of time (the datasheet should tell you exactly how much). During this time, any attempt to access flash from either core blocks that core until the erase is finished. If the BLE peripheral needs constant attention from the software, it won't work.
Moving all code essential to the communication to RAM should help, but I don't know if it's possible to do with the radio coprocessor firmware.