2024-09-04 02:56 AM - last edited on 2024-09-04 04:09 AM by SofLit
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).
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.
The tab with the message that pops-up(appears), see picture below:
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.
A picture of referance manual below:
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.
Solved! Go to Solution.
2024-09-04 08:19 AM
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.
Picture(below) containing the solution(correction):
Thanks SMarie .Thanks guys. Problem solved.
2024-09-04 04:08 AM
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.
2024-09-04 05:28 AM
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?
2024-09-04 05:40 AM - edited 2024-09-04 05:43 AM
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.
2024-09-04 05:56 AM
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
2024-09-04 07:40 AM
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)..
"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.
2024-09-04 07:59 AM
"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?
I have changed my internal flash memory in the linker.
PageError value before the crash(see picture below)
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.
2024-09-04 08:19 AM
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.
Picture(below) containing the solution(correction):
Thanks SMarie .Thanks guys. Problem solved.