cancel
Showing results for 
Search instead for 
Did you mean: 

Can not erase flash memory page - a tab pops up when debugging

FLuba.1
Associate III

Hi, i have write a code to erase data of internal flash memory of the MCU. But when i  debug it,a page(tab) pops up with the following message: No source available for "<signal handler called>() at 0xfffffffe" . And i can't any longer debug.

I use the MCU: STM32L4P5ZGTXP_FLASH
IDE: STM32CubeIDE STM32CubeIDE ,Version: 1.16.0

My code comes from an example code of STM32.

--------------AN EXTRACT OF THE CODE-------------

main.c

// if( __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() != HAL_OK)//added

// {

// BSP_Error_Handler(genFuncLTDC_TRANSFER_ERROR); //////////////////////////////////////////

// }



/* Unlock the Flash to enable the flash control register access *************/

HAL_FLASH_Unlock();



/* Erase the user Flash area

(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/



/* Get the 1st page to erase */

FirstPage = GetPage(FLASH_USER_START_ADDR);



/* Get the number of pages to erase from 1st page */

NbOfPages = GetPage(FLASH_USER_END_ADDR) - FirstPage + 1;



/* Get the bank */

BankNumber = GetBank(FLASH_USER_START_ADDR);



/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;

EraseInitStruct.Banks = BankNumber;

EraseInitStruct.Page = FirstPage;

EraseInitStruct.NbPages = NbOfPages;



if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)

{

/*

Error occurred while page erase.

User can add here some code to deal with this error.

PageError will contain the faulty page and then to know the code error on this page,

user can call function 'HAL_FLASH_GetError()'

*/



/* Infinite loop */

while (1)

{

/* Turn on LED3 */

BSP_LED_On(LED3);

}

}

main.h

/*Defines for internal memory */

/*Table 8 Reference manual: Flash module - 1 Mbyte dual-bank organization, DB1M = 1

* (64 bits read width)

* Bank 1 is used

* */

#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_0 /* Start @ of user Flash area */

#define FLASH_USER_END_ADDR (ADDR_FLASH_PAGE_1 + FLASH_PAGE_SIZE - 1) /* End @ of user Flash area */



#define DATA_32 ((uint32_t)0x12345678) //enkel 2x 32 bit data schrijven is toegestaan

#define DATA_64 ((uint64_t)0x1234567812345678) //The Flash memory is programmed 72 bits at a time (64 bits + 8 bits ECC).

#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08080000) /* Base @ of Page 0, bank 2 4 Kbytes */

#define ADDR_FLASH_PAGE_1 ((uint32_t)0x08081000) /* Base @ of Page 1, bank 2, 4 Kbytes */

#define ADDR_FLASH_PAGE_2 ((uint32_t)0x08082000) /* Base @ of Page 2, bank 2, 4 Kbytes */



----------------------END CODE-------------------------

 The following code is put on comment since it isn't applicable for my MCU i think.:

// if( __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() != HAL_OK)//added

// {

// BSP_Error_Handler(genFuncLTDC_TRANSFER_ERROR); //////////////////////////////////////////

// }

When debugging, the code hangs during execution of the following function:" if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)", on line 377(see picture below).

FLuba1_0-1725442302804.png

 In function "HAL_StatusTypeDef HAL_FLASHEx_Erase()", the debugging stops(hangs) when trying to execute the code on line 125(see picture below) and the tab mentioned above appears. It even can't enter the function on line 125(function "FLASH_WaitForLastOperation()"). When we are on this function, then press "step into", the tab with the message appears.

FLuba1_1-1725442423970.png

The tab with the message that pops-up(appears), see picture below:

FLuba1_4-1725443623001.png

I have chosen pages(adresses) different than the MCU uses. Here below you can see(trough a Build Analyzer picture), wich adresses the MCU uses.

 

FLuba1_2-1725442766972.png

A picture of referance manual below:

FLuba1_3-1725442806076.png

Can someone help me? I need to use the internal flash memory to store data that isn't lost after the device is switched off.

 

1 ACCEPTED SOLUTION

Accepted Solutions
FLuba.1
Associate III

I've found my error. I must correct the return value to FLASH_BANK_2(that's why banks has value 1, since return value is FLASH_BANK_1). Picture below is how it was.

FLuba1_4-1725463005707.png

 

FLuba1_3-1725462744413.png

 

 

Picture(below) containing the solution(correction):

FLuba1_5-1725463094117.png

Thanks SMarie .Thanks guys. Problem solved. 

View solution in original post

7 REPLIES 7
SofLit
ST Employee

Hello,

In next time please use </> button to paste your code. Not easy to read it in text format.

Thank you for your understanding.

Refer to the tips on posting.

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.
SMarie
Senior

Hi,

Could you show us the values of EraseInitStruct before you enter HAL_FLASHEx_Erase?
Could you also give us the value of PageError once the function crash?

TDK
Guru

After the issue happens, connect with STM32CubeProgrammer and verify the correct page was erased.

The symptom presents itself as if you have erased code the STM32 was using. Can't see your GetPage or GetBank functions.

You should also change linker so that memory at 0x08080000 is not visible to it--change the flash size to 512K.

 

Edit: Also, is the DB1M option byte set? Check with STM32CubeProgrammer. If not, that could be the issue.

If you feel a post has answered your question, please click "Accept as Solution".

Erase blocks at the end of memory, not the front / vector table. Basically you're causing an active interrupt to go to 0xFFFFFFFF

Use pages beyond your active firmware image

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

 

Firstly, thank you for all your hints, it only makes me better at programming.

 

DB1M(dualbank) option byte is set, see picture below. I've checked it with "STM32CubeIDE debugger -->SFRs".

All the addresses have the value 0xFFFFFFFF, so it's difficult to check wich page has been erased(see in picture below in memory tab, the value in addresses of the internal flash memory).. 

FLuba1_6-1725460224901.png

 

 

FLuba1_2-1725459528945.png

FLuba1_3-1725459555156.png

"Can't see your GetPage or GetBank functions."

In the code i've posted above it's mentionned. You should click "view more" to see the complete code. It's mentionned on the following lines: 21, 31, 37. 

 

"You should also change linker so that memory at 0x08080000 is not visible to it--change the flash size to 512K"
I've changed it, but still have the same problem. See picture below, for a picture of my linker file. 

FLuba1_7-1725460773625.png

 

 

"Could you show us the values of EraseInitStruct before you enter HAL_FLASHEx_Erase?" 

Is it normal that i receive for "Banks" the value 1? Since i use bank2. Or does it refer to number of bank that i use?

FLuba1_0-1725461392398.png

I have changed my internal flash memory in the linker.

FLuba1_1-1725461600187.png

 

PageError value before the crash(see picture below)

FLuba1_2-1725461780692.png

 

PageError value after the crash(see picture below).  I think that it doesn't enter the function  "FLASH_WaitForLastOperation(). PageError has the same value as before the crash.

FLuba1_3-1725461828746.png

 

 

FLuba.1
Associate III

I've found my error. I must correct the return value to FLASH_BANK_2(that's why banks has value 1, since return value is FLASH_BANK_1). Picture below is how it was.

FLuba1_4-1725463005707.png

 

FLuba1_3-1725462744413.png

 

 

Picture(below) containing the solution(correction):

FLuba1_5-1725463094117.png

Thanks SMarie .Thanks guys. Problem solved.