PlatformIO Community

Lwip... where to begin?

It is not the first time that I am googling for how to use lwip (pppos) on stm32. Every time I start, I get the feeling I am doing things backwards. There seems to be so little (if any) tutorials how to integrate lwip and tailoring it.

Most questions on different forums seem to point out the wikipedia page on lwip, and point to savannah nongnu and fandom. I’ve read them all, but none of them really take me by the hand and tell me, for example, which files I should incorparate to build. Information seems to be divided sparsely.

I found a couple of libaries in platformio, but of course they won’t compile when I choose stm32/st32cube.

I also cloned the official lwip git repo, and find myself staring at sources files not having a clue where to start. Which files to I need? All of them? Should I just start copying files over in my project and hit compile and see what happens?

Who can help me “jump start” this journey? I would love to make my own custom library in platformio and configure it so that I can use pppos.

PS: If there is a good book that explains this I don’t mind buying a copy.

Have you seen this tutorial and the docs?

Especially the tutorial seems pretty straight-forward to me. STM32CubeMX is used to generate a boilerplate project template for LwIP and UART peripheral initialization, then a bit of code is written so that the UART input is fed into the LwIP stack by means of calling pppos_input(), and writing the data that lwIP want’s to send back to the UART in the ppp_output_cb() implementation, along with the needed boilerplate initialization code for the network interface and the connection initiation.

I am starting to fail google. I am going in circles, for some reason I am not man enough to find the things that you can. I will start drilling down the tutorial, and see if I can get that to work. I don’t have cubemx, I think it’s superceeded by stmcube. At least they look a lot alike.

I remember that stmcube wouldn’t allow me to enable lwip middleware for my nucleo f446ze, but to be honest, I never tried to choose a different MCU which does have ethernet support (and thus allows me to choose lwip middleware), and reroute stuff towards pppos after.

Lack of knowledge is holding me back I think. I should be less of a coward and try something :).

OK, new reading material, I’ll start on that. Thx again!!

I started out with creating a project in stm cube, for some random board that allowed me to enable lwip. I noticed that stm forces me to use CMSIS layer on top of FreeRTOS. Since I haven’t read much positive stuff about ST’s generated CMSIS code I wasn’t sure if I should go ahead. I also wasn’t sure which version of lwip they included for me.

So decided to move away from that, and pulled 2.1.0 from savannah (both contrib and their lwip core), and started to put things together. Had a lot of errors (mostly due to stupidity) but in the end I noticed that all linker errors were related to the “OS abstraction” used by lwip: sys_arch.c.

Since I couldn’t manage to tell platformio to allow source files in 2 directories (namely lib/src and lib/OS) I moved the OS folder (which contains the sys_arch.c source file) to lib/src (where it doesn’t really belong…). That does compile.

Well, it compiled before, but now it also compiles when I call “tcp_init” on lwip library.

I pushed the whole thing again to github.

I’ll keep it up 2 date, hopefully until the point where I manage to use lwip with my modem in pppos mode. I think it’s quite a long way to go. Well, I hope not, but I am afraid it is :wink:

If you would have any other suggestions, remarks, concerns, tips, anything, I’d be thankful to hear them.

There i absolutely no correlation between ‘being a man’ and Google skills luck, let me tell you that :smiley:

Looks interesting! Noticed there’s also already FreeRTOS integration in sys_arch.c, but some macros like LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX are set 0 which might get better performance? Anyways, those are tiny things.

You should also check how STM32CubeMX generates boilerplate code to interact with LwIP, e.g. stm32-nucleo144-f7-iks01a1/lwip.c at master · cnoviello/stm32-nucleo144-f7-iks01a1 · GitHub. You can see that it does a few things more than just tcpip_init() but also adds a default network interface and sets up IP addresses etc, and how in stm32-nucleo144-f7-iks01a1/ethernetif.c at 5daaabe5a60cfa81f67a42280c056ad4c0eeba38 · cnoviello/stm32-nucleo144-f7-iks01a1 · GitHub it gathers data from the ethernet MAC controller and pumps it into the network interface – though of course you have to implement the input / output via UART and pppos_input etc.

I’d also recommend that you turn on lwIP debug output in the lwipopts.h :slight_smile: Then some basic UART receive and send code to be able to feed stuff into the lwIP core and you should have a starting point.

I’d be interested to see if this will work – with the tutorial using Linux to set up a PPP network it looks like a good development environment.

Thx for the pointers agan! Will follow up on them. I had a look at the STMCube project and noticed they indeed do more on the init. For now I just stole the tcp_init from that example since I have no idea yet if I need a mac address/network interface when I use the pppos approach. Reading your comment, I guess you already know that I do.

Maybe it will become more clear when I read the links you shared. I will follow up on them.

PS: if you are willing, and can find the time: I just pushed some changes, which make the AT protocol I already wrote earlier “synchronous” instead of cyclic (which I had to do before I had the luxury of freertos at my disposal). If am curious if I am using free rtos “as they are intended”.

Added sio.h implementation and ppposclient implementation. It runs, no clue if it makes any sense at all :smiley:

But it doesn’t hang up, so I guess that counts for something, right?!

I hope I have time tomorrow to try to actually to connect a socket to the outside digitial world (I probably end up really disappointed! :p)

1 Like

Hey Max, just wanted to let you know, I just managed to open a socket to Google \o/. Lwip over pppos works!

If useful I will post the final solution to github.

Thx again for the pointers!

1 Like

Sorry for not looking into it, haven’t had time set aside for setting up PPPOS on my linux system and test it on one of my STM32F4x MCUs, but it looks like you’ve been quite successful! :slight_smile:

1 Like