How to call LwIP thread-unsafe functions when using FreeRTOS?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-24 3:07 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-24 5:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-24 5:48 AM
Use a mutex to ensure only one thread is calling a function at once. Or, only call LwIP functions from a single thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-24 11:20 PM
I use STM32F769I-DISCOVERY board.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-24 11:21 PM
Does that mean as long as unsafe LwIP functions are not called simultaneously they are fine to use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-25 12:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-25 12:49 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-26 6:04 AM
Hello @_AdamNtrx ,
Please check out the lwIP projects on GitHub for the STM32F769I board. It can help you with your issue
BR
