ETH_LWIP problem to send UDP in RTOS mode

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
I got working ETH_LWIP in non RTOS mode (at least sending UDP datagrams).
on relax kit 4500

Then I tried to use in RTOS environment. I created two more threads.
If I do nothing related to ETH_LWIP, program seems to work correctly.
Both LED are blinking as expected (so both threads are running) and I can ping the relax kit.

So I tried to send UDP datagram:
1) In task "LED2_Task" I tried to use raw api, same at work for me in non RTOS environment.

void LED2_Task(void const *pvParameters)
{
//register UDP Port
struct udp_pcb *pcb;
struct pbuf * pb;
struct ip_addr dstaddr;

IP4_ADDR(&dstaddr,192,168,0,1);
//create socket and bind
pcb = udp_new();
udp_bind(pcb, IP_ADDR_ANY, DST_UDP_PORT);

//create buffer
pb = pbuf_alloc(PBUF_TRANSPORT, sizeof(string_to_send), PBUF_RAM);
pb->payload = string_to_send;
pb->len = pb->tot_len = sizeof(string_to_send);

while(1)
{

DIGITAL_IO_ToggleOutput(&LED2);
iDebugArray[2]++;
//udp_sendto(pcb, pb, &dstaddr, DST_UDP_PORT);
osDelay( LED2_TASK_DELAY );
}
}


But when I uncommented line 149 in main.c following code
udp_sendto(pcb, pb, &dstaddr, DST_UDP_PORT);
threads are running for a while (according to LED blinking - maybe 5 seconds) a then stop. No UDP was sent.

2) In task "LED1_Task" I tried to use netconn api.
void LED1_Task(void const *pvParameters)
{
struct netconn *conn;
char msg[]="Hello Word" ;
struct netbuf *buf;
char * data;
struct ip_addr dstaddr;

iDebugArray[1]++;
DIGITAL_IO_ToggleOutput(&LED1);



IP4_ADDR(&dstaddr,192,168,0,1);
//conn = netconn_new( NETCONN_UDP );
//netconn_bind(conn, IP_ADDR_ANY, 1234 ); //local port
//netconn_connect(conn, &dstaddr, DST_UDP_PORT );

while(1)
{

//Led indication
iDebugArray[1]++;
DIGITAL_IO_ToggleOutput(&LED1);

//send udp
buf = netbuf_new();
data =netbuf_alloc(buf, sizeof(msg));
memcpy (data, msg, sizeof (msg));
//netconn_send(conn, buf);
netbuf_delete(buf); // De-allocate packet buffer

//wait
osDelay(LED1_TASK_DELAY);

}
}


In this case program stopped completely before thread was executed. When I debugged the code, I find out that program never returned from function
conn = netconn_new( NETCONN_UDP );

on line 101 in main.c (see attachment).

I tried to move netconn_new( NETCONN_UDP ) to main loop before starting RTOS, but result is the same.

Is there any fatal mistake I did?
Is it available any example how to manage UDP packets in RTOS environment?
0 Likes
6 Replies
User11187
Level 2
Level 2
Hi, I have a similar problem with TCP socket.
I dont have a lot of experience with rtos, but in my case I have a stack overflow (system loops in system errore procedure), and the function never returns. Maybe it is the same for you... I think it's a configuration problem, but I don't know how to solve... I hope someone can help us.
0 Likes
Not applicable
Hello.

I have made small research on the web and I found that all examples runs tcpip_init from thread running after osKernelStart is launched.
Something like this:
void LWIP_Init(void)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;

/* Create tcp_ip stack thread */
tcpip_init( NULL, NULL );

//other init...
.....
}

void main_task(void const *args)
{
LWIP_Init();
}
osThreadDef(main_task, osPriorityNormal, 1, 0);

int main(void)
{
osKernelInitialize();
osThreadCreate(osThread(main_task), NULL);
osKernelStart();
}


On the contrary APP run init functions in DAVE_Init() before osKernelStart is launched.
Could be this cause of problems?
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

The RAW API is not meant to be used in an RTOS environment.
The netconn API (LED1_task) is working for me if you increase the default stack size from 200 to 512 bytes in the CMSIS_RTOS_RTX configuration UI.

Best regards,
Jesus
0 Likes
Not applicable
Hi everyone,

With this project, I am able to ping the xmc4500 board.

but by using python or any other socket test app I am not able to receive the message. "Hello Word"
I am using a switch with normal Ethernet cables.
Am I doing something wrong?
did any one successfully run this code? I want to establish a send/receive UDP communication between xmc4500 and a PC.
any help is highly appreciated.

Thanks.
0 Likes
Not applicable
almost same problem here. Not able to connect by using putty in telnet mode.
0 Likes
lock attach
Attachments are accessible only for community members.
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

Find attached an example of a very simplistic telnet server, e.g. only help and bye commands available.

Regards,
Jesus
0 Likes