STM32L4R5 || read/erase/write internal Flash
Hello everyone,
Dev Board based on STM32L4R5
I am just trying to erase and then write something on the internal FLASH.
I am trying to follow the example:
I have created a small test function to just erase the bank 2
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_256 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_511 + FLASH_PAGE_SIZE - 1 /* End @ of user Flash area */
void testFlash( void )
{
/* 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);
/* Get the bank */
BankNumber = GetBank(FLASH_USER_START_ADDR);
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_MASSERASE;
EraseInitStruct.Banks = BankNumber;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
{
// Error occurred while mass erase.
// To know the code error, user can call function 'HAL_FLASH_GetError()'
//Infinite loop
while (1)
{
//BSP_LED_On(LED3);
}
}
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
}
Issue:
Having testFlash() function in main(), cases the HAL_Init() not return at all.
If I remove the testFlash() the application runs as expected.
Hope someone can direct me to some debug information.
Thank you.
Posted Jun 21, 2021, 8:18 PM UTC
11