/** ****************************************************************************** * File Name : LWIP.c * Description : This file provides initialization code for LWIP * middleWare. ****************************************************************************** * @attention * *

© Copyright (c) 2021 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "lwip.h" #include "lwip/init.h" #include "lwip/netif.h" #if defined ( __CC_ARM ) /* MDK ARM Compiler */ #include "lwip/sio.h" #endif /* MDK ARM Compiler */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /* Private function prototypes -----------------------------------------------*/ /* ETH Variables initialization ----------------------------------------------*/ void Error_Handler(void); #include "string.h" extern struct eth_addr MACAddr; ip_addr_t ip; ip_addr_t nm; ip_addr_t gw; void LWIP_SetIP(network_settings *net, char *NewIP) { ip4addr_aton(NewIP, &ip); netif_set_ipaddr(&net->netif, &ip); memcpy(net->ipv4_addr, NewIP, strlen(NewIP)); } void LWIP_SetNetMask(network_settings *net, char *NewNetMask) { ip4addr_aton(NewNetMask, &nm); netif_set_netmask(&net->netif, &nm); memcpy(net->ipv4_nm, NewNetMask, strlen(NewNetMask)); } void LWIP_Set_Gateway(network_settings *net, char *NewGateway) { ip4addr_aton(NewGateway, &gw); netif_set_gw(&net->netif, &gw); memcpy(net->ipv4_gw, NewGateway, strlen(NewGateway)); } void LWIP_NetApply(network_settings *net){ ip4addr_aton(net->ipv4_addr, &ip); ip4addr_aton(net->ipv4_nm, &nm); ip4addr_aton(net->ipv4_gw, &gw); netif_set_addr(&net->netif, &ip, &nm, &gw); } void LWIP_SetNetSettings(network_settings *net, char *NewIP, char *NewNetMask, char *NewGateway) { memset(net->ipv4_addr, 0x00, sizeof(net->ipv4_addr)); memcpy(net->ipv4_addr, NewIP, strlen(NewIP)); memset(net->ipv4_nm, 0x00, sizeof(net->ipv4_nm)); memcpy(net->ipv4_nm, NewNetMask, strlen(NewNetMask)); memset(net->ipv4_gw, 0x00, sizeof(net->ipv4_gw)); memcpy(net->ipv4_gw, NewGateway, strlen(NewGateway)); ip4addr_aton(net->ipv4_addr, &ip); ip4addr_aton(net->ipv4_nm, &nm); ip4addr_aton(net->ipv4_gw, &gw); netif_set_addr(&net->netif, &ip, &nm, &gw); } void LWIP_resetIP(network_settings *net){ ip4addr_aton("192.168.0.254", &ip); ip4addr_aton("255.255.255.0", &nm); ip4addr_aton("192.168.0.1", &gw); netif_set_addr(&net->netif, &ip, &nm, &gw); } /* USER CODE END 2 */ /** * LwIP initialization function */ void MX_LWIP_Init(network_settings *net) { ip4addr_aton(net->ipv4_addr, &ip); ip4addr_aton(net->ipv4_nm, &nm); ip4addr_aton(net->ipv4_gw, &gw); netif_add(&net->netif, &ip, &nm, &gw, NULL, ðernetif_init, &tcpip_input); net->netif.flags |= NETIF_FLAG_LINK_UP; net->netif.hwaddr_len = ETH_HWADDR_LEN; net->netif.hwaddr[0] = MACAddr.addr[0]; net->netif.hwaddr[1] = MACAddr.addr[1]; net->netif.hwaddr[2] = MACAddr.addr[2]; net->netif.hwaddr[3] = MACAddr.addr[3]; net->netif.hwaddr[4] = MACAddr.addr[4]; net->netif.hwaddr[5] = MACAddr.addr[5]; /* maximum transfer unit */ net->netif.mtu = 1500; net->netif.flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;// | NETIF_FLAG_LINK_UP; // if (netif_is_link_up(&net->netif))netif_set_up(&net->netif); // else netif_set_down(&net->netif); } #ifdef USE_OBSOLETE_USER_CODE_SECTION_4 /* Kept to help code migration. (See new 4_1, 4_2... sections) */ /* Avoid to use this user section which will become obsolete. */ /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ #endif #if defined ( __CC_ARM ) /* MDK ARM Compiler */ /** * Opens a serial device for communication. * * @param devnum device number * @return handle to serial device if successful, NULL otherwise */ sio_fd_t sio_open(u8_t devnum) { sio_fd_t sd; /* USER CODE BEGIN 7 */ sd = 0; // dummy code /* USER CODE END 7 */ return sd; } /** * Sends a single character to the serial device. * * @param c character to send * @param fd serial device handle * * @note This function will block until the character can be sent. */ void sio_send(u8_t c, sio_fd_t fd) { /* USER CODE BEGIN 8 */ /* USER CODE END 8 */ } /** * Reads from the serial device. * * @param fd serial device handle * @param data pointer to data buffer for receiving * @param len maximum length (in bytes) of data to receive * @return number of bytes actually received - may be 0 if aborted by sio_read_abort * * @note This function will block until data can be received. The blocking * can be cancelled by calling sio_read_abort(). */ u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len) { u32_t recved_bytes; /* USER CODE BEGIN 9 */ recved_bytes = 0; // dummy code /* USER CODE END 9 */ return recved_bytes; } /** * Tries to read from the serial device. Same as sio_read but returns * immediately if no data is available and never blocks. * * @param fd serial device handle * @param data pointer to data buffer for receiving * @param len maximum length (in bytes) of data to receive * @return number of bytes actually received */ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) { u32_t recved_bytes; /* USER CODE BEGIN 10 */ recved_bytes = 0; // dummy code /* USER CODE END 10 */ return recved_bytes; } #endif /* MDK ARM Compiler */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/