cancel
Showing results for 
Search instead for 
Did you mean: 

Optimizing TCP server [LWIP]

bosquet2
Associate
Posted on June 25, 2015 at 10:48

In my project I use a STM32F4 Discovery with a phy adapter DP83848 to create an ethernet connection between my board and my laptop. I use it to acquire measure.

I use F4Cube as library with the stack LWIP and I don't use RTOS. I create a TCP server on my board and use a TCP  terminal as a client on my laptop. My connection works well and is stable with no paquet lost at 10Mbits.

Here is my main problem, I would like to send each measure that I acquire through one USART as soon as I get one (my STM32F4 send a command each time to get one). These measures are small (30 octets). The problem is, between two measure I get a 10ms delay due (I think) to the TCP/IP stack and I don't know where looking to reduce this one.

During this 10ms delay I can't send anoter command to acquire a new measure so my maximum acquisition frequency is stuck at 100Hz.

Any idea to reduce this delay? 

#discovery #stm32f4 #lwip
5 REPLIES 5
qwer.asdf
Senior
Posted on June 25, 2015 at 12:40

You can try to optimize your protocol. For example get 10 measures every time instead of 1 then you will have 1000Hz.

bosquet2
Associate
Posted on June 26, 2015 at 08:16

I can't, I need a continous acquisition. I can't take only 10 measures and after, wait 10ms where I can't continue to measure to be able to send last 10 one.

I saw many option (memory size, buffer size, paquet size, paquet fragment...) on the LWIP stack (opt.h and lwipopts.h) but I don't know which one is critical in my case.

I also try to desactivate nagle algorithme but I got no effect on this delay.
Michael Steinecke
Associate II
Posted on June 29, 2015 at 15:46

Hello McCliff

probably TCP/IP is not the correct protocol for your usecase. TCP/IP has no deterministic in the delivery. Chose something like EtherCAT (Real Time).

However if you stay with TCP, you should start by disabling Nagle algorithm. also you may get better results by using UDP.

Also the LWIP poll interval (default 250ms) can have an influence on you.

leonardo2
Associate II
Posted on November 04, 2016 at 12:07

Hi McCliff,

I work on a configuration that is like yours:

A board with STM32F1 that samples data and act as a server, in order to send a stream of data to the connected client Computer.

I already took a look at the examples of the LwIP from F1CubeMX, but at the end I couldn't get so much help from them.

Could you please give me some clues on where to start? 

thank you very much

slimen
Senior
Posted on November 07, 2016 at 10:36

Hello,

I'd recommend you to have a look to the

http://www.st.com/content/ccc/resource/technical/document/user_manual/10/c5/1a/43/3a/70/43/7d/DM00104712.pdf/files/DM00104712.pdf/jcr:content/translations/en.DM00104712.pdf

User manual, in the paragraph ''B.3.6 LwIP'' for the STM32CubeMX LwIP side.

For more details about LwIP, I suggest that you take a look to the following resources which can help you to go further in your application:

-

http://www.st.com/content/ccc/resource/technical/document/user_manual/65/e8/20/db/16/36/45/f7/DM00103685.pdf/files/DM00103685.pdf/jcr:content/translations/en.DM00103685.pdf

“Developing applications on STM32Cube with LwIP TCP/IP stack“.-

http://www.st.com/content/ccc/resource/technical/document/application_note/66/dd/f9/3f/5f/75/49/c8/CD00255062.pdf/files/CD00255062.pdf/jcr:content/translations/en.CD00255062.pdf

 â€œlwIP TCP/IP stack demonstration for STM32F107xx connectivity line microcontrollersâ€� .

Regards