cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get the IP using DHCP

JhonVijay
Associate II

Hello everyone,
   I am trying to get an IP for my controller using the DHCP i can able to detect the Link up and link down but i can't able to get the IP. I had refered the example code for the ethernet(lwip https server netconn rtos) But i can't able to integrate with my main code can someone please help to either identify the issue or help me to integrate the example code with the main file.
                     Thank you.

Output Of my code 

 LWIP Stack Initialized
DHCP Started...
DHCP Task Started
Link Task Started
DHCP State Changed: 255 -> 6
DHCP State: UNKNOWN (6)
Ethernet Cable: CONNECTED DHCP Restarted

3 REPLIES 3
mƎALLEm
ST Employee

Hello,

Start by following this knowledge base article: How to create a project for STM32H7 with Ethernet and LwIP stack working

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I had made the code in which is had done by static IP but i need to implement the Dynamic IP using the DHCP can you guide me to use the DHCP

STackPointer64
ST Employee

Hello @JhonVijay,

After reviewing your project, I noticed several misconfigurations, missing elements, and unnecessary changes that complicate the project.

Here are my observations based on your CubeMX configuration:

  • There is no Memory Protection Unit (MPU) configuration for Ethernet buffers and descriptors, and no cache enabled, which could improve performance.
  • You are using Ethernet with FreeRTOS, but the Ethernet global interrupt is not enabled, which is required.
  • The ETH_TX_EN and ETH_TXD0 pins need to be remapped to PG11 and PG13 respectively for your NUCLEO board.
  • In the LwIP configuration, MEM_SIZE is set to 16,000 bytes, but ETH_RX_BUFFER_CNT is 12. Since 12 RX buffers × 1536 bytes/frame = 18,432 bytes (~18 KB), this exceeds the allocated memory. Adjust ETH_RX_BUFFER_CNT to 10 to fix this.
  • If power consumption is not a concern, I suggest increasing the clock speed to the maximum for better performance with RTOS.

Regarding your project:

  • You have not created dedicated memory sections for descriptors and pool sections in the linker file.
  • You created additional threads for DHCP and link management, but a specific DHCP task is unnecessary. The link thread already exists inside lwip.c in the MX_LWIP_Init() function and is implemented in ethernetif.c. For DHCP debug messages, adjust LwIP’s verbosity level instead.

In summary, I recommend generating a new project following the knowledge base article mentioned by @mƎALLEm, enabling DHCP instead of using a static IP, and adapting the configuration to your NUCLEO board. Then, include the Segger driver as you did in your attached project. This approach will save you hours of debugging.

If you get stuck at any step, please reply to this thread with the issue you encounter, and I’ll be glad to help.

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.