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
Piranha
Chief II

If the code is flawed, it's flawed. It cannot be "set up" with some CubeMX clicking!

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

RKara.2
Associate II

I have the same problem - today I wanted to play with my board, but it isn't working at all. I used my old code prepared in Keil and I was able to ping board, so PCB is working fine. I did the same steps in Stm32CubeIde - I added only LWIP and disabled DHCP to obtain static IP - code compile like a charm, but it is not working. Can other people check it? I was using also NUCLEO-F767ZI

Hi,

First of all, thank you for your answer.

You obviously made networking work. As far as I understand by rebuilding the whole thing using codes from the

original sources and totaly outside of the STM IDE. Well... I guess this represents a lot of work and requires a very

good understanding of the libraries internals themselves.

I apreciate and respect this approach, but I presume most people who are thinking about using the STM32 chips

are probably not doing this and go to an easier path.

I totaly agree: I'm lazy and I just want to use a TCP stack... not to rebuild it from scrap :-))

Mbed do provide one which is working (and I made it work without problem), but I cannot use mbed for this

project (mostly because mbed works very well on evaluation boards but there is no documentation to

move it to custom hardware, and also because of other considerations such as memory being tight).

So what other option do I have which are "practical" ?

Keil ? Is it worth going there ?

Some fix for the STM IDE ? I plan to use only LwIP, not rtos, which should make the solution simpler, I presume,

but I have no clue where to start.

Another option ?

Or maybe somebody can be hired to fix this issue ?

I am really looking for a solution since it is quite a blocking issue in my project.

Hi,

thank you for replying.

We apparently are numerous having the same problem. There are a few post of people who claim

to have it working (so it gives some hope about feasability), some even posted sources... on a share

with limited time, so which are not available anymore. Sad.

If you get it to work, please tell me (I will do the same on my side) and if possible let's try to post

a solution wich can be used by others.

It's a bit of a shame that such a functionality isn't working (or isn't properly documented) and that

we're apparently left alone. There is a need for a solution.

I found a workaround - if you add a FreeRTOS in Cube, somehow it start to work. Unfortunally I cannot use FreeRTOS, so I still struggle to make it work.

Frederic Cloth
Associate III

OK,

I finaly found the problem, I suppose.

At least it now reply to pings, which is a tremendous progress :)

It seems that when you give a static address to the CubeMX configurator

it just does NOTHING with it :(

[dear ST staff... shouldn't it be fixed ?]

So the code believe its address is 0.0.0.0 (since it never is initialised

with the value you entered) and therefore... it doesn't work.

So, all you have to do is:

edit the file LWIP/App/lwip.c

you will find

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4];

uint8_t NETMASK_ADDRESS[4];

uint8_t GATEWAY_ADDRESS[4];

change it for something like this:

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4]={192,168,1,200};

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

uint8_t GATEWAY_ADDRESS[4]={192,168,1,1};

compile and run.

So for people out there who like me are looking for help

here is the complete operations to get an empty project with a

functional (let's hope it is) native LwIP network stack:

--------------------------------------------------------------

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

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 */

 }

4) Enter the correct IP address

- I open the file LWIP/App/lwip.c

you will find

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4];

uint8_t NETMASK_ADDRESS[4];

uint8_t GATEWAY_ADDRESS[4];

change it for your static network config

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4]={192,168,1,200};

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

uint8_t GATEWAY_ADDRESS[4]={192,168,1,1};

and now if you execute the code, it will reply to pings.

I don't know yet how it will behave with a real server code,

but I will try it soon.

I think I found the answer: CubeMX ignores the static configuration you give !

edit the file LWIP/App/lwip.c

you will find

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4];

uint8_t NETMASK_ADDRESS[4];

uint8_t GATEWAY_ADDRESS[4];

change it for something like this:

/* Variables Initialization */

struct netif gnetif;

ip4_addr_t ipaddr;

ip4_addr_t netmask;

ip4_addr_t gw;

uint8_t IP_ADDRESS[4]={192,168,1,200};

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

uint8_t GATEWAY_ADDRESS[4]={192,168,1,1};

done !

Thank you very much. My board reply to ping and I'm able to send UDP packet. With optimalization flate Ofast, I'm able to send payloads with 12.5 MB/s (yes, mega bytes, at least this is what Wireshark computes).

Geraldo Pereira
Associate II

Hi Cloth,

I´ve just bought two STM32F767ZI kit, but I could not run the LwIP examples. I tried run diferent kinds of examples of the file STM32Cube_FW_F7_V1.16.0, with MDK-ARM and Cube IDE, but nothing run.

For example, bellow are a fragment of the main.h file to configure a static IP adress:

/* Exported constants --------------------------------------------------------*/ 

//#define USE_DHCP    /* enable DHCP, if disabled static address is used*/

/*Static IP ADDRESS*/

#define IP_ADDR0  192

#define IP_ADDR1  168

#define IP_ADDR2  0

#define IP_ADDR3  130

  

/*NETMASK*/

#define NETMASK_ADDR0  255

#define NETMASK_ADDR1  255

#define NETMASK_ADDR2  255

#define NETMASK_ADDR3  0

I compile and load the code, but nothing happens. I can´t ping the board. I thinks it´s the same problem that yout have. So I´d like:

1) Did you get sucess in a socket or TCP example?

2) Did you run the LwIP examples from Repository?

What other board don´t have bugs with network? Do you suggest other boart that I can try to run a simple socket example?

Thanks,

Geraldo.