cancel
Showing results for 
Search instead for 
Did you mean: 

How to integrate lwIP stack on stm32L0 series

BChav.1
Associate III

Hi all,

I am working on stm32L0 controller that communicate with LAN9250 ethernet ic over SPI. Now i want to integrate lwIP stack in code to use the protocols. When checked in stmcube ide i did not see lwIP stack option in middleware in ioc configuration file.

Please guide me how can i integrate the stack in my code?any document for reference?

TIA,

Bipin

9 REPLIES 9
Louis Cloete
Associate III

I don't think there is an LwIP port for STM32L0 because the Middlewares in the IOC generate low level MAC control code for chips with an ETH peripheral. You'll have to read https://www.nongnu.org/lwip/2_1_x/index.html and figure out yourself how to implement the low-level input/output functionality and timers. Good luck!

Hi,

Yes right, there is no support for lwIP in middleware for stm32L0 series. Is there any reference example code for controller that does not have ETH and lwIP support in middleware but lwIP stack is integrated externally?

That would be more helpful in my case as i am still not able figure out how i can map LwIP stack with my low level driver and use low_level_output() and low_level_input() api's.

Thanks,

Bipin .

I'm definitely not an expert, but as I understand it, your low-level input and output functions must have a specific API and they have to be able to give new data to the stack or output new data from the stack to your PHY. I don't have examples other than maybe to create a project for a chip which does have an ETH peripheral (STM23F207 is the one I know) and then reading ST's low level IO code and try to understand what's going on there.

From a certain level upwards the stack takes over, and you shouldn't need to change anything. You only have to provide a driver which can check for new data and read it from the LAN9250 and which can handle sending new data to the LAN9250 if your stack asks you to. You can probably steal ST's implementation of TCP timers as well, since it doesn't depend on the PHY.

Again, good luck! I'm not saying it will be easy. It will depend on how much time you have. If it's a hobby project, you can play. If something needs to be delivered and you bargained on having LwIP available, maybe you should reconsider your options.

Hi LCloe.2,

I have somehow managed to integrate the stack in my project and using RAW api to send/receive data.but what i suspect is still there are some dots missing. i am not able to figure out what is it. Attaching few files from my code for your reference. Can you please check and suggest if there are any dots still missing which is why my code is not working.You can refer to core/src/udpClientRAW.c for udp api's used and ethernetif.c and lwip.c are available in same directory.You can refer to core/src/lwipopts.h to check if configurations are correct or not.

Thanks,

Bipin

So I did not look too closely, but it seems your low level init and input/output routines are just copied from the generated CubeMX code, but with the calls to the Eth peripheral commented. You should replace those with code which can send to / read from your Eth to SPI chip to do the same. You'll probably want to write abstractions which can get a register address or start address and length, read/write bit and data to write. You'll have to study the datasheet for the LAN9250 to figure out how exactly you should control it via SPI. Unfortunately it will be a little overwhelming if this is your first time.

Hi,

Yes right .Low level init and input/output are kept as it is what downloaded in stack code available on http://savannah.nongnu.org/ . Calls to ETH peripheral are commented because my controller does not support on board ETH port and hence in cube mx HAL layer code for ETH is not generated. Instead of using HAL layer transmit and receive functions for ETH, i am using my driver specifically written for LAN9250 code. SendETH_Frame() and RecvETH_Frame() functions are used in low level input and out functions to do the actual tx and rx over SPI.

after referring to application note "UM1713" i am using udp raw api to send and receive messages. while sending messages using udp,low_level_output() should come the picture?but i dont see that api being called when using udp_send(); and that is the missing link in my code as per my understanding.

Can you please guide on that part?

Thanks

Ah, the SendETH_Frame and RecvETH_Frame is commented in the code you attached and I can't find their definitions anywhere. The only occurrence the IDE finds is the one line which is commented. Is it maybe an older version?

BChav.1
Associate III

Hi,

I did not attach the LAN9250.c and .h files in the project that's why the functions calls are commented there. Its purely SPI transactions .

I do not see anything that jumps out as wrong then. I'd suggest you put a breakpoint in your udpClient_send() function and step into all functions it calls. Check if your netif->output points to your low level transmit function or not. If not, it is not initialized correctly.