2021-03-23 08:26 AM
Hi,
I'm using the example FLASH_WriteProtection with P-NUCLEO-WB55 with success but if I change the define FLASH_USER_START_ADDR in order to write only two (so I change the define FLASH_USER_END_ADDR in 'ADDR_FLASH_PAGE_250 + FLASH_PAGE_SIZE - 1') page from the PAGE_230 (adddress: 0x080E6000) I've a hard fault after I call HAL_FLASHEx_Erase.
I want to delete and after write on this location because in my application I need to store at the end of flash some application data. What's the problem?
regards,
Giampietro
2021-03-23 08:59 AM
Hello,
Maybe if you attach the modified main.c, people would be able to see the diff from the original example and spot the problem.
Have you tried debugging, and see when the hardfault happens ?
2021-03-23 09:14 AM
I use the original example 'FLASH_WriteProtection' for the MCU STM32WB with only the following change:
#if 0
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_16 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_126 + FLASH_PAGE_SIZE - 1 /* End @ of user Flash area */
#else
#define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_254 /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_255 + FLASH_PAGE_SIZE - 1 /* End @ of user Flash area */
#endif
Debugging I've seen that the hardfault happens when call the function 'FLASH_PageErase'. This function is called by HAL_FLASHEx_Erase (row 415).
I report you the code of the function FLASH_PageErase:
void FLASH_PageErase(uint32_t Page)
{
/* Check the parameters */
assert_param(IS_FLASH_PAGE(Page));
/* Proceed to erase the page */
MODIFY_REG(FLASH->CR, FLASH_CR_PNB, ((Page << FLASH_CR_PNB_Pos) | FLASH_CR_PER | FLASH_CR_STRT));
}
The hardfault occurs calling MODIFY_REG when Page values 254.
regards,
Giampietro
2021-03-23 09:38 AM
Maybe that won't help,
bu I compiled and ran the FLASH_WriteProtection with your modifications from STM32Cube_FW_WB_V1.10.1/Projects/P-NUCLEO-WB55.Nucleo/Examples/FLASH/FLASH_WriteProtection.
I don't meet any hardfaults.
2021-03-23 09:45 AM
I'm using STM32Cube_FW_WB_V1.11.0 and STM32CubeIDE Version: 1.6.0.
Could be the cause the versions?
2021-03-24 02:35 AM
I don't think so, I have tried with STM32Cube_FW_WB_V1.11.0 as well.
Maybe check the option bytes to see whether there is some flash protection in place.
2021-03-24 04:16 AM
Ok, I'll check