cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-F39ZI with LwIP and FREERTOS simple tcp echo app doesn't work properly

AFara.2
Associate II

Hi all,

I'm trying to develop a simple tcp echo application with my NUCLEO-F439ZI. I used CubeMX to configure my board. My app is under FREERTOS using LwIP library. I followed example indications I found but It really doesn't work fine. This is the my CubeMX configuration:

-- CLOCK0693W000000UCMEQA4.jpg

-- System base time source

0693W000000UCMnQAO.jpg

-- ETH

0693W000000UCN7QAO.jpg0693W000000UCNHQA4.jpg

-- FREERTOS

0693W000000UCOjQAO.jpg

0693W000000UCOoQAO.jpg

0693W000000UCP8QAO.jpg

-- LwIP

0693W000000UCPhQAO.jpg

0693W000000UCPmQAO.jpg

0693W000000UCPwQAO.jpg

My code is the following:

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_FREERTOS_Init(); 

 osKernelStart();

 while (1){}

}

void MX_FREERTOS_Init(void) {

 osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 256);

 defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

}

void StartDefaultTask(void const * argument)

{

 MX_LWIP_Init();

 tcpecho_init();

 for(;;)

 {

  osDelay(1);

 }

}

void MX_LWIP_Init(void)

{

 /* IP addresses initialization */

 IP_ADDRESS[0] = 192;

 IP_ADDRESS[1] = 168;

 IP_ADDRESS[2] = 0;

 IP_ADDRESS[3] = 10;

 NETMASK_ADDRESS[0] = 255;

 NETMASK_ADDRESS[1] = 255;

 NETMASK_ADDRESS[2] = 255;

 NETMASK_ADDRESS[3] = 0;

 GATEWAY_ADDRESS[0] = 0;

 GATEWAY_ADDRESS[1] = 0;

 GATEWAY_ADDRESS[2] = 0;

 GATEWAY_ADDRESS[3] = 0;

  

 tcpip_init( NULL, NULL );

 IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);

 IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);

 IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);

 netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

 netif_set_default(&gnetif);

 if (netif_is_link_up(&gnetif))

 {

  netif_set_up(&gnetif);

 }

 else

 {

  netif_set_down(&gnetif);

 }

 netif_set_link_callback(&gnetif, ethernetif_update_config);

 osSemaphoreDef(Netif_SEM);

 Netif_LinkSemaphore = osSemaphoreCreate(osSemaphore(Netif_SEM) , 1 );

 link_arg.netif = &gnetif;

 link_arg.semaphore = Netif_LinkSemaphore;

 osThreadDef(LinkThr, ethernetif_set_link, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2);

 osThreadCreate (osThread(LinkThr), &link_arg);

}

void tcpip_init(tcpip_init_done_fn initfunc, void *arg)

{

 lwip_init();

 tcpip_init_done = initfunc;

 tcpip_init_done_arg = arg;

 if (sys_mbox_new(&tcpip_mbox, TCPIP_MBOX_SIZE) != ERR_OK) {

  LWIP_ASSERT("failed to create tcpip_thread mbox", 0);

 }

#if LWIP_TCPIP_CORE_LOCKING

 if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {

  LWIP_ASSERT("failed to create lock_tcpip_core", 0);

 }

#endif /* LWIP_TCPIP_CORE_LOCKING */

 sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);

}

void tcpecho_init(void){

sys_thread_new("tcpecho_server", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, osPriorityAboveNormal);

return;

}

static void tcpecho_thread(void *arg){

struct netbuf *my_buf;

void *data;

u16_t len;

struct netconn *conn, *newconn;

err_t err, accept_err, recv_err;

/* Create a new connection identifier */

conn = netconn_new(NETCONN_TCP);

if(conn != NULL){

/* Bind connection to well know port number 7 */

err = netconn_bind(conn, NULL, 7);

if(err == ERR_OK){

/* Tell connection to go into listening mode */

netconn_listen(conn);

while(1){

/* Grab new connection */

accept_err = netconn_accept(conn, &newconn);

/* Process the new connection */

if(accept_err == ERR_OK){

while ((recv_err = netconn_recv(newconn, &my_buf)) == ERR_OK){

do{

netbuf_data(my_buf, &data, &len);

netconn_write(newconn, data, len, NETCONN_COPY);

HAL_GPIO_TogglePin(GPIOB, LD1_Pin|LD3_Pin|LD2_Pin);

}

while (netbuf_next(my_buf) >= 0);

netbuf_delete(my_buf);

}

/* Close connection and discard connection identifier */

netconn_close(newconn);

netconn_delete(newconn);

}

}

}

else{

netconn_delete(newconn);

}

}

}

When I debug, my code always go into static void prvCheckTasksWaitingTermination( void ) function.

Could you help me please? It took me forever.

Thank you.

Regards

3 REPLIES 3
AFara.2
Associate II

Hi @Piranha​ ,

thank you for answering me. I read your page but I can't understand very well all you want to say. I'm working on NUCLEO-F439ZI. Is it possible to receive some code examples please? I think so I'll can understand well. Also some code parts.

Regards

Nettok
Associate II

Hi @AFara.2​ . What worked for me was to set "PHY Address = 0" , that would be in the third image that you posted. Otherwise, all other configuration was left with their defaults.