cancel
Showing results for 
Search instead for 
Did you mean: 

How to Erase STM32H7B3 internal Flash with HAL_Flash_Erase function

DJean.3
Associate

i see somewere that the way to erase the flash is to do this instructions.

FLASH_EraseInitTypeDef EraseInitStruct;

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Banks = FLASH_BANK_1;

EraseInitStruct.Sector = FirstSector;

EraseInitStruct.NbSectors = NbOfSectors;

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);

the matter is that i have STM32H7B3I-DK board with code that i genérate form STM32CubeMx. But when a write these instructions; the word "FLASH_VOLTAGE_RANGE_3" is unkown by the IDE (KEIL).

1 ACCEPTED SOLUTION

Accepted Solutions
Mike_ST
ST Employee

Hello,

If I'm correct,

In STM32H7 HAL, the FLASH_VOLTAGE_RANGE_X are conditionnal to the existence of the FLASH_CR_PSIZE bits in FLASH_CR1 register, which do not exist on the STM32H7B3, but does on H743/H753.

#if defined (FLASH_CR_PSIZE)

/** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range

 * @{

 */

#define FLASH_VOLTAGE_RANGE_1       0x00000000U      /*!< Flash program/erase by 8 bits */

#define FLASH_VOLTAGE_RANGE_2       FLASH_CR_PSIZE_0 /*!< Flash program/erase by 16 bits */

#define FLASH_VOLTAGE_RANGE_3       FLASH_CR_PSIZE_1 /*!< Flash program/erase by 32 bits */

#define FLASH_VOLTAGE_RANGE_4       FLASH_CR_PSIZE   /*!< Flash program/erase by 64 bits */

/**

 * @}

 */

#endif /* FLASH_CR_PSIZE */

So I guess the VoltageRange field does not need to be filled on STM32H7B3.

Please have a look at the exemples available here:

https://www.st.com/en/embedded-software/stm32cubeh7.html

And check the project:

STM32Cube_FW_H7_V1.10.0\Projects\STM32H7B3I-DK\Examples\FLASH\FLASH_EraseProgram

View solution in original post

4 REPLIES 4
RomainR.
ST Employee

Hello DJean.3 (Community Member),

FLASH_VOLTAGE_RANGE_3 which is defined in STM32Cube_FW_H7_V1.11.0\Drivers\STM32H7xx_HAL_Driver\Inc\stm32h7xx_hal_flash_ex.h

Can you check if you include this file by uncomment:

#define HAL_FLASH_MODULE_ENABLED in stm32h7xx_hal_conf.h at line #49 ?

Can you try the following example project ?

\STM32Cube_FW_H7_V1.11.0\Projects\STM32H7B3I-DK\Examples\FLASH\FLASH_EraseProgram

Best regards,

Romain,

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

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.

Check the HAL conf file

Check the build target MCU, and defines passed to the compiler

Try find-in-files some of the constants / defines that do work

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mike_ST
ST Employee

Hello,

If I'm correct,

In STM32H7 HAL, the FLASH_VOLTAGE_RANGE_X are conditionnal to the existence of the FLASH_CR_PSIZE bits in FLASH_CR1 register, which do not exist on the STM32H7B3, but does on H743/H753.

#if defined (FLASH_CR_PSIZE)

/** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range

 * @{

 */

#define FLASH_VOLTAGE_RANGE_1       0x00000000U      /*!< Flash program/erase by 8 bits */

#define FLASH_VOLTAGE_RANGE_2       FLASH_CR_PSIZE_0 /*!< Flash program/erase by 16 bits */

#define FLASH_VOLTAGE_RANGE_3       FLASH_CR_PSIZE_1 /*!< Flash program/erase by 32 bits */

#define FLASH_VOLTAGE_RANGE_4       FLASH_CR_PSIZE   /*!< Flash program/erase by 64 bits */

/**

 * @}

 */

#endif /* FLASH_CR_PSIZE */

So I guess the VoltageRange field does not need to be filled on STM32H7B3.

Please have a look at the exemples available here:

https://www.st.com/en/embedded-software/stm32cubeh7.html

And check the project:

STM32Cube_FW_H7_V1.10.0\Projects\STM32H7B3I-DK\Examples\FLASH\FLASH_EraseProgram

Thanks Dear Mike

sorry for the late. it is correct that STM32H7B3 doesn't have the FLASH_CR_PSIZE bits in FLASH_CR1 register. and then FLASH_VOLTAGE_RANGE_X  are not defined.

i checked the project STM32Cube_FW_H7_V1.10.0\Projects\STM32H7B3I-DK\Examples\FLASH\FLASH_EraseProgram.

and the way to errase the STM32H7B3 flash is:

/*Variable used for Erase procedure*/

static FLASH_EraseInitTypeDef EraseInitStruct;

 /* Fill EraseInit structure*/

 EraseInitStruct.TypeErase   = FLASH_TYPEERASE_SECTORS;

 EraseInitStruct.Banks     = FLASH_BANK_1;

 EraseInitStruct.Sector    = FirstSector;

 EraseInitStruct.NbSectors   = NbOfSectors;

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);

Hope it will help someone who will face to same issue has me.