cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DISCO + TouchGFX + Ethernet

Hello, I would like to add ethernet support to my TouchGFX application.

I have got the LwIF directory from Cube, copied this in my TouchGFX app directory and integrated to gcc\Makefile with the following change:

components := TouchGFX/gui target TouchGFX/generated/gui_generated LwIP

and

       $(Drivers_path)/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_eth.c \

After some include moving to compile now I have a link ok.

This is my actual code but still no DHCP work!

I don't see the new IP on router.

#include "lwip/opt.h"
#include "lwip/stats.h"
#include "lwip/sys.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/init.h"
#include "lwip/netif.h"
#include "netif/etharp.h"
 
#include "ethernetif.h"
 
struct netif    netif_data;

void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
    if (p != NULL) {
        /* send received packet back to sender */
        udp_sendto(pcb, p, addr, port);
        /* free the pbuf */
        pbuf_free(p);
    }
}
 
void          BSP_ETH_Init()
{
    struct udp_pcb * pcb;
    struct netif   *netif = &netif_data;
    struct ip4_addr  ipaddr;
    struct ip4_addr  netmask;
    struct ip4_addr  gateway;
 
    lwip_init();
 
    IP4_ADDR(&netmask, 0,0,0,0);
    IP4_ADDR(&gateway, 0,0,0,0);
    IP4_ADDR(&ipaddr, 0,0,0,0);
 
    netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL,ethernetif_init,ip_input);
 
    netif_set_default(netif);
 
    if (netif_is_link_up(netif))
    {
       netif_set_up(netif);
    }
    else
    {
       netif_set_down(netif);
    }
 
    dhcp_start(netif);
 
 
    pcb = udp_new();
 
    if (pcb == NULL) 
    {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
        return;
    }
 
    if (udp_bind(pcb, IP_ADDR_ANY, 7) != ERR_OK) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
        return;
    }
 
 
    udp_recv(pcb, udp_echo_recv, NULL);
 
}

2 REPLIES 2

NO_SYS flag must be 1 or 0 with TouchGFX in lwipopts.h file ?

tcpip_init(NULL, NULL); or    lwip_init();

Piranha
Chief II

Your topics are not about ST's "Interface and Connectivity ICs". IC is an integrated circuit - for example Ethernet PHY, Bluetooth chips etc. Your topics are about lwIP (not LwIF - at least try to read the 4 letter name without errors) software on STM32 MCU.

You haven't even said from where you are taking lwIP code. I'm assuming is't a bloatware from CubeMX... In your previous topic I gave you a link to my Ethernet & lwIP problem report. Did you read it? Was the brain turned on, when you were reading? From that link it must be completely clear that ST's implementation of lwIP on F7 series is not working! And it probably never will, because their brainless code monkeys haven't been able to make a working implementation of lwIP since the year 2007!!!

> how to add some code to give an answer to a ping or to a specific port ?

Pinging is done by ICMP protocol and it should be on by default.

> what to insert before the udp_new(); to start dhcp client ?

DHCP is started by ST's code, but that code is totally broken. That is described in my topic and there are links to more details in documentation.

> NO_SYS flag must be 1 or 0 with TouchGFX in lwipopts.h file ?

> tcpip_init(NULL, NULL); or  lwip_init();

And again you haven't read anything from the documentation!

https://www.nongnu.org/lwip/2_0_x/pitfalls.html

https://www.nongnu.org/lwip/2_0_x/group__lwip__nosys.html

https://www.nongnu.org/lwip/2_0_x/group__lwip__os.html

https://github.com/yarrick/lwip/blob/1a10a942f22c5d139573c5a4b68431a57ea47d30/src/include/lwip/opt.h#L71