victormerino wrote on Thursday, December 13, 2018:
I am trying to implement a TCP MODBUS Server in FREERTOS (for STM32F7). I am using LWIP Sockets. When I use only one task, it works fine, but when I use more than one, the task that uses accept() and recv() gets blocked and I don’t know why…
Could someone help me?
heinbali01 wrote on Thursday, December 13, 2018:
It is hard to tell what goes wrong with so little information.
It is perfectly normal for
recv() to block for a certain time. This time-out can be configured with a call to
accept() never wakes up, it sounds like there is no incoming request to connect.
recv() blocks for ever, apparently there is no incoming data.
Please keep in mind that your tasks run in a multi-tasking environment. Only one task be be active at a time, and so be aware that every task must block or sleep regularly. Could it be that you have a task that is just spinning and refuses to block ( yield )?
rtel wrote on Thursday, December 13, 2018:
Hmm, there are many ways you could have done the integration so
assistance is not that easy (this is after all a third party piece of
software, not FreeRTOS, which is the subject of this forum). Some time
back I did a reference integration using the Windows simulator - that
project is still available in the FreeRTOS Interactive site
(http://interactive.freertos.org - under the non vendor specific
category) although both FreeRTOS and lwIP have moved on a long way since
then. As I recall, at that time (maybe still, don’t know), lwIP was
only thread safe if you used its sockets API. Also, from memory, one of
the key factors was how you handled memory allocation for packets
received in interrupts - best to defer the memory allocation to the task
level (but then lwIP also has many memory allocation schemes). I’m
afraid that is about as much as I can do…
victormerino wrote on Friday, December 14, 2018:
My problem comes when the task that uses recv() and accept() gets blocked so the next task in priority is selected to run. Because if other task is running, when I send some data to the Socket, it doesn’t receive the message. I want to receive the data and interpret it with different tasks. Moreover, I want to have more tasks than these mentioned. Is it possible?
heinbali01 wrote on Friday, December 14, 2018:
Hi Victor, Richard has already tried to explain that lwIP is third-party software, and we can not give support on it. lwIP also has a forum which is actively monitored by some great engineers.
Maybe you want to have a look at our FreeRTOS+TCP library. It is an alternative for lwIP. It is well integrated with the FreeRTOS kernel ( 8.0 or higer ).
You can find information on freertos.org/tcp and you can download the latest source code from github.
If you have questions about FreeRTOS+TCP, we’re happy to answer them on this forum.
I want to have more tasks than these mentioned. Is it possible?
One last try to answer your question:
It sounds like you’re doing something basically wrong: a second task doesn’t seem to yield ( block, sleep ). That task prevents the other task from becoming active.