STM32 LWIP PPPos implementation
Asked Answered
L

1

5

On my STM32F7 I have to connect a 3G modem using serial port. I can communicate with the modem using AT commands. I would like to use PPPos (PPP over serial) library from LWIP to enter in PPP mode. So I take a long look at the official documentation

http://lwip.wikia.com/wiki/PPP

and

https://github.com/tabascoeye/lwip/blob/master/doc/ppp.txt

I understand the guideline but I'm really surprise there is no implementation example with serial port. Indeed, I think there is a lot of modems that have a serial interface, so I thought i can easily find an example of use.

Anyone have already done that or has an example ?

Liggins answered 8/2, 2017 at 15:13 Comment(0)
E
11

While I cannot publish my example, the general idea when it comes to integrating TCP/IP stack of your choice with its PPP driver is the same among all serial modems and all TCP/IP stacks that I've worked with.

Generally as you've mentioned, you start with configuring the modem using AT commands - things like checking whether SIM card is present, whether it requires PIN, specifying PIN if needed, checking if it has successfully registered in the network. Possibly reading additional information data such as IMEI, IMSI as well as diagnostic data: signal quality, BER etc. Once you're done, you switch the modem to "data" mode (see ATD*99), wait for the modem to respond to that command and pass the responsibility to the TCP/IP stack, as at this point the modem starts talking PPP.

When it comes to integrating your modem with the stack so it can communicate with it, the implementations I've encountered all require implementing some form of low-level API functions for the stack. For LwIP, the wiki page you've linked in the "PPP over serial" section, it is described quite well how those functions should behave. Because TCP/IP stacks are just a software library not tied to specific hardware and they can be run on almost anything (assuming sufficient resources), specific API implementations such as the one discussed are not always provided - there would have to be a ton of examples for it to provide any value. Although if you google around for it, you might find someone having done it for the MCU that you use personally. Assuming you've already done the part where you successfully comminicate with your modem using AT commands, it shouldn't be much more other than using the send/receive functions you already have. Some slight changes may be required, such as adjusting their behavior (synchronous->asynchronous or vice versa) or redirecting received data to the TCP/IP API receive function instead of your AT command parser. Nonetheless, most of the necessary hard work should be done already.

Once the TCP/IP stack takes over, you continue with the modem using provided stack PPP API. For LwIP see functions such as: pppSetAuth, pppOverSerialOpen. Those will cause the stack to internally handle the necessary communication with the modem over PPP: LCP, PAP/CHAP, IPCP. Once that part is done (you retrieve IP configuration data from the network) it becomes transparent how this operates - it becomes one (of possibly multiple) network interfaces and you use it just as any other one, for example using socket API.

Electroballistics answered 9/2, 2017 at 12:28 Comment(3)
thanks for your huge answer. I will take a look at that but I'm really surprised that there is no sample with basic serial implementation...Liggins
As I've said, every implementation of sending/receiving data differs depending on the MCU used (registers and handling differ), although some libraries such as STM32Cube attempt to provide a common API, at least for a given set of MCU families. However, even for a single MCU type the implementation may differ, depending on the rest of your project. For example it will be different whether you use an operating system such FreeRTOS or not. With OS, you most likely will use system queues to send/reveice data, semaphores to do blocking operations etc., without it you'll probably do it all by hand.Electroballistics
I understand well but STM32Cube have a lot of complex example like HTTP server on one or two MCU. If you have not this one it's easy to understand and adapt to your MCU. For PPPos I've found none.Liggins

© 2022 - 2024 — McMap. All rights reserved.