Request for Baremetal TCP Client Example Using LwIP Stack on MIMXRT1180-EVK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Request for Baremetal TCP Client Example Using LwIP Stack on MIMXRT1180-EVK

Jump to solution
497 Views
PavanKumarS
Contributor II

Hello,

I am working with the MIMXRT1180-EVK board and would like to implement a baremetal TCP client using the LwIP stack. Could you kindly provide an example or point me toward resources that would help me achieve this?

I am looking for a basic setup that includes Ethernet initialization and a simple TCP client communication implementation.

Any assistance would be greatly appreciated!

Thank you.

0 Kudos
Reply
1 Solution
370 Views
Harry_Zhang
NXP Employee
NXP Employee

HI @PavanKumarS 

Sorry, i forgot it.

ethernetif_input(&netif) is responsible for processing incoming packets. Without this function being called, your application doesn’t receive Ethernet frames from the network interface.

If you remove the loop, network events like incoming packets or timeouts won’t be handled, so the connection won’t be properly maintained.

If you want to avoid relying on this polling loop, you can use LwIP with an operating system (like FreeRTOS) to handle network events asynchronously through interrupts and tasks.

BR

Hang

View solution in original post

0 Kudos
Reply
5 Replies
463 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @PavanKumarS 

You can download the MIMXRT1180-EVK SDK.

Select Board | MCUXpresso SDK Builder (nxp.com)

And you can refer to lwip examples.

HangZhang_0-1728901501274.png

BR

Hang

0 Kudos
Reply
459 Views
PavanKumarS
Contributor II
Hi @Harry_Zhang,
I have checked the SDK, but I was not able to find the bare metal TCP client example. Could you kindly provide an example or point me towards the resources that could help.
0 Kudos
Reply
435 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @PavanKumarS 

To implement a baremetal TCP client on the MIMXRT1180-EVK using the LwIP stack,

Import the lwip_ping_bm_cm33 example.

This examples include the necessary Ethernet initialization, which you can adapt to create a TCP client.

Then you will add client codes.

Here’s a basic example for creating a TCP client. You need to set up a connection and manage sending and receiving data using callbacks.
#include "lwip/tcp.h"
static struct tcp_pcb *tcp_client_pcb;
// Callback when data is received
err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) {
if (p == NULL) {
// Connection closed
tcp_close(tpcb);
return ERR_OK;
}
// Process received data
tcp_recved(tpcb, p->len);
pbuf_free(p);
return ERR_OK;
}
// Callback when a TCP connection is established
err_t tcp_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
if (err == ERR_OK) {
// Connection successful
// Set the receive callback
tcp_recv(tpcb, tcp_client_recv);
// Send some data
const char *data = "Hello, Server!";
tcp_write(tpcb, data, strlen(data), TCP_WRITE_FLAG_COPY);
} else {
// Handle connection error
tcp_close(tpcb);
}
return err;
}
// Initiate the TCP connection
void tcp_client_connect(void) {
ip_addr_t server_ip;
IP4_ADDR(&server_ip, 192, 168, 1, 100); // Set the server's IP address
// Create a new TCP control block
tcp_client_pcb = tcp_new();
// Connect to the server on port 80 (you can change this to your desired port)
tcp_connect(tcp_client_pcb, &server_ip, 80, tcp_client_connected);
}

Integrate everything in the main() function of your application.
int main(void) {
// Board initialization (clocks, Ethernet, etc.)
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitDebugConsole();
// Initialize the LwIP stack and network interface
lwip_init_function();
// Start the TCP client
tcp_client_connect();
while (1) {
// LwIP needs to be continuously polled to handle network events
sys_check_timeouts();
}
return 0;
}

BR

Hang

0 Kudos
Reply
407 Views
PavanKumarS
Contributor II
Hi @Harry_Zhang,
I followed the steps provided and implemented the TCP client as described, but I encountered an issue where the connection wasn't being established with the server. However, when I added the line ethernetif_input(&netif); in the main while loop, the connection worked.
the loop:
while (1) {
ethernetif_input(&netif);
// LwIP needs to be continuously polled to handle network events
sys_check_timeouts();
}

I’m trying to understand why this loop is necessary. Is there a way to isolate the connection functionality so that it doesn't rely on the loop? How can I make the connection part independent of this polling mechanism?
0 Kudos
Reply
371 Views
Harry_Zhang
NXP Employee
NXP Employee

HI @PavanKumarS 

Sorry, i forgot it.

ethernetif_input(&netif) is responsible for processing incoming packets. Without this function being called, your application doesn’t receive Ethernet frames from the network interface.

If you remove the loop, network events like incoming packets or timeouts won’t be handled, so the connection won’t be properly maintained.

If you want to avoid relying on this polling loop, you can use LwIP with an operating system (like FreeRTOS) to handle network events asynchronously through interrupts and tasks.

BR

Hang

0 Kudos
Reply