FRDM-K64 LWIP as both client and server in bare metal

cancel
Showing results for 
Search instead for 
Did you mean: 

FRDM-K64 LWIP as both client and server in bare metal

935 Views
mignacio
Contributor III

Hello,

I am new to LWIP and programming TCP/IP client and server sockets.

I see 2 kinds of SDK projects available in FRDM-K64 - bare metal (BM) and FreeRTOS - particularly for lwip_tcpecho and lwip_httpsrv SDK projects.

I'd like to create my project in BM.  The goal of the project is create both a client and a server socket to make a connection where the client will be requesting for data, say DS18B20 sensor temperature readings from the server and the client displaying it on the UART console display terminal.  Makes sense?

I see that LWIP_NETCONN and LWIP_SOCKET preprocessor #defines are only enabled in FreeRTOS version.  

Question:

Will all the applications like creating sockets and data buffering receive and transmit work if I "fake-out" the LWIP_NETCONN and LWIP_SOCKET #defines as enabled in BM? E.g. modifiy lwpopts.h to have such overrides under the "else" section of "#if USE_RTOS" or that NOT_USE_RTOS.

In BM, is it just a matter of calling simple functions like create socket, bind, listen, accept (server)... connect, write, read (client)...?

Please advise.

Thanks for the help.

MI

Labels (1)
0 Kudos
9 Replies

866 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @mignacio ,

It could work but you could use the examples that we provide for quick enablement. You have to be aware of all the processes that the stack requires and the specific times to be compatible with the other side.

Thank you for your feedback, we are improving our community for a better experience. However, you could find our different community section for the MCU General Purpose Microcontrollers

https://community.nxp.com/t5/General-Purpose-Microcontrollers/ct-p/general-purpose-mcus

Regards,

Mario

0 Kudos

874 Views
mignacio
Contributor III

 

Hello Mario,

I understand why you recommend using an RTOS for this situation... for multithreaded, multitasking environment so the system can provide time-slicing of resources of K64 MCU, FRDM-K64 memory space and such.

First, I'm trying out simple loop and polling mechanism and build the system from such basic environment so I can fully understand what this SDK base are capable of and then building my own required operations little-by-little on top of it.

For example, I have created a DS18B20 one-wire protocol project & it is pretty much stable.   I'm logging readings and displaying on debug console terminal.  I'm modifying to save the most recent 100 or so readings into memory, etc.

Since last 2 days, I'm looking into ethernet and LWIP and httpserv_bm (baremetal) which right now only accesses a pre-made HTML file to display some test on a browser about LWIP TCP/IP stack.  

Now I'm thinking of the possibility of REPLACING the html file read and output to be reading temperature READINGS that I have logged and outputting that out to the web browser, and such operations.   The point is the other endpoint will be some cloud-based app which will be requesting for such readings and then the FRDM-K64 will need to send-out to that app.

Simple step-by-step without complications of an RTOS.

That's just how I work, start from scratch and do operations in the most basic way THAT I MADE THE DECISION OF and that my loop logic can control.

If that does not work out, say I add a 2nd ethernet port (K64 is capable of 2 ENETS afterall), then I shall consider an RTOS.

Makes sense?

Thanks for all your help.   

I'll definitely keep asking on this community & I hope you forgive some of my dumb ignorant questions. 

(As an aside... Please note, I like the previous NXP community forum whereby I get to choose which specific Kinetis or LPC MCU to parse through posts or from the beginning when I first post the question.  I'm confused because it looks like all NXP/Freescale MCU's are combined in one full list of many other different threads.  How come NXP did this?   Or am I just not configured right?  You can say this is a "complaint".)

Regards,

MI

0 Kudos

888 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi,

Now I have to re-evaluate why I want to use the single board as BOTH client and server to see where my development is going.  

It is possible the requirement, I recommend to use FreeRTOS that provides both examples and is an easy way to adapt, for example, Http and an echo.

However, you have to be aware of the memory that the stacks will require. You could implement a state machine that pools your sockets for any activity. Also, you could implement a small scheduler with 2 tasks that will be checking the LWIP.

Regards,

Mario

0 Kudos

895 Views
mignacio
Contributor III

Folks, 

I figured out my mistakes.   When I reviewed my system connections using an Enet Switch, that was the clue to the problem. 

Both PC and FRDM-K64 should not go through the switch but rather should physically be connected directly to each other, not switch.  Then I have to do "manual" IP address setting of my PC to "192.168.0.100" per readme.txt instruction.

And viola! both lwip_tcpecho_bm and lwip_httpserv_bm individual programs worked fine.   I apologize for my ignorance & mistakes & in case I caused confusion for my silly questions on my last post.

Now I have to re-evaluate why I want to use the single board as BOTH client and server to see where my development is going.   The later goal is to use 2 separate  ENETs (1 external mini board via SPI) to see how a "star" network will be born - one port will be for secured modbus PLC interface and the other to a could application.

I still await anyone's comment if they know how to combine the SDKs to make one board as both  client and server concurrently working in a mainloop NO-OS operation.

Thanks for your help.

MI

0 Kudos

900 Views
mignacio
Contributor III

 

More questions...

I don't know how to make FRDM-K64 SDK project, lwip_httpsrv_bm, work.

Based on readme.txt, 

Overview
========

The lwip_httpsrv demo application demonstrates an HTTPServer on the lwIP TCP/IP stack with bare metal SDK or FreeRTOS.  The user uses an Internet browser to send a request for connection. The board acts as an HTTP server and sends a Web
page back to the PC.

...  I don't know exactly what to put as "host" IP as stated on step 4 preparation here below because 192.168.0.100 does not work on Chrome browser.

Prepare the Demo
================
1. Connect a USB cable between the PC host and the OpenSDA(or USB to Serial) USB port on the target board.
2. Open a serial terminal on PC for OpenSDA serial(or USB to Serial) device with these settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
3. Insert the Ethernet Cable into the target board's RJ45 port and connect it to your PC network adapter.
4. Configure the host PC IP address to 192.168.0.100.???
5. Open a web browser.
6. Download the program to the target board.
7. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

*** This result does not happen... "website can't be reached" ***

Running the demo
================
1. When the demo runs successfully, the terminal will display the following:
Initializing PHY...

************************************************
HTTP Server example
************************************************
IPv4 Address : 192.168.0.102
IPv4 Subnet mask : 255.255.255.0
IPv4 Gateway : 192.168.0.100
************************************************
2. On the browser address bar, type 192.168.0.102(ip address of the board).
The browser should respond as shown below:

lwIP - A Lightweight TCP/IP stack

The web page you are watching was served by a simple web server running on top of the lightweight TCP/IP stack lwIP.

... etc...

... NOT GETTING THAT website on Chrome brower.

 

WHAT AM I MISSING?  What am I doing wrong?  Why this LWIP SDK not working as simple non-OS, mainloop program to display that website?

SHOULD I ASK our IT department to enable access to that board's website?  I mean there is NO security issue message.  It just says, "... can't be reached".

NOTE:  I'm using an Ethernet switch with 3 cables:  1 from the wall to the switch. 1 from switch to my PC.  1 from switch to FRDM-K64 RJ45.   Is there something wrong in that setup?

Please let me know what to do to make this run properly.

Thanks.

MI

 

0 Kudos

882 Views
mignacio
Contributor III

 

More questions...

For now I'm studying the SDK lwip_httpsrv_bm main-loop code function calls running it on FRDM-K64.

I need help how to make this project work.  Not sure I understand IP address I should assign as "host" or client PC address.

I tried what is described on readme.txt for this project as this:

Overview
========

The lwip_httpsrv demo application demonstrates an HTTPServer on the lwIP TCP/IP stack with bare metal SDK or FreeRTOS.  The user uses an Internet browser to send a request for connection. The board acts as an HTTP server and sends a Web page back to the PC.

...

Prepare the Demo
================
1. Connect a USB cable between the PC host and the OpenSDA(or USB to Serial) USB port on the target board.
2. Open a serial terminal on PC for OpenSDA serial(or USB to Serial) device with these settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
3. Insert the Ethernet Cable into the target board's RJ45 port and connect it to your PC network adapter.
4. Configure the host PC IP address to 192.168.0.100.  <<<???
5. Open a web browser.
6. Download the program to the target board.
7. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

===============

My question is on step 4 above.    When the program runs, it dumps this on the debug console:

Initializing PHY...

************************************************
HTTP Server example
************************************************
IPv4 Address : 192.168.0.102
IPv4 Subnet mask : 255.255.255.0
IPv4 Gateway : 192.168.0.100
************************************************

My Windows CMD prompt where I type ipconfig, shows my PC's IP addresses as follows.  Which one really should I enter as IP address to be the "host" so the web browser does NOT hang and say "can't reach the board httpserver" or such message on Chrome browser? instead of what the readme.txt is telling me & what the program default "host" IP address is,  192.168.0.100.   Should I use My PC's IP address whichever is correct here?

CMD> ipconfig

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . :___.local
Link-local IPv6 Address . . . . . : fe80::4070:946a:cac9:69e2%22
IPv4 Address. . . . . . . . . . . : 10.1.1.17
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.1.1.1

Ethernet adapter VirtualBox Host-Only Network:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::110c:a794:5d49:64fc%13
IPv4 Address. . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

0 Kudos

915 Views
mignacio
Contributor III

Hello Mario,

Sorry I'm not interested in using LWIP under any OS.  I've been reading about some topics on "mainloop" no OS example projects.

Do you have any example project that I can easily modify or explain to me how I can modify to make it behave as BOTH server and client (2 nodes) in one program?

Thanks for the help.

MI

0 Kudos

917 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @mignacio,

I hope you are doing great.

Amazon FreeRTOS uses the FreeRTOS kernel for multitasking and inter-task communications, the LWIP Stack requires specific times for all the data that it needs to process.

Please look at the Getting started that could help you to create 

"\SDK_2.8.2_FRDM-K64F_doc\docs\FreeRTOS\Getting Started with MCUXpressoSDK and FreeRTOS OS.pdf"

Also, for better information about the LWIP. Please follow the next link.

https://savannah.nongnu.org/projects/lwip/

Regards,

Mario

 

0 Kudos

839 Views
mjbcswitzerland
Specialist V

Hi

https://www.utasker.com/kinetis/FRDM-K64F.html

Webserver serving web pages from internal Flash or SD card (with Telnet, FTP for loading new pages) supporting dynamic web content and posting new firmware to it.

No RTOS needed and works faster than FreeRTOS and co. due to small, fast code and simplicity.

Also supports second Ethernet interface: https://www.utasker.com/kinetis/TEENSY_3.5.html#LAN

Regards

Mark

 

0 Kudos