cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Lwip, freertos and 3 tcp socekts. The website problem

pferd
Associate III

 Hello,

I have problem with my project on STM32F4. I use Lwip, Freertos, and 3 TCP sockets in separate threads. The first and the second is for the modbus. The third is for the website. When the first and the second socket’s threads are in the waiting state for connection, the website gets only a part of the scripts. I have connection errors and reset errors in the web console. If I disable the first or the second socket, it works fine. The socket configuration is below. Could you tell me where is the problem? Thank you for your help.

///////////////////// FIRST, SECOND ///////////////////////

setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes))

setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes))

setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes))

listen(sock, 1)

///////////////////// WEBSITE ///////////////////////

setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));

setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(opt));

setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &opt, sizeof(opt));

listen(sock, 1)

///////////////////// LWIP OPTIONS ///////////////////////

/*----- WITH_RTOS enabled (Since FREERTOS is set) -----*/

#define WITH_RTOS 1

/*----- CHECKSUM_BY_HARDWARE disabled -----*/

#define CHECKSUM_BY_HARDWARE 0

/*-----------------------------------------------------------------------------*/

/* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/

/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/

/*----- Default Value for LWIP_UDP: 1 ---*/

#define LWIP_UDP 1

/*----- Default Value for MEMP_NUM_UDP_PCB: 3 ---*/

#define MEMP_NUM_UDP_PCB 3

/*----- Value in opt.h for DEFAULT_UDP_RECVMBOX_SIZE: 6 -----*/

#define DEFAULT_UDP_RECVMBOX_SIZE 6

/*----- Default Value for MEMP_NUM_TCP_PCB: 6 ---*/

#define MEMP_NUM_TCP_PCB 10

/*----- Default Value for MEM_LIBC_MALLOC: 3 ---*/

#define MEM_LIBC_MALLOC 1

/*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/

#define MEM_ALIGNMENT 4

/*----- Default Value for MEMP_NUM_TCP_PCB_LISTEN: 8 ---*/

#define MEMP_NUM_TCP_PCB_LISTEN 8

/*----- Default Value for PBUF_POOL_BUFSIZE: 592 ---*/

#define PBUF_POOL_BUFSIZE 1524

/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/

#define LWIP_ETHERNET 1

/*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/

#define LWIP_DNS_SECURE 7

/*----- Default Value for TCP_MSS: 536 ---*/

#define TCP_MSS 1460

/*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/

#define TCP_SND_QUEUELEN 9

/*----- Value in opt.h for TCP_SNDQUEUELOWAT: LWIP_MAX(TCP_SND_QUEUELEN)/2, 5) -*/

#define TCP_SNDQUEUELOWAT 5

/*----- Default Value for LWIP_NETIF_LINK_CALLBACK: 0 ---*/

#define LWIP_NETIF_LINK_CALLBACK 1

/*----- Default Value for TCPIP_THREAD_NAME: "tcpip_thread" ---*/

#define TCPIP_THREAD_NAME "TcpIp"

/*----- Value in opt.h for TCPIP_THREAD_STACKSIZE: 0 -----*/

#define TCPIP_THREAD_STACKSIZE 2048

/*----- Value in opt.h for TCPIP_THREAD_PRIO: 1 -----*/

#define TCPIP_THREAD_PRIO osPriorityHigh

/*----- Value in opt.h for TCPIP_MBOX_SIZE: 0 -----*/

#define TCPIP_MBOX_SIZE 16

/*----- Value in opt.h for SLIPIF_THREAD_STACKSIZE: 0 -----*/

#define SLIPIF_THREAD_STACKSIZE 1024

/*----- Value in opt.h for SLIPIF_THREAD_PRIO: 1 -----*/

#define SLIPIF_THREAD_PRIO osPriorityHigh

/*----- Value in opt.h for DEFAULT_THREAD_STACKSIZE: 0 -----*/

#define DEFAULT_THREAD_STACKSIZE 1024

/*----- Value in opt.h for DEFAULT_THREAD_PRIO: 1 -----*/

#define DEFAULT_THREAD_PRIO 5

/*----- Value in opt.h for DEFAULT_TCP_RECVMBOX_SIZE: 0 -----*/

#define DEFAULT_TCP_RECVMBOX_SIZE 16

/*----- Value in opt.h for DEFAULT_ACCEPTMBOX_SIZE: 0 -----*/

#define DEFAULT_ACCEPTMBOX_SIZE 16

/*----- Value in opt.h for LWIP_NETCONN: 1 -----*/

#define LWIP_NETCONN 1

/*----- Value in opt.h for LWIP_SOCKET: 1 -----*/

#define LWIP_SOCKET 1

/*----- Default Value for LWIP_TCP_KEEPALIVE: 0 ---*/

#define LWIP_TCP_KEEPALIVE 1

/*----- Default Value for LWIP_SO_SNDTIMEO: 0 ---*/

#define LWIP_SO_SNDTIMEO 1

/*----- Default Value for LWIP_SO_RCVTIMEO: 0 ---*/

#define LWIP_SO_RCVTIMEO 1

/*----- Default Value for TCP_LISTEN_BACKLOG: 0 ---*/

#define TCP_LISTEN_BACKLOG 1

/*----- Value in opt.h for RECV_BUFSIZE_DEFAULT: INT_MAX -----*/

#define RECV_BUFSIZE_DEFAULT 2000000000

/*----- Default Value for SO_REUSE: 0 ---*/

#define SO_REUSE 1

/*----- Default Value for LWIP_SNTP: 0 ---*/

#define LWIP_SNTP 1

/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */

#define MEMP_NUM_SYS_TIMEOUT 4

/*----- Value in opt.h for LWIP_STATS: 1 -----*/

#define LWIP_STATS 0

/*----- Value in opt.h for CHECKSUM_GEN_IP: 1 -----*/

#define CHECKSUM_GEN_IP 0

/*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/

#define CHECKSUM_GEN_UDP 0

/*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/

#define CHECKSUM_GEN_TCP 0

/*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/

#define CHECKSUM_GEN_ICMP 0

/*----- Value in opt.h for CHECKSUM_GEN_ICMP6: 1 -----*/

#define CHECKSUM_GEN_ICMP6 0

/*----- Value in opt.h for CHECKSUM_CHECK_IP: 1 -----*/

#define CHECKSUM_CHECK_IP 0

/*----- Value in opt.h for CHECKSUM_CHECK_UDP: 1 -----*/

#define CHECKSUM_CHECK_UDP 0

/*----- Value in opt.h for CHECKSUM_CHECK_TCP: 1 -----*/

#define CHECKSUM_CHECK_TCP 0

/*----- Value in opt.h for CHECKSUM_CHECK_ICMP: 1 -----*/

#define CHECKSUM_CHECK_ICMP 0

/*----- Value in opt.h for CHECKSUM_CHECK_ICMP6: 1 -----*/

#define CHECKSUM_CHECK_ICMP6 0

3 REPLIES 3
Piranha
Chief II

Are you using ST's bloatware? Higher layers cannot work if the lower ones are broken...

https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

pferd
Associate III

Thank you for your link. I've read it, but I still don't understand how to solve my problem and where is the problem. There are many projects with at least one socket. They work well.

Geraldo Pereira
Associate II

Hello PFerd,

Sorry but I could not help you, yet. But I need program a F429ZI board with LwIP, RTOS and a simple socket. Could you please suggest me a tutorial? I´m readind the board´s docs, but if you could give me a hint or a example, I´ll be great.

Thanks,

Geraldo.