2022-11-08 05:58 AM
i use STM32F107+LWIP(2.0.3)+freeRTOS
I wrote the program with the help of the following document :
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?
Solved! Go to Solution.
2022-11-26 07:18 PM
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
2022-11-09 03:13 AM
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.
This device works well with another program written with lwip-1.3.1 and Kiel.
2022-11-09 03:38 AM
So you don't handle pbuf == NULL, or err != ERR_OK.
Check some examples and why that might be necessary (e.g., closing connection).
2022-11-09 04:17 AM
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
2022-11-15 12:24 AM
I created the project without FreeRTOS but the problem still exists and it crashes after receiving the network a few times.
2022-11-15 03:35 AM
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
2022-11-15 05:07 AM
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.
2022-11-15 05:52 AM
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.
2022-11-26 07:18 PM
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
2024-03-03 07:47 AM
Does anyone know what is causing this error and how to fix it in STMCubeIDE?
Thanks!