cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107+LWIP(2.0.3)+freeRTOS not work

HKabi.1
Associate II

i use STM32F107+LWIP(2.0.3)+freeRTOS

I wrote the program with the help of the following document :

https://www.st.com/resource/en/user_manual/um1713-developing-applications-on-stm32cube-with-lwip-tcpip-stack-stmicroelectronics.pdf

After connecting the computer with the micro a few times, the information is correctly received by the micro.

But I don't send a reply to the computer. The tcp_server_recv callback function only turns one LED on and off for one second.

After sending information a few times, it stops receiving and I don't have ping anymore.

What advice can you give?

1 ACCEPTED SOLUTION

Accepted Solutions
Piranha
Chief II

You have to be kidding... You are not freeing the PBUF! All examples, including the one from ST, does free the PBUF. And as LCE said, you have to close your the connection, when the other end closes it.

static err_t TCPRecv_(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
	if (!p) {
		tcp_close(tpcb);
		return ERR_OK;
	}
 
	// Process the received data
 
	tcp_recved(tpcb, p->tot_len);
	pbuf_free(p);
	return ERR_OK;
}

Read the documentation and this:

https://lwip.fandom.com/wiki/Raw/TCP

Also, when using the lwIP core API with RTOS, the lwIP core locking must be used. You can find more information and examples in the following topic:

https://community.st.com/s/question/0D53W00001sGiChSAK/cubemx-lwip-ethernetlinkthread-bug

View solution in original post

13 REPLIES 13
HKabi.1
Associate II

My receive callback is :

static err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,err_t err) {
 
	if (p != NULL){
 
            tcp_recved(tpcb,p->tot_len);
 
            HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
 
            osDelay(1000);
 
            HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
 
	}
 
	return ERR_OK;
 
}

Many times the receive callback function is executed twice.

It stops after a few pings.

The result can be seen in the photo.

0693W00000WHs3pQAD.png 

This device works well with another program written with lwip-1.3.1 and Kiel.

LCE
Principal

So you don't handle pbuf == NULL, or err != ERR_OK.

Check some examples and why that might be necessary (e.g., closing connection).

HKabi.1
Associate II

pbuf is structure and define p

struct pbuf *p (line 1 break)

I added the error check but it didn't make any difference

static err_t tcp_server_recv(void *arg,struct tcp_pcb *tpcb,struct pbuf *p, err_t err) {
	if ((p != NULL) && (err==ERR_OK)){
	  tcp_recved(tpcb,p->tot_len);
	  Beep();
	}
	return ERR_OK;
}

i can not test my program with keil becuse when i export to keil and comple get this err :

../Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h(71): error: #5: cannot open source input file "reent.h": No such file or directory 

HKabi.1
Associate II

I created the project without FreeRTOS but the problem still exists and it crashes after receiving the network a few times.

HKabi.1
Associate II

Has anyone used lwip and tcpserver in cube?

I have a very hard problem with this on my stm32f107vct6 micro and no one can help.

I used Cube's LWIP TCP ECHO SERVER example in stm32f107, but the same problem exists.

I think this problem is from ST side. @st

LCE
Principal

I started with the Cube stuff and the HAL ethernet drivers with a STM32F767.

I had a HTTP server (http is based on TCP) up quite quickly, TCP echo working too.

The problems were rather on my lwIP's "opt.h" side, and the HAL ethernet drivers.

It was not "plug and play".

Check your code, use the CubeIDE debugging tools and work through it.

If you want to use STM32 and lwIP for some serious stuff = work / job, then you have to understand more than using CubeMX.

I use the CubeIDE debugger. No errors or exceptions occur, only the ping is interrupted and the network connection is interrupted. But the main loop is still running.

This happens almost after sending 8 data packets.

Piranha
Chief II

You have to be kidding... You are not freeing the PBUF! All examples, including the one from ST, does free the PBUF. And as LCE said, you have to close your the connection, when the other end closes it.

static err_t TCPRecv_(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
	if (!p) {
		tcp_close(tpcb);
		return ERR_OK;
	}
 
	// Process the received data
 
	tcp_recved(tpcb, p->tot_len);
	pbuf_free(p);
	return ERR_OK;
}

Read the documentation and this:

https://lwip.fandom.com/wiki/Raw/TCP

Also, when using the lwIP core API with RTOS, the lwIP core locking must be used. You can find more information and examples in the following topic:

https://community.st.com/s/question/0D53W00001sGiChSAK/cubemx-lwip-ethernetlinkthread-bug

spoatech
Associate II

Does anyone know what is causing this error and how to fix it in STMCubeIDE?

 

spoatech_0-1709480785790.png

 

Thanks!