Skip to main content
GPomp.1
Associate III
March 23, 2021
Question

Problem using the internal Flash using P-NUCLEO-WB55

  • March 23, 2021
  • 6 replies
  • 1048 views

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

This topic has been closed for replies.

6 replies

Mike_ST
ST Technical Moderator
March 23, 2021

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 ?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
GPomp.1
GPomp.1Author
Associate III
March 23, 2021

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 Technical Moderator
March 23, 2021

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.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
GPomp.1
GPomp.1Author
Associate III
March 23, 2021

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

Could be the cause the versions?

Mike_ST
ST Technical Moderator
March 24, 2021

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.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
GPomp.1
GPomp.1Author
Associate III
March 24, 2021

Ok, I'll check