cancel
Showing results for 
Search instead for 
Did you mean: 

How to call LwIP thread-unsafe functions when using FreeRTOS?

_AdamNtrx
Associate III

Hello!

I am writing a program that uses FreeRTOS and LwIP libraries. I would want to check ARP table, but functions from ip4 directory are not considered thread-safe. How can I check ARP table when using FreeRTOS or how can I make sure calling thread-unsafe functions won't break my program?

I saw that there is an LwIP mutex that can be used to lock the stack via LOCK_TCPIP_CORE() and UNLOCK_TCPIP_CORE() macros, but I am not sure how to use them properly or if it is even a good approach.

 

Thank you in advance!

7 REPLIES 7
MOBEJ
ST Employee

Hello @_AdamNtrx ?

 

Could you please confirm which STM32 board you are using  for your project? This will help us provide you with the accurate example of LWIP using FreeRTOS.

 

Br

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
TDK
Guru

Use a mutex to ensure only one thread is calling a function at once. Or, only call LwIP functions from a single thread.

If you feel a post has answered your question, please click "Accept as Solution".

I use STM32F769I-DISCOVERY board.

Does that mean as long as unsafe LwIP functions are not called simultaneously they are fine to use?

Yes and no.

As long as you keep your LwIP calls to one thread / task, you are safe.
In a preemptive multitasking system, any calls to the same function from different tasks will eventually be "simultaneous", statistically speaking.

 

Alright, so if LwIP functions are either called only in one task or are protected by mutex, they are fine. Got it.

 

What about (UN)LOCK_TCPIP_CORE() macros? How to use them? Or should they be used at all?

Hello @_AdamNtrx , 

Please check out the lwIP projects on GitHub for the STM32F769I board. It can help you with your issue

 

BR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.