cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup a native LwIP TCP stack for STM32F7 board ?

Frederic Cloth
Associate III

Hi,

I'm desperate !

Can somebody help me setup a working TCP / UDP stack on an STM32F767ZI

evaluation board using LwIP native (ie not rtos/netconn) ?

This should be easy, I obviously am missing something but what ???

I Have read all available documentation on ST (about 3 or 4 pdf): they

were of no help.

I looked over the internet: I see I am not alone to suffer on this

but found no usable answer. If a good answer is made it will clearly

not only good for me, but for many other people as well: so please help !

Here are the details of what I do:

1) Selection of the board

- I use STM32CubeIDE (Version: 1.2.1 Build: 5190_20200115_1224 (UTC))

- I go to "File->New->STM32 Project

- Within MCU/MPU Selector, I search for "STM32F767ZI"

- Within the search result screen on the right side, I select "NUCLEO-F767ZI"

 that appears as a link in the "Board" collumn.

- I click on "Next>" at the bottom of the screen.

2) Enabling LwIP in CubeMX

- I enter a project name (say "tcptest52")

- I hit "Finish" (not modifying anything from the proposed defaults)

- I answer yes to "Initialize all peripherals with their default Mode ?"

- I answer yes to "This kind of project is associated with the STM32CubeMx

 perspective. Do you want to open this perspective now ?"

- I click on "Middleware->LWIP"

- I click on "Enabled"

- I click on "IPv4 - DHCP Options / LWIP_DHCP : Disabled"

- I enter a fixed IP: 192.168.001.200

- I enter a net mask: 255.255.255.000

- I enter a gateway : 192.168.001.001

- I go to "File->Save" which generates the code

note:

- LWIP_ICMP is enabled (I don't change this, I expect it to reply to pings)

- LWIP_UDP is enabled (I don't change this, obviously: this is what I want)

- MEMP_NUM_UDP_PCB=4 proposed by default

- LWIP_TCP is enabled (I don't change this)

- MEMP_NUM_TCP_PCB=5 proposed by default

in general I kept all the defaults proposed besides the fixed IP.

3) Adding LWIP process function

- I open the Core/Src/main.c file

- within the int main(void) function, I edit the while(1) loop

 to add the LWIP event processing function:

 /* USER CODE BEGIN WHILE */

 while (1)

 {

    MX_LWIP_Process();

   /* USER CODE END WHILE */

   /* USER CODE BEGIN 3 */

 }

- I execute the project "Run->Debug"

- I select "STM32 Cortex-M C/C++ Application"

- I builds the project (no error/no warnings)

- In "Edit launch configuration properties" I keep the defaults

 and i just click "OK"

- It proposes me to switch to the debugger view, I do agree

 by clicking on "Switch"

- I click on the "Resume/F8" button (something that looks like

 a yellow and green recorder "play/pause" button)

4) Test

- from the computer I try

C:\Users\frcl>ping 192.168.1.200

Pinging 192.168.1.200 with 32 bytes of data:

Reply from 192.168.1.199: Destination host unreachable.

Reply from 192.168.1.4: Destination host unreachable.

Reply from 192.168.1.4: Destination host unreachable.

Reply from 192.168.1.4: Destination host unreachable.

Ping statistics for 192.168.1.200:

   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

C:\Users\frcl>

It just simply doesn't work.

Note 1:

I compiled an http TCP server I wrote for the same board using mbed,

and it does work perfectly in the exact same configuration:

answers to ping (and answers to the web browser as well):

C:\Users\frcl>ping 192.168.1.200

Pinging 192.168.1.200 with 32 bytes of data:

Reply from 192.168.1.200: bytes=32 time<1ms TTL=255

Reply from 192.168.1.200: bytes=32 time<1ms TTL=255

Reply from 192.168.1.200: bytes=32 time<1ms TTL=255

Reply from 192.168.1.200: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.1.200:

   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

   Minimum = 0ms, Maximum = 0ms, Average = 0ms

So the hardware is working fine and the network is also working fine.

Note 2:

As I explained, I tried (with no luck) to find answers in the

ST documentation:

- UM1709 User manual STM32Cube Ethernet IAP example

- AN3966 Application note

 LwIP TCP/IP stack demonstration for STM32F4x7 microcontrollers

- UM1713 User manual

 Developing applications on STM32Cube with LwIP TCP/IP stack

19 REPLIES 19

Hi Geraldo,

This is not board depended, this is error with LWIP code generator - check Frederic response, it contain all needed informations. You need to put values into i..e IP_ADDRESS array, defines are not enough. Can you please share your code?

Piranha
Chief II

> What other board don´t have bugs with network?

Nothing is wrong with the board. It's the HAL/Cube broken bloatware...

You can check the board and it's performance with my demo firmware:

https://community.st.com/s/question/0D50X0000AhNBoWSQW/actually-working-stm32-ethernet-and-lwip-demonstration-firmware

Hi RKara,

Thanks by your answer. I did´t generate any code. I tried first test my board with LwIP_HTTP_Server_Netconn_RTOS example that cames with STM32Cube_FW_F7_V1.16.0 of the Repository (STM32 Cube). I tested the examples of MDK-ARM (uVison), SW4STM32 and with STM32 Cube IDE, but nothing run. I´ve read about IP_ADDRESS array but in theses versions I could not find LwIP.c file.

After your and Piranha´s post I´ll test everything again.

Thanks,

Geraldo.

Hi Piranha,

Good news. I´ll test everything again. By the way, in the LwIP_HTTP_Server_Netconn_RTOS examples that cames with STM32Cube_FW_F7_V1.16.0 of the Repository (STM32 Cube), where can I edit IP_ADDRESS? I could not find the LwIP.c file in theses projects.

And what code and where, must I put to see the IP adress of the board?

I´ll read and test everything again. I´ll report my results soon.

Thanks,,

Geraldo.

Hi Piranha,

I´ve just download the NUCLEO-144.hex file. I´m looking how load this file in my board, but What is the easy way to do that? What tool do you suggest to load the code to the board?

Thanks,

Geraldo.

I´ve just downloaded the ST-Link utility and load and tested the firmware and the board is good. I´ll check and try develop my program.

Thanks,

Geraldo.

I have the same issue and I don't know how I will fixe it

i change the LWIP/App/lwip.c file but the ping not working

can someone help me

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4]={10,0,0,10} ;

uint8_t NETMASK_ADDRESS[4]={255,255,255,0};

uint8_t GATEWAY_ADDRESS[4]={10,0,0,254} ;

Try other IP and Gateway addresses.

If IP address = x.y.1.z, then try

Gateway = x.y.1.1

And don't forget to assign the addresses in MX_LWIP_Init():

  /* IP addresses initialization with OR without DHCP (IPv4), see init values above (all "0" for DHCP) */
  IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
  IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
  IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);

I changed the address but nothing change

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4]={10,0,1,123} ;

uint8_t NETMASK_ADDRESS[4]={255,255,0,0} ;

uint8_t GATEWAY_ADDRESS[4]={10,0,1,1} ;

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/**

 * LwIP initialization function

 */

void MX_LWIP_Init(void)

{

 /* IP addresses initialization */

 IP_ADDRESS[0] = 10;

 IP_ADDRESS[1] = 0;

 IP_ADDRESS[2] = 1;

 IP_ADDRESS[3] = 123;

 NETMASK_ADDRESS[0] = 255;

 NETMASK_ADDRESS[1] = 255;

 NETMASK_ADDRESS[2] = 0;

 NETMASK_ADDRESS[3] = 0;

 GATEWAY_ADDRESS[0] = 10;

 GATEWAY_ADDRESS[1] = 0;

 GATEWAY_ADDRESS[2] = 1;

 GATEWAY_ADDRESS[3] = 1;

/* USER CODE BEGIN IP_ADDRESSES */

/* USER CODE END IP_ADDRESSES */

 /* Initilialize the LwIP stack without RTOS */

 lwip_init();

 /* IP addresses initialization without DHCP (IPv4) */

 IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);

 IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);

 IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);

 /* add the network interface (IPv4/IPv6) without RTOS */

 netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

I have a question but I think its a bit stupid

the address must be in the same domaine of my wifi network or can i choose any address i wanted

Carte réseau sans fil Wi-Fi :

  Suffixe DNS propre à la connexion. . . : home

  Adresse IPv6. . . . . . . . . . . . . .: fd14:a51a:fb5a:f500:da8:496a:f224:387b

  Adresse IPv6 temporaire . . . . . . . .: fd14:a51a:fb5a:f500:c018:88af:7c30:9221

  Adresse IPv6 de liaison locale. . . . .: fe80::da8:496a:f224:387b%15

  Adresse IPv4. . . . . . . . . . . . . .: 10.0.0.2

  Masque de sous-réseau. . . . . . . . . : 255.255.255.0

  Passerelle par défaut. . . . . . . . . : 10.0.0.254

I see this link posted many times, but I don't have access to it. Any alternate link?