cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using the internal Flash using P-NUCLEO-WB55

GPomp.1
Associate III

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

6 REPLIES 6
Mike_ST
ST Employee

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 ?

GPomp.1
Associate III

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

Mike_ST
ST Employee

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.

I'm using STM32Cube_FW_WB_V1.11.0 and STM32CubeIDE Version: 1.6.0.

Could be the cause the versions?

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.

GPomp.1
Associate III

Ok, I'll check