cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G491CC (not defined FLASH_OPTR_DBANK) -> Problem cube firmware (stm32g4xx_hal_flash.h) , FLASH_PAGE_NB is wrong

Robert1
Associate II

FLASH_PAGE_NB is wrong == 64 page, must be 128 pages  

#define FLASH_PAGE_NB   ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

Work for STM32G491CE == 256 Pages 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Robert​ ,

We have tried to fix your reported issue but we don't have a STM32G491CC sample with 256k flash available on my side.

So, could you please check the following fix from your side :

Update in stm32g4xx_hal_flash.h file line 883 :

#define FLASH_PAGE_NB ((FLASH_SIZE == 0x00080000U) ? 256U : \

((FLASH_SIZE == 0x00040000U) ? 128U : 64U))

instead of

#define FLASH_PAGE_NB          ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

BeST Regards,

Walid

View solution in original post

6 REPLIES 6
Imen.D
ST Employee

Hello @Robert​ ,

Please make sure to use the latest release of STM32CubeG4 MCU package (v1.4.0) with FLASH_PAGE_NB = 128U

#define FLASH_PAGE_NB                   128U
#define FLASH_PAGE_SIZE_128_BITS        0x1000U /* 4 KB */
#else
#define FLASH_SIZE                      ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x80UL << 10U) : \
                                        (((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))
#define FLASH_BANK_SIZE                 (FLASH_SIZE)
#define FLASH_PAGE_NB                   ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Robert1
Associate II

FLASH_OPTR_DBANK not defined for STM32G491, therefore you get for

the type STM32G491CC (256 Kbyte Flash 128 pages) -> FLASH_PAGE_NB = 64 and not 128

...

#else

#define FLASH_PAGE_NB          ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

#if defined (FLASH_OPTR_DBANK)

#define FLASH_SIZE           ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x200UL << 10U) : \

                    (((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))

#define FLASH_BANK_SIZE         (FLASH_SIZE >> 1)

#define FLASH_PAGE_NB          128U

#define FLASH_PAGE_SIZE_128_BITS    0x1000U /* 4 KB */

#else

#define FLASH_SIZE           ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x80UL << 10U) : \

                    (((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))

#define FLASH_BANK_SIZE         (FLASH_SIZE)

#define FLASH_PAGE_NB          ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

#endif

Imen.D
ST Employee

Hi @Robert​ and thanks for pointing out this issue.

I agree with you and I raised this issue internally to our development teams for fix.

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello @Robert​ ,

We have tried to fix your reported issue but we don't have a STM32G491CC sample with 256k flash available on my side.

So, could you please check the following fix from your side :

Update in stm32g4xx_hal_flash.h file line 883 :

#define FLASH_PAGE_NB ((FLASH_SIZE == 0x00080000U) ? 256U : \

((FLASH_SIZE == 0x00040000U) ? 128U : 64U))

instead of

#define FLASH_PAGE_NB          ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)

BeST Regards,

Walid

Hello Walid,
I checked your macro bugfix.
STM32G491CC (get 128 pages)
and
STM32G491CE (get 256 pages).
It works.
With best regards
Robert Chudalla

Great news! Thanks for your contribution.

Please close this topic by choosing Select as Best. This will help other users find that answer faster.