Skip to main content
Explorer II
August 5, 2024
Solved

USBCPD CubeIDE code results in HardFault when GUI_INTERFACE is enabled

  • August 5, 2024
  • 2 replies
  • 1600 views

So, I followed the following video step by step for a "project with a custom board" (video minute 13:04)

https://www.youtube.com/watch?v=cbdFHmMOMwk

I am working on an STM32G0B1CBT6

The code is generated and can be built, but as soon as I enable the Utilities->GUI_INTERFACE in CubeMX, the generated code results in a Hardfault during initialisation ( to be specific in the in the file Utilities-> GUI_INTERFACE->bsp_gui.c) during execution of the line number 80, that is

 

 

 

 if ((0xFFFFFFFFu != *((uint32_t *)_addr)) && (MagicNumber != *((uint64_t *)_addr)))

 

 

 

Any hints on how to proceed debugging?

Thanks!

    This topic has been closed for replies.
    Best answer by TDK

    The STM32G0B1CBT6 chip has 128 kB of flash. Address 0x803F800 is past the end of the flash which is at 0x08020000.

    TDK_0-1722869055634.png

    2 replies

    Super User
    August 5, 2024

    Ensure that the address at _addr is valid and lies within a readable memory somewhere.

    Franz.1Author
    Explorer II
    August 5, 2024

    Well, _addr is defined as

     

    uint32_t _addr = GUI_FLASH_MAGIC_NUMBER;

     

     

    The GUI_FLASH_MAGIC_NUMBER itself comes from 

     

    #define GUI_FLASH_MAGIC_NUMBER ADDR_FLASH_LAST_PAGE

     

     

    ADDR_FLASH_LAST_PAGE comes from

     

    #if defined (FLASH_OPTR_DBANK) || defined(FLASH_DBANK_SUPPORT)
    #define INDEX_PAGE ((FLASH_PAGE_NB * 2u) - 1u) /* Index of latest page */
    #else
    #define INDEX_PAGE (FLASH_PAGE_NB - 1u) /* Index of latest page */
    #endif /* FLASH_OPTR_DBANK || FLASH_DBANK_SUPPORT */
    #define ADDR_FLASH_LAST_PAGE (FLASH_BASE + (INDEX_PAGE * FLASH_PAGE_SIZE)) /* Base @ of latest page */
    #define ADDR_FLASH_PAGE_END (ADDR_FLASH_LAST_PAGE + FLASH_PAGE_SIZE - 1u)

     

     

    This comes all from the pregenerated code. The defines in the section above all refer to the respective stm32g0xx_hal_flash.h.  I did not change any of that and it seems correct.

    Super User
    August 5, 2024

    I agree with your assessment.

    When you debug the code, use the fault analyzer to see what it says is wrong.

    Look at "_addr" in the expressions or variables window to find out where it points and ensure it's valid.

    Visitor II
    August 6, 2025

    Just wanted to surface this thread to ST; this bug still exists. @FBL