Skip to main content
Visitor II
June 25, 2019
Question

STM32H743ZI LWIP TCP/IP EchoClient Example

  • June 25, 2019
  • 10 replies
  • 5823 views

I am sorry that I am not good at English.

Hi. 

I use the stm32h743zi mcu. 

I ported stm32h743i-val lwip tcp echo server and client application

server application was well working but client was not working

ping test was not responed.

my firmware flow is this

lwip init -> tcp_echoclient init -> lwip process

i don't use RTOS

    This topic has been closed for replies.

    10 replies

    Visitor II
    October 22, 2019

    Yes, I have the same issue. I am using Nucleo board with STM32H743ZI. I tried lwip netconn echo server without any problem, but I couldn't manage to get neither the tcp echo client example working that uses Raw lwip API (after I ported from STM32H743I) nor using netconn API with FreeRTOS.

    I wish we can get any help from STMicro team regarding the TCP/IP client issue.

    Visitor II
    August 4, 2020

    I have the same problem. I cannot make LWIP TCP client work on stm32f4. Can anybody please provide full example of TCP client working on some discovery board?

    Thank You.

    Peter

    KKim.19Author
    Visitor II
    August 4, 2020

    i had solved the problem. after a while, i couldn't remember exactly

    but i set up recommendded MPU memory and activated the D-cash while the lwip processing

    and increased the heap memory.

    i recommend debugging through wireshark.

    i hope it helped you​

    thank you

    Visitor II
    August 4, 2020

    Thx Kim for answer,

    Can you please tell me where I find this recommendation? I am generating project from CubeMX and probably some settings to Ethernet driver or LWIP library is not as it should be. However I am not able to debug what to problem is, I just do not get any error message, any assert nothing, function for connection passes as the connection was successfully established. but I cannot see any message in wireshark, LWIP library did nothing...

    I tried couple approaches to make TCP connection to server:

    raw api:

    echoclient_pcb = tcp_new();

    tcp_connect(echoclient_pcb,&ipaddr,50030,tcp_echoclient_connected);

    netconn api:

    void tcp_client_thread(void)

    {

       struct netconn * conn;

       ip_addr_t ipaddr;

       ip_addr_t local;

       unsigned int   port_no = 50070;

       err_t          err2;

       tcp_setup();

       IP4_ADDR(&local, 192, 168, 0, 70);

       IP4_ADDR(&ipaddr, 192, 168, 0, 30);                                        // Connection destination IP address

           conn = netconn_new(NETCONN_TCP);                                       // create new TCP connection handle

           if (conn!= NULL) {

              err2 = netconn_bind(conn, &local, port_no);

               if (err2 == ERR_OK) {

                  err2 = netconn_connect(conn, &ipaddr, 50030);                    // Connection destination port is 4000

                   if(err2 == ERR_OK) {

                      HAL_GPIO_TogglePin(LED_B_GPIO_Port, LED_B_Pin);

                       while(1) {

                           tcp_client_serve(conn);

                           if (conn->pcb.tcp->state == CLOSE_WAIT) {

                               break;

                           }

                       }

                   }

                   else {

                       printf("Connect server fail ! \n");

                   }

               }

               else {

                   printf("can not bind netconn");

               }

           }

           else {

               printf("can not create netconn");

           }

           netconn_delete(conn);                                                  // delete TCP connection handle

           if (port_no < 0xFFFF)  port_no++;                                     // port number is increment

           else                   port_no = 0xC000;

           osDelay(1000);

           HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);

       }

    }

    both approaches pass without failing, but as I said, chip do not send any ACK message. But when I create netconn server on the same board, with the same Ethernet an LWIP setup, everything works OK

     struct netconn *conn, *newconn;

     err_t err, accept_err;

    netcon TCP server - works fine with the same ethernet and lwip configuration.

     conn = netconn_new(NETCONN_TCP);

     HAL_GPIO_WritePin(GPIOE, LED_P_Pin, GPIO_PIN_SET);

     if (conn!= NULL)

     {

       /* Bind to port 80 (HTTP) with default IP address */

       err = netconn_bind(conn, NULL, 50070);

       if (err == ERR_OK)

       {

         HAL_GPIO_WritePin(GPIOE, LED_W_Pin, GPIO_PIN_SET);

         /* Put the connection into LISTEN state */

         netconn_listen(conn);

         while(1)

         {

    //      HAL_GPIO_TogglePin(GPIOE, LED_B_Pin);

           /* accept any icoming connection */

           accept_err = netconn_accept(conn, &newconn);

           if(accept_err == ERR_OK)

           {

              HAL_GPIO_TogglePin(GPIOE, LED_B_Pin);

             /* serve connection */

             http_server_serve(newconn);

             /* delete connection */

             netconn_delete(newconn);

           }

         }

       }

     }

    thx a lot

    Peter

    Visitor II
    August 4, 2020

    Thx Kim for answer,

    Can you please tell me where I find this recommendation? I am generating project from CubeMX and probably some settings to Ethernet driver or LWIP library is not as it should be. However I am not able to debug what to problem is, I just do not get any error message, any assert nothing, function for connection passes as the connection was successfully established. but I cannot see any message in wireshark, LWIP library did nothing...

    I tried couple approaches to make TCP connection to server:

    raw api:

    echoclient_pcb = tcp_new();

    tcp_connect(echoclient_pcb,&ipaddr,50030,tcp_echoclient_connected);

    netconn api:

    void tcp_client_thread(void)

    {

       struct netconn * conn;

       ip_addr_t ipaddr;

       ip_addr_t local;

       unsigned int   port_no = 50070;

       err_t          err2;

       tcp_setup();

       IP4_ADDR(&local, 192, 168, 0, 70);

       IP4_ADDR(&ipaddr, 192, 168, 0, 30);                                        // Connection destination IP address

           conn = netconn_new(NETCONN_TCP);                                       // create new TCP connection handle

           if (conn!= NULL) {

              err2 = netconn_bind(conn, &local, port_no);

               if (err2 == ERR_OK) {

                  err2 = netconn_connect(conn, &ipaddr, 50030);                    // Connection destination port is 4000

                   if(err2 == ERR_OK) {

                      HAL_GPIO_TogglePin(LED_B_GPIO_Port, LED_B_Pin);

                       while(1) {

                           tcp_client_serve(conn);

                           if (conn->pcb.tcp->state == CLOSE_WAIT) {

                               break;

                           }

                       }

                   }

                   else {

                       printf("Connect server fail ! \n");

                   }

               }

               else {

                   printf("can not bind netconn");

               }

           }

           else {

               printf("can not create netconn");

           }

           netconn_delete(conn);                                                  // delete TCP connection handle

           if (port_no < 0xFFFF)  port_no++;                                     // port number is increment

           else                   port_no = 0xC000;

           osDelay(1000);

           HAL_GPIO_TogglePin(LED_G_GPIO_Port, LED_G_Pin);

       }

    }

    both approaches pass without failing, but as I said, chip do not send any ACK message. But when I create netconn server on the same board, with the same Ethernet an LWIP setup, everything works OK

     struct netconn *conn, *newconn;

     err_t err, accept_err;

    netcon TCP server - works fine with the same ethernet and lwip configuration.

     conn = netconn_new(NETCONN_TCP);

     HAL_GPIO_WritePin(GPIOE, LED_P_Pin, GPIO_PIN_SET);

     if (conn!= NULL)

     {

       /* Bind to port 80 (HTTP) with default IP address */

       err = netconn_bind(conn, NULL, 50070);

       if (err == ERR_OK)

       {

         HAL_GPIO_WritePin(GPIOE, LED_W_Pin, GPIO_PIN_SET);

         /* Put the connection into LISTEN state */

         netconn_listen(conn);

         while(1)

         {

    //      HAL_GPIO_TogglePin(GPIOE, LED_B_Pin);

           /* accept any icoming connection */

           accept_err = netconn_accept(conn, &newconn);

           if(accept_err == ERR_OK)

           {

              HAL_GPIO_TogglePin(GPIOE, LED_B_Pin);

             /* serve connection */

             http_server_serve(newconn);

             /* delete connection */

             netconn_delete(newconn);

           }

         }

       }

     }

    thx a lot

    Peter

    Visitor II
    August 4, 2020

    only thing I see in Wireshark is

    ARP Who has 192.168.0.30? Tell 192.168.0.70

    LLDP MA/8c:3b:ad:2c:ed:a0 LA/g7 120

    but after this no ACK message of TCP protokol

    Visitor II
    August 4, 2020

    only thing I see in Wireshark is

    ARP Who has 192.168.0.30? Tell 192.168.0.70

    LLDP MA/8c:3b:ad:2c:ed:a0 LA/g7 120

    but after this no ACK message of TCP protokol

    Visitor II
    August 5, 2020

    Hi Piranha,

    thank You for the answer.

    I am trying to implemented recommended changes, but I am not able to do them all. I am using stm32f417 chip. I am generating cubeMX project with RTOS and LWIP with firmware package STM32Cube_FW_F4_V1.25.0 and cubeMX version 5.6.1

    from the list You provided:

    https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

    I have added these modifications:

    1.

    i added ad the end of function MX_LWIP_Init() in the lwip.c:

    ETH->MACIMR = ETH_MACIMR_TSTIM | ETH_MACIMR_PMTIM;

    ETH->MMCRIMR = ETH_MMCRIMR_RGUFM | ETH_MMCRIMR_RFAEM | ETH_MMCRIMR_RFCEM;

    ETH->MMCTIMR = ETH_MMCTIMR_TGFM | ETH_MMCTIMR_TGFMSCM | ETH_MMCTIMR_TGFSCM;

    2.

    I added function MPU_Config() and call it at the end of main function inicialization.

    void MPU_Config(void)

    {

       MPU_Region_InitTypeDef MPU_InitStruct;

       /* Disables the MPU */

       HAL_MPU_Disable();

       /**Initializes and configures the Region and the memory to be protected

       */

       MPU_InitStruct.Enable = MPU_REGION_ENABLE;

       MPU_InitStruct.Number = MPU_REGION_NUMBER2;

    ...

    The rest I am not able to identify what exactly should i change and where.

    1.

    from the point:

    https://community.st.com/s/question/0D50X0000C4Nk4GSQS/bug-missing-compiler-and-cpu-memory-barriers

    I cannot locate OWN bit so i do not know where to add __DMB()

    2.

    https://community.st.com/s/question/0D50X0000B2AG7FSQW/ethernet-send-complete-interrupt-not-triggered-in-stm32f7

    this is very confusion, no clue what should be done.

    3.

    this one is last one applicable for stm32f4

    lwIP API related:

    • Code made by ST is not thread-safe. When used with RTOS, it generally ignores lwIP requirements described in Common pitfalls and Multithreading. IP stack initialization, Ethernet link status and DHCP processing code are all broken in this regard.
    • Improper use of netif up/down status. The meaning of NETIF_FLAG_UP flag changed in v2.0.0, but ST's code is not updated. For a link status NETIF_FLAG_LINK_UP flag must be used.
    • Improper use of DHCP client. The code is for an outdated version of DHCP client.

    I use fixed IP address, so no DHCP is used.

    anybody could help please?

    Thank You.

    Peter

    Visitor II
    August 6, 2020

    Could enyone help please? I really cannot move from this place.

    Thank You.

    Peter

    KKim.19Author
    Visitor II
    August 5, 2020

    I did not use RTOS.

    And I have Project STM32H743I-EVAL in STM32Cube_FH_H7_V1.4.0

    Refer to LWIP Application.

    This is what the MPU referenced.

    https://community.st.com/s/article/FAQ-Ethernet-not-working-on-STM32H7x3

    I hope this helps.

    Visitor II
    August 9, 2020

    ST Community,

    I am stuck at TCP client for STM32f4. Could anybody please give me working example for the STM32f4 chip family?

    Thanks a lot!

    Peter

    Visitor II
    August 7, 2020

    Hi ST comunity, could somebody please provide CubeMX file with RTOS and LWIP properly setup for stm32f4* chip ,that will generate project, which i could use for running TCP client?

    Thank You.

    Peter

    Visitor II
    August 10, 2020

    Hi ST comunity,

    Here I add my TCP client project generated with CubeMX. As I said, project is nto working, I cannot see ACK message beeing send out of the chip. However with the same setup TCP server is working good.

    Could anybody please help?

    Thank You.

    Peter