STM32 LwIP Ethernet Only Works in Debug Mode

192 views Asked by At

Okay so basically I noticed that whenever I flased my MCU it would stop running after 1-2 seconds but whenever I debugged it then it would work.

Context: Using NUCLEO-F746ZG Board Running LwIP using Ethernet ( Polling Mode, No RTOS ) Using WAY less storage/Ram/Flash Memory then the capacity

I noticed that when examining the board after it had stopped using STM32CubeProgrammer Bug analysis that I kept getting a Hard Fault, something to do with alignment issues.

Tried to manually set MPU configurations and etc using HAL API but I still kept gettting issues. Tried to play around with Buffer sizes and Buffer Pool sizes in the opt.h for LwIP but still no luck.

Solution: in LwIP/src/include/lwip/opt.h theres a macro called MEM_ALIGNMENT, it was defined as 1. The Doxygen comment was: /**

  • MEM_ALIGNMENT: should be set to the alignment of the CPU
  • 4 byte alignment -> #define MEM_ALIGNMENT 4
  • 2 byte alignment -> #define MEM_ALIGNMENT 2 */

After changing it to 4, it worked.

No idea why on earth it was defined as 1 but this stuff had me frustrated for days. If anyone finds this helpful then honestly just share your solutions online to pay it forward cuz I had absolutely no luck finding this online.

I noticed that when examining the board after it had stopped using STM32CubeProgrammer Bug analysis that I kept getting a Hard Fault, something to do with alignment issues.

1

There are 1 answers

0
HunKonrad On

I used the STM32CubeIDE "Device Configuration Tool Code Generation" for setting the Ethernet and LwIP layers. This has changed the MEM_ALIGNMENT to 4 automatically (NUCLEO-F746ZG). I highly recommend to use STM32CubeIDE instead of STM32CubeProgrammer for more complex tasks like Ethernet communication.