freeRTOS LwIP UNALIGNED hardfault access. STM32H7

@RAc
Desktop.zip (504.8 KB)
Here is my .map files with RAM_D1 and RAM_D2. I have tried to search the variable which is causing the damage in the map file and I couldn’t find it.

That does not appear to make sense. From your linker command file:

/* Memories definition */
MEMORY
{
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K

512k is 0x80000, but this is what your map file reads:

Memory Configuration

Name Origin Length Attributes
RAM_D1 0x0000000024000000 0x0000000000100000 xrw

that would be 1M.

We also need to see your interrrupt vector table in the source code, or give us the first 8 bytes at 0x0000000008000000 once your application is loaded.

You need the one which is in the startup file? like this:


g_pfnVectors:
  .word  _estack
  .word  Reset_Handler
  .word  NMI_Handler
  .word  HardFault_Handler
  .word  MemManage_Handler
  .word  BusFault_Handler
  .word  UsageFault_Handler
  .word  0
  .word  0
  .word  0
  .word  0
  .word  SVC_Handler
  .word  DebugMon_Handler
  .word  0
  .word  PendSV_Handler
  .word  SysTick_Handler

  /* External Interrupts */
  .word     WWDG_IRQHandler                   /* Window WatchDog Interrupt ( wwdg1_it, wwdg2_it) */
  .word     PVD_AVD_IRQHandler                /* PVD/AVD through EXTI Line detection */
  .word     TAMP_STAMP_IRQHandler             /* Tamper and TimeStamps through the EXTI line */
  .word     RTC_WKUP_IRQHandler               /* RTC Wakeup through the EXTI line */
  .word     FLASH_IRQHandler                  /* FLASH                        */
  .word     RCC_IRQHandler                    /* RCC                          */
  .word     EXTI0_IRQHandler                  /* EXTI Line0                   */
  .word     EXTI1_IRQHandler                  /* EXTI Line1                   */
  .word     EXTI2_IRQHandler                  /* EXTI Line2                   */
  .word     EXTI3_IRQHandler                  /* EXTI Line3                   */
  .word     EXTI4_IRQHandler                  /* EXTI Line4                   */
  .word     DMA1_Stream0_IRQHandler           /* DMA1 Stream 0                */
  .word     DMA1_Stream1_IRQHandler           /* DMA1 Stream 1                */
  .word     DMA1_Stream2_IRQHandler           /* DMA1 Stream 2                */
  .word     DMA1_Stream3_IRQHandler           /* DMA1 Stream 3                */
  .word     DMA1_Stream4_IRQHandler           /* DMA1 Stream 4                */
  .word     DMA1_Stream5_IRQHandler           /* DMA1 Stream 5                */
  .word     DMA1_Stream6_IRQHandler           /* DMA1 Stream 6                */
  .word     ADC_IRQHandler                    /* ADC1, ADC2 and ADC3s         */
  .word     FDCAN1_IT0_IRQHandler             /* FDCAN1 interrupt line 0      */
  .word     FDCAN2_IT0_IRQHandler             /* FDCAN2 interrupt line 0      */
  .word     FDCAN1_IT1_IRQHandler             /* FDCAN1 interrupt line 1      */
  .word     FDCAN2_IT1_IRQHandler             /* FDCAN2 interrupt line 1      */
  .word     EXTI9_5_IRQHandler                /* External Line[9:5]s          */
  .word     TIM1_BRK_IRQHandler               /* TIM1 Break interrupt         */
  .word     TIM1_UP_IRQHandler                /* TIM1 Update interrupt        */
  .word     TIM1_TRG_COM_IRQHandler           /* TIM1 Trigger and Commutation interrupt */
  .word     TIM1_CC_IRQHandler                /* TIM1 Capture Compare         */
  .word     TIM2_IRQHandler                   /* TIM2                         */
  .word     TIM3_IRQHandler                   /* TIM3                         */
  .word     TIM4_IRQHandler                   /* TIM4                         */
  .word     I2C1_EV_IRQHandler                /* I2C1 Event                   */
  .word     I2C1_ER_IRQHandler                /* I2C1 Error                   */
  .word     I2C2_EV_IRQHandler                /* I2C2 Event                   */
  .word     I2C2_ER_IRQHandler                /* I2C2 Error                   */
  .word     SPI1_IRQHandler                   /* SPI1                         */
  .word     SPI2_IRQHandler                   /* SPI2                         */
  .word     USART1_IRQHandler                 /* USART1                       */
  .word     USART2_IRQHandler                 /* USART2                       */
  .word     USART3_IRQHandler                 /* USART3                       */
  .word     EXTI15_10_IRQHandler              /* External Line[15:10]s        */
  .word     RTC_Alarm_IRQHandler              /* RTC Alarm (A and B) through EXTI Line */
  .word     0                                 /* Reserved                     */
  .word     TIM8_BRK_TIM12_IRQHandler         /* TIM8 Break and TIM12         */
  .word     TIM8_UP_TIM13_IRQHandler          /* TIM8 Update and TIM13        */
  .word     TIM8_TRG_COM_TIM14_IRQHandler     /* TIM8 Trigger and Commutation and TIM14 */
  .word     TIM8_CC_IRQHandler                /* TIM8 Capture Compare         */
  .word     DMA1_Stream7_IRQHandler           /* DMA1 Stream7                 */
  .word     FMC_IRQHandler                    /* FMC                          */
  .word     SDMMC1_IRQHandler                 /* SDMMC1                       */
  .word     TIM5_IRQHandler                   /* TIM5                         */
  .word     SPI3_IRQHandler                   /* SPI3                         */
  .word     UART4_IRQHandler                  /* UART4                        */
  .word     UART5_IRQHandler                  /* UART5                        */
  .word     TIM6_DAC_IRQHandler               /* TIM6 and DAC1&2 underrun errors */
  .word     TIM7_IRQHandler                   /* TIM7                         */
  .word     DMA2_Stream0_IRQHandler           /* DMA2 Stream 0                */
  .word     DMA2_Stream1_IRQHandler           /* DMA2 Stream 1                */
  .word     DMA2_Stream2_IRQHandler           /* DMA2 Stream 2                */
  .word     DMA2_Stream3_IRQHandler           /* DMA2 Stream 3                */
  .word     DMA2_Stream4_IRQHandler           /* DMA2 Stream 4                */
  .word     ETH_IRQHandler                    /* Ethernet                     */
  .word     ETH_WKUP_IRQHandler               /* Ethernet Wakeup through EXTI line */
  .word     FDCAN_CAL_IRQHandler              /* FDCAN calibration unit interrupt  */
  .word     CM7_SEV_IRQHandler                /* CM7 Send event interrupt for CM4  */
  .word     CM4_SEV_IRQHandler                /* CM4 Send event interrupt for CM7  */
  .word     0                                 /* Reserved                     */
  .word     0                                 /* Reserved                     */
  .word     DMA2_Stream5_IRQHandler           /* DMA2 Stream 5                */
  .word     DMA2_Stream6_IRQHandler           /* DMA2 Stream 6                */
  .word     DMA2_Stream7_IRQHandler           /* DMA2 Stream 7                */
  .word     USART6_IRQHandler                 /* USART6                       */
  .word     I2C3_EV_IRQHandler                /* I2C3 event                   */
  .word     I2C3_ER_IRQHandler                /* I2C3 error                   */
  .word     OTG_HS_EP1_OUT_IRQHandler         /* USB OTG HS End Point 1 Out   */
  .word     OTG_HS_EP1_IN_IRQHandler          /* USB OTG HS End Point 1 In    */
  .word     OTG_HS_WKUP_IRQHandler            /* USB OTG HS Wakeup through EXTI */
  .word     OTG_HS_IRQHandler                 /* USB OTG HS                   */
  .word     DCMI_IRQHandler                   /* DCMI                         */
  .word     0                                 /* Reserved                     */
  .word     RNG_IRQHandler                    /* Rng                          */
  .word     FPU_IRQHandler                    /* FPU                          */
  .word     UART7_IRQHandler                  /* UART7                        */
  .word     UART8_IRQHandler                  /* UART8                        */
  .word     SPI4_IRQHandler                   /* SPI4                         */
  .word     SPI5_IRQHandler                   /* SPI5                         */
  .word     SPI6_IRQHandler                   /* SPI6                         */
  .word     SAI1_IRQHandler                   /* SAI1                         */
  .word     LTDC_IRQHandler                   /* LTDC                         */
  .word     LTDC_ER_IRQHandler                /* LTDC error                   */
  .word     DMA2D_IRQHandler                  /* DMA2D                        */
  .word     SAI2_IRQHandler                   /* SAI2                         */
  .word     QUADSPI_IRQHandler                /* QUADSPI                      */
  .word     LPTIM1_IRQHandler                 /* LPTIM1                       */
  .word     CEC_IRQHandler                    /* HDMI_CEC                     */
  .word     I2C4_EV_IRQHandler                /* I2C4 Event                   */
  .word     I2C4_ER_IRQHandler                /* I2C4 Error                   */
  .word     SPDIF_RX_IRQHandler               /* SPDIF_RX                     */
  .word     OTG_FS_EP1_OUT_IRQHandler         /* USB OTG FS End Point 1 Out   */
  .word     OTG_FS_EP1_IN_IRQHandler          /* USB OTG FS End Point 1 In    */
  .word     OTG_FS_WKUP_IRQHandler            /* USB OTG FS Wakeup through EXTI */
  .word     OTG_FS_IRQHandler                 /* USB OTG FS                   */
  .word     DMAMUX1_OVR_IRQHandler            /* DMAMUX1 Overrun interrupt    */
  .word     HRTIM1_Master_IRQHandler          /* HRTIM Master Timer global Interrupt */
  .word     HRTIM1_TIMA_IRQHandler            /* HRTIM Timer A global Interrupt */
  .word     HRTIM1_TIMB_IRQHandler            /* HRTIM Timer B global Interrupt */
  .word     HRTIM1_TIMC_IRQHandler            /* HRTIM Timer C global Interrupt */
  .word     HRTIM1_TIMD_IRQHandler            /* HRTIM Timer D global Interrupt */
  .word     HRTIM1_TIME_IRQHandler            /* HRTIM Timer E global Interrupt */
  .word     HRTIM1_FLT_IRQHandler             /* HRTIM Fault global Interrupt   */
  .word     DFSDM1_FLT0_IRQHandler            /* DFSDM Filter0 Interrupt        */
  .word     DFSDM1_FLT1_IRQHandler            /* DFSDM Filter1 Interrupt        */
  .word     DFSDM1_FLT2_IRQHandler            /* DFSDM Filter2 Interrupt        */
  .word     DFSDM1_FLT3_IRQHandler            /* DFSDM Filter3 Interrupt        */
  .word     SAI3_IRQHandler                   /* SAI3 global Interrupt          */
  .word     SWPMI1_IRQHandler                 /* Serial Wire Interface 1 global interrupt */
  .word     TIM15_IRQHandler                  /* TIM15 global Interrupt      */
  .word     TIM16_IRQHandler                  /* TIM16 global Interrupt      */
  .word     TIM17_IRQHandler                  /* TIM17 global Interrupt      */
  .word     MDIOS_WKUP_IRQHandler             /* MDIOS Wakeup  Interrupt     */
  .word     MDIOS_IRQHandler                  /* MDIOS global Interrupt      */
  .word     JPEG_IRQHandler                   /* JPEG global Interrupt       */
  .word     MDMA_IRQHandler                   /* MDMA global Interrupt       */
  .word     DSI_IRQHandler                    /* DSI global Interrupt        */
  .word     SDMMC2_IRQHandler                 /* SDMMC2 global Interrupt     */
  .word     HSEM1_IRQHandler                  /* HSEM1 global Interrupt      */
  .word     HSEM2_IRQHandler                  /* HSEM1 global Interrupt      */
  .word     ADC3_IRQHandler                   /* ADC3 global Interrupt       */
  .word     DMAMUX2_OVR_IRQHandler            /* DMAMUX Overrun interrupt    */
  .word     BDMA_Channel0_IRQHandler          /* BDMA Channel 0 global Interrupt */
  .word     BDMA_Channel1_IRQHandler          /* BDMA Channel 1 global Interrupt */
  .word     BDMA_Channel2_IRQHandler          /* BDMA Channel 2 global Interrupt */
  .word     BDMA_Channel3_IRQHandler          /* BDMA Channel 3 global Interrupt */
  .word     BDMA_Channel4_IRQHandler          /* BDMA Channel 4 global Interrupt */
  .word     BDMA_Channel5_IRQHandler          /* BDMA Channel 5 global Interrupt */
  .word     BDMA_Channel6_IRQHandler          /* BDMA Channel 6 global Interrupt */
  .word     BDMA_Channel7_IRQHandler          /* BDMA Channel 7 global Interrupt */
  .word     COMP1_IRQHandler                  /* COMP1 global Interrupt     */
  .word     LPTIM2_IRQHandler                 /* LP TIM2 global interrupt   */
  .word     LPTIM3_IRQHandler                 /* LP TIM3 global interrupt   */
  .word     LPTIM4_IRQHandler                 /* LP TIM4 global interrupt   */
  .word     LPTIM5_IRQHandler                 /* LP TIM5 global interrupt   */
  .word     LPUART1_IRQHandler                /* LP UART1 interrupt         */
  .word     WWDG_RST_IRQHandler               /* Window Watchdog reset interrupt (exti_d2_wwdg_it, exti_d1_wwdg_it) */
  .word     CRS_IRQHandler                    /* Clock Recovery Global Interrupt */
  .word     ECC_IRQHandler                    /* ECC diagnostic Global Interrupt */
  .word     SAI4_IRQHandler                   /* SAI4 global interrupt      */
  .word     0                                 /* Reserved                   */
  .word     HOLD_CORE_IRQHandler              /* Hold core interrupt        */
  .word     WAKEUP_PIN_IRQHandler             /* Interrupt for all 6 wake-up pins */

That is definitely wrong, unless _estack is somewhat adjusted in the linker command file. A stack grows to lower addresses, and initializing the startup address to the beginning of a memory section means the stack grows into the previous section.

what are the first 4 bytes at address 0x0000000008000000?

@RAc The _estack is mentioned in linker like this:

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of "RAM_D1" Ram type memory */

This is what I did compared to the stack where I mentioned that I have changed to RAM_D2. I have changes this line of code in linker. Is there any other stack for main? This is my linker script:

/*
******************************************************************************
**
**  File        : LinkerScript.ld
**
**  Author      : STM32CubeIDE
**
**  Abstract    : Linker script for STM32H7 series
**                      1024Kbytes FLASH
**                       800Kbytes RAM
**
**                Set heap size, stack size and stack location according
**                to application requirements.
**
**                Set memory bank area and size if external memory is used.
**
**  Target      : STMicroelectronics STM32
**
**  Distribution: The file is distributed as is without any warranty
**                of any kind.
**
*****************************************************************************
** @attention
**
** Copyright (c) 2023 STMicroelectronics.
** All rights reserved.
**
** This software is licensed under terms that can be found in the LICENSE file
** in the root directory of this software component.
** If no LICENSE file comes with this software, it is provided AS-IS.
**
*****************************************************************************
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of "RAM_D1" Ram type memory */

_Min_Heap_Size = 0xc000 ; /* required amount of heap  */
_Min_Stack_Size = 0x8000; /* required amount of stack */

/* Memories definition */
MEMORY
{
  RAM_D1 (xrw)   : ORIGIN = 0x24000000, LENGTH = 512K
  FLASH   (rx)   : ORIGIN = 0x08000000, LENGTH = 1024K    /* Memory is divided. Actual start is 0x08000000 and actual length is 2048K */
  DTCMRAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 128K
  RAM_D2 (xrw)   : ORIGIN = 0x30000000, LENGTH = 288K
  RAM_D3 (xrw)   : ORIGIN = 0x38000000, LENGTH = 64K
  ITCMRAM (xrw)  : ORIGIN = 0x00000000, LENGTH = 64K
  QUADSPI (r)	 : ORIGIN = 0x90000000,	LENGTH = 64M
  SDRAM   (xrw)  : ORIGIN = 0xD0000000,  LENGTH = 3600K
  SDRAM2  (xrw)  : ORIGIN = 0xD0384000,  LENGTH = 4592K
}

/* Sections */
SECTIONS
{
  /* The startup code into "FLASH" Rom type memory */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

  /* The program code and other data into "FLASH" Rom type memory */
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH

  /* Constant data into "FLASH" Rom type memory */
  .rodata :
  {
    . = ALIGN(4);
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    . = ALIGN(4);
  } >FLASH

  .ARM.extab   : { 
    . = ALIGN(4);
    *(.ARM.extab* .gnu.linkonce.armextab.*)
    . = ALIGN(4);
  } >FLASH
  
  .ARM : {
    . = ALIGN(4);
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
    . = ALIGN(4);
  } >FLASH

  .preinit_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .init_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
    . = ALIGN(4);
  } >FLASH
  
  .fini_array :
  {
    . = ALIGN(4);
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    . = ALIGN(4);
  } >FLASH

  /* Used by the startup to initialize data */
  _sidata = LOADADDR(.data);

  /* Initialized data sections into "RAM" Ram type memory */
  .data : 
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
    *(.RamFunc)        /* .RamFunc sections */
    *(.RamFunc*)       /* .RamFunc* sections */

    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM_D1 AT> FLASH

  /* Uninitialized data section into "RAM" Ram type memory */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM_D1

  /* User_heap_stack section, used to check that there is enough "RAM" Ram  type memory left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM_D1


  
  /* Remove information from the compiler libraries */
  /DISCARD/ : 
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

 

  .ARM.attributes 0 : { *(.ARM.attributes) }
  
TouchGFX_Framebuffer (NOLOAD) :
 	{
		*(TouchGFX_Framebuffer TouchGFX_Framebuffer.*)
		*(.gnu.linkonce.r.*)
        . = ALIGN(0x4);
	} >SDRAM
	
BufferSection (NOLOAD) :
  {
    
    *(Video_RGB_Buffer Video_RGB_Buffer.*)
    *(.gnu.linkonce.r.*)
    . = ALIGN(0x4);
  } >SDRAM2
 


   
ExtFlashSection :
	{
		*(ExtFlashSection ExtFlashSection.*)
		*(.gnu.linkonce.r.*)
        . = ALIGN(0x4);
	} >QUADSPI
	
  .lwip_sec (NOLOAD) :
  {
  	. = ABSOLUTE(0x30000000);
  	*(.RxDecripSection)
  	
  	. = ABSOLUTE(0x30000200);
  	*(.TxDecripSection)
  	
	. = ABSOLUTE(0x30000400);
  	*(.RxPool)
  } >RAM_D2
}

Apologies, you are right. However, your map file locates _estack in the RAM1 case to 0x0000000024100000 which would be fatal if your hardware only has 512k. It surprises me that the 512k length in your linker command file appears to be ignored.

@RAc Hello! I hope you are doing well. I cannot understand what is going wrong but look what I have noticed here. I create the same project with the same steps using freeRTOS v1 and the project worked successfully, no hardfault errors and etc. This project was made with the lvgl and the UI from SquareLine studio. The project that I need to fix is from TouchGFX designer which uses freeRTOS v2. In that case, my I assume that freeRTOS v2 has problems in the code that is being generated automatically?

Hard to say. Are you absolutely sure that both projects use equal compilation (in particular optimization) and linker flags and the same lcf? Have you compared the map files?

This is getting so much into detail that the best recommendation is to contact ST, eg via the ST support forum.

Best of luck!

1 Like

Have you found the solution? If not, can you share your complete code?

@aggarg Hello, unfortunately I didn’t manage to find the solution yet. As I mentioned above I rebuild a simple project just to enable only the LwIP functionality with freeRTOS V2. This project was automatically generated from TouchGFX Designer, and after that I did those steps:

  1. Enable the ETH peripheral with NVIC priority 5.
  2. From middleware, I enabled the LwIP connectivity. Furthermore, I set my own static IP address and also I set MEM_SIZE to 14*1024, while the RAM_HEAP_POINTER to 0x30004000, and finally I increase the MEMP_NUM_SYS_TIMEOUT by one to enable the MQTT functionality.
  3. After that I set the MPU configuration as the picture illustrates above and
  4. At the ethernetif.c file I declared the RxPool section with memo_memory_RX_POOL_base.
    5)Moreover I create a section to linker script, which is being illustrate above.
    Those steps I make just to pink my screen, which is done successfully although after some time approximately 20 to 40 minutes it generates a hard fault exception.

Since I am not experienced in embedded, I have tried everything I could and didn’t manage to figured it out. So I am trying to do my best until now. The thing that I have noticed, is that if I play with the TOTAL_HEAP_SIZE and the minimum stack_size in freeRTOSConfig.h I succeed to run it for an hour although it corrupts again. I have set the stack size of the task also like 20000*4 that was a desperate approach but nothing again.

Sorry for analysing so much above, I am not able to post my hole code today, although I will do it tomorrow. Thanks a lot for your willingness!

The thing is that I made the same steps with Lvgl and the problem was not appears. It was running successfully for 12 hours. It uses though the freeRTOS v1 and not touchgfx tasks. I don’t know, I am getting tired with that.

Have you double checked to test the return value of every single of your FreeRTOS API calls? If one fails undetectedly, you may encounter every problem you can think of. And more! :wink:

1 Like

@RAc I don’t think that is possible that during normal operation there are being called a lot of functions which if I enter inside every function I will probably stop it’s normal operation.

So you are basically saying that the generated code which is a combination from Touchgfx and cubemx(lwip) is full of failures? I didn’t write a single line of code!

In all honesty, Nikos: ST does NOT write good software. They are a hardware company, and the libs they provide are made to sell their hardware, nothing more. Everybody knows that. if you rely on their software to run stably and reliably in the field out of the box, you’re in for a number of surprises.

And that is not only ST, most hardware manufacturers work like that, and you can not blame them for it.

Lets go systematically and try to find out the root cause of the hard fault. The following 2 are good resources:

Please try to find the faulting instruction and let us know what you find.

1 Like

@RAc @aggarg Hello folks. I have been trying for a week now but unfortunately can’t find the reason why I am getting those hardfault errors at random time. I saw your posts @aggarg and I think that they were useful to understand what is going on with the hardfaults, although they weren’t enough for solving my problem despite that they indeed gave me a good feedback about that. I will close this post, because I don’t want to bore you more. At least I tried it as much as I could. I also include a function in the hardfault_handler in order to extract the values from the register and it seems like there aren’t address but some strange large values. Anyway I would like to thank you both for your willingness. :v: :v:

Are you using one of the STM32H7 dev kits? I have NUCLEO-STM32H743ZI and NUCLEO-STM32H723ZG. If you are using one of these and are willing to share your code, I can give it a try and see if I can find the issue.

@aggarg I am using the RIVERDI display with the STM32H7 microcontroller. If that works for you, yes I can share my code to you!

Unfortunately I do not have that setup. Drop me a DM with your email and preferred times if you’d like to setup a debug session to debug it together.

Hello again folks! I hope that you are well. I tried to check in the memory map as it has been already suggested above. Unfortunately, I didn’t understand from the begging where to find it and I was looking into the debug folder of STM32CubeIDE. Moreover, I tried successfully to investigate the error further as the @aggarg mentioned, with the helpful links that posted above and I noticed that.

  1. The hardfault is a preciserr error, with the forced bit set and
    1.1) the BFAR register is pointing to the address 0x2b006d43.
    I have checked the memory map of the microcontroller and I noticed that this address is in ram and also is reserved!! So thats why I think I am having this error.
    The thing is that it happens at random times. For instance, it corrupted at 5 minutes and after that I have changed some parameters like the TCPIP_THREAD_STACKSIZE to 4096, the SLIPIF_THREAD_STACKSIZE and the DEFAULT_THREAD_STACKSIZE to 2048 and it runs for 45 minutes.
    My microcontroller reference manual is https://www.st.com/resource/en/reference_manual/rm0399-stm32h745755-and-stm32h747757-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

So I would like to ask. Since I have inserted a new section in linker script, should I have resize the sizes or the lengths of Flash or RAM? I ask this questions because I have read that in this article https://www.beningo.com/how-to-debug-a-hard-fault-on-an-arm-cortex-m/which is trying to explain how to debug such errors and it mentioning that it had been assigned a new section in linker without resize of flash. I have done the some think in mine project so I was wondering if this could be a similar case.

Hello again,

I am fairly certain that the root cause of your fault is a bug in the ST display driver library. Again, try to contact ST. If that does not help, use the usual techniques to isolate the problem, eg remove or disable components one by one until you know the minimal setup required to reproduce the problem. Your overall architecture seems to be fairly complex as is, so you must make your haystack as small as possible to have a chance of locating the needle.

Your other choice is to narrow down the isse by setting DWT data break points if you can locate some write operation (address and/or data) that exposes the symptomatic cause.

1 Like