2024-08-05 04:53 AM
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!
Solved! Go to Solution.
2024-08-05 07:45 AM
The STM32G0B1CBT6 chip has 128 kB of flash. Address 0x803F800 is past the end of the flash which is at 0x08020000.
2024-08-05 05:51 AM - edited 2024-08-05 05:51 AM
Ensure that the address at _addr is valid and lies within a readable memory somewhere.
2024-08-05 06:19 AM - edited 2024-08-05 06:19 AM
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.
2024-08-05 06:28 AM
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.
2024-08-05 06:46 AM - edited 2024-08-05 06:52 AM
Well, _addr reports to 0x803F800 which is is the same value as the GUI_FLASH_MAGIC_NUMBER define.
HOWEVER, the line operates on MagicNumber (note case sensitivity) which is defined in the code as
static const uint64_t MagicNumber = 0xDEADBABEDEADF00DU;
Funny is, that I cannot view the MagicNumber variable in the variable watch which gives me
Multiple errors reported.
1) Failed to execute MI command:
-var-create - * MagicNumber
Error message from debugger back end:
-var-create: unable to create variable object
2) Unable to create variable object
3) Failed to execute MI command:
-data-evaluate-expression MagicNumber
Error message from debugger back end:
No symbol "MagicNumber" in current context.
4) Failed to execute MI command:
-var-create - * MagicNumber
Error message from debugger back end:
-var-create: unable to create variable object
//EDIT: Is seems indeed that i cannot read from the _addr since the expression watch does not show a number when the value is defererenced (see screenshot)
Per reference manual, the upper boundary of main flash (STM32G0B1xx) is 0x0807 FFFF, so the region 0x803F800 should be readable?
2024-08-05 07:45 AM
The STM32G0B1CBT6 chip has 128 kB of flash. Address 0x803F800 is past the end of the flash which is at 0x08020000.
2024-08-05 08:07 AM
Ooooh, I had a look in the dataheet, but I had interchanged the Letters in CBT6, it is the 'B" in CBT6 that tells the 128kByte. not the 'C' which is the pincount here. Wrong order
I changed the following define to the start of the last page (i.e. the last 2k of Flash)
#define ADDR_FLASH_LAST_PAGE 0x1F800
At least the hardfault is gone. I would say this is a bug of the code generator. Anyway: Thanks a lot @TDK !