Skip to main content
Visitor II
June 21, 2021
Solved

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

  • June 21, 2021
  • 4 replies
  • 1689 views

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 

    This topic has been closed for replies.
    Best answer by Walid ZRELLI

    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

    4 replies

    Technical Moderator
    June 21, 2021

    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

    Robert1Author
    Visitor II
    June 22, 2021

    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

    Technical Moderator
    June 29, 2021

    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

    Visitor II
    June 29, 2021

    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

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

    Great news! Thanks for your contribution.

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