cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault in etharp_raw with LwIP and NUCLEO-H723ZG

marcociprianiaa
Associate II

I'm quite new to STM32, and I'm trying to get LwIP up and running on my NUCLEO-H723ZG. No matter what I've tried so far, my board has always goes into HardFault, specifically during MX_LWIP_Init(), when the HAL calls etharp_raw(). Here is the full call stack for reference:

298392412-b6d91517-dd38-4c2b-97ee-75f23f506cc3.png

Here are the lines of code in etharp.c in which the HardFault occurs:

etharp_request_dst():

marcociprianiaa_2-1706114558348.png

etharp_raw():

marcociprianiaa_3-1706114579763.png

These are the steps I followed so far:

  • Set up a new CubeIDE project for the NUCLEO-H723ZG board, and enabled:
    • Speculation, ICache, DCache, MPU
    • Debug with Trace Async Sw
    • USB Device, CDC class (I need it)
    • FreeRTOS with CMSIS_V2, USE_NEWLIB_REENTRANT
    • ETH, Rx descriptor to 0x30000000, Tx descriptor to 0x30000100
    • LwIP, LAN8742 interface, heap pointer to 0x30000200
  • Set my clock configuration to use the High Speed Internal RC (this NUCLEO board doesn't have a HSE crystal), 550MHz clock 
  • Set the SYS timebase to TIM6
  • Followed the detailed guide by @Adam BERLINGER in this forum post
    • Set up the MPU with all the correct addresses for the STM32H723
    • Set every ETH pin with Very High speed
    • Set all the stack sizes following the guide
    • Configured LwIP, again following the guide
    • Modified the code as described in the post and in the GitHub repo (including the _FLASH.ld linker script), except for adding lwiperf, since I'm not even able to reach the main loop of the code.

 

I've also tried:

  • Doing everything as above, but without FreeRTOS:
    • In this case, I didn't follow the last step of modifying the code, since any of that resulted in compilation errors. I also tried with and without modifying the linker script.
    • I added MX_LWIP_Process() in the while(1) loop.
    •  
  • Not enabling the MPU and cache (resulted in memory faults when run)
  • With DHCP or static IP, same results
  • Increase stack and heap size to 0x1000 (didn't help)
  • Straight up using the default CubeMX configuration and LwIP settings without enabling RTOS (obviously didn't work)
  • Commenting LWIP_RAM_HEAP_POINTER in lwipopts.h to force LwIP to use the heap instead of a pre-defined memory address.
    • With a static IP address set in CubeMX, I don't get a HardFault and the while loop is entered, but I can't ping the board
    • If, instead, I enable DHCP, I never get an IP address. Doing printf on gnetif.ip_addr.addr always returns 0.0.0.0

 

I'm quite lost on what could be the cause. Any help would be highly appreciated,

Marco

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

how to get more details in case of HardFaults?

This one is easy. The CubeIDE debugger has a Fault Analyzer tool (look for the bomb icon). When you get a hard fault, open it and it will expose useful details. For more info please look in CubeIDE used guide. Generally there's a lot of info about the HardFaults and how to analyze them. 

http://efton.sk/STM32/Cortex_M4_faults.pdf  from @Jan Waclawek 

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c from @Tesla DeLorean 

 

View solution in original post

5 REPLIES 5

Dump out the register set from the fault, and the instructions there.

My guess would be that ipsrc_addr is an accessible memory address, at all, or misaligned.

Start by looking at what it is the processor doesn't like, not shot-gunning a whole bunch of code, heap or stack changes.

Once you know specifically what the processor is objecting too, work backward from there, perhaps adding telemetry output or sanity checks.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III
marcociprianiaa
Associate II

@Tesla DeLorean I will try tomorrow to get a register and instruction dump, I'll post it here since I don't have the knowledge to understand it completely.

@Pavel A. Yes, that is in fact the example I'm following made by @Adam BERLINGER and that I'm struggling to reproduce following his instructions, both in his post and in the README.

Can you point me to some guide or application note that describes how to get more details in case of HardFaults? Not knowing what's going on is becoming quite frustrating

Pavel A.
Evangelist III

how to get more details in case of HardFaults?

This one is easy. The CubeIDE debugger has a Fault Analyzer tool (look for the bomb icon). When you get a hard fault, open it and it will expose useful details. For more info please look in CubeIDE used guide. Generally there's a lot of info about the HardFaults and how to analyze them. 

http://efton.sk/STM32/Cortex_M4_faults.pdf  from @Jan Waclawek 

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c from @Tesla DeLorean 

 

marcociprianiaa
Associate II

I was finally able to find the dumb error that caused the fault, I didn't set one of the MPU regions's "TEX field level" to "level 1". Now the STM32 connects to ethernet and I can ping the board when using a static IP address or DHCP.

Thanks for the help.