[PATCH rtems-lwip v2 4/7] rtemslwip: Add STM32F4 lwipopts.h and netstart.c

Kinsey Moore kinsey.moore at oarcorp.com
Tue Sep 6 19:01:32 UTC 2022


On 9/6/2022 11:20, Duc Doan wrote:
> ---
>   rtemslwip/stm32f4/lwipopts.h | 141 +++++++++++++++++++++++++++++++++++
>   rtemslwip/stm32f4/netstart.c |  52 +++++++++++++
>   2 files changed, 193 insertions(+)
>   create mode 100644 rtemslwip/stm32f4/lwipopts.h
>   create mode 100644 rtemslwip/stm32f4/netstart.c
>
> diff --git a/rtemslwip/stm32f4/lwipopts.h b/rtemslwip/stm32f4/lwipopts.h
> new file mode 100644
> index 0000000..49a19e4
> --- /dev/null
> +++ b/rtemslwip/stm32f4/lwipopts.h
> @@ -0,0 +1,141 @@
> +/* USER CODE BEGIN Header */
> +/**
> +  ******************************************************************************
> +  * File Name          : Target/lwipopts.h
> +  * Description        : This file overrides LwIP stack default configuration
> +  *                      done in opt.h file.
> +  ******************************************************************************
> +  * @attention
> +  *
> +  * Copyright (c) 2022 STMicroelectronics.
> +  * All rights reserved.
> +  *
> +  * This software is licensed under terms that can be found in the LICENSE file
> +  * in the root directory of this software component.
> +  * If no LICENSE file comes with this software, it is provided AS-IS.
> +  *
> +  ******************************************************************************
> +  */
> +/* USER CODE END Header */
> +
> +/* Define to prevent recursive inclusion --------------------------------------*/
> +#ifndef __LWIPOPTS__H__
> +#define __LWIPOPTS__H__
> +
> +/*-----------------------------------------------------------------------------*/
> +/* Current version of LwIP supported by CubeMx: 2.1.2 -*/
> +/*-----------------------------------------------------------------------------*/
> +
> +/* Within 'USER CODE' section, code will be kept by default at each generation */
> +/* USER CODE BEGIN 0 */
> +
> +/* USER CODE END 0 */
> +
> +#ifdef __cplusplus
> + extern "C" {
> +#endif
> +
> +/* STM32CubeMX Specific Parameters (not defined in opt.h) ---------------------*/
> +/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
> +/*----- WITH_RTOS disabled (Since FREERTOS is not set) -----*/
> +#define WITH_RTOS 0
> +/*----- CHECKSUM_BY_HARDWARE disabled -----*/
> +#define CHECKSUM_BY_HARDWARE 0
> +/*-----------------------------------------------------------------------------*/
> +
> +/* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/
> +/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
> +/*----- Default value in ETH configuration GUI in CubeMx: 1524 -----*/
> +#define ETH_RX_BUFFER_SIZE 1536
> +/*----- Value in opt.h for NO_SYS: 0 -----*/
> +#define NO_SYS 0
> +/*----- Value in opt.h for SYS_LIGHTWEIGHT_PROT: 1 -----*/
> +#define SYS_LIGHTWEIGHT_PROT 0
> +/*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/
> +#define MEM_ALIGNMENT 4
> +/*----- Default Value for H7 devices: 0x30044000 -----*/
> +#define LWIP_RAM_HEAP_POINTER 0x20017f58
> +/*----- Value supported for H7 devices: 1 -----*/
> +#define LWIP_SUPPORT_CUSTOM_PBUF 1
> +/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/
> +#define LWIP_ETHERNET 1
> +/*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/
> +#define LWIP_DNS_SECURE 7
> +/*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/
> +#define TCP_SND_QUEUELEN 9
> +/*----- Value in opt.h for TCP_SNDLOWAT: LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) -*/
> +#define TCP_SNDLOWAT 1071
> +/*----- Value in opt.h for TCP_SNDQUEUELOWAT: LWIP_MAX(TCP_SND_QUEUELEN)/2, 5) -*/
> +#define TCP_SNDQUEUELOWAT 5
> +/*----- Value in opt.h for TCP_WND_UPDATE_THRESHOLD: LWIP_MIN(TCP_WND/4, TCP_MSS*4) -----*/
> +#define TCP_WND_UPDATE_THRESHOLD 536
> +/*----- Value in opt.h for LWIP_NETIF_LINK_CALLBACK: 0 -----*/
> +#define LWIP_NETIF_LINK_CALLBACK 1
> +/*----- Value in opt.h for LWIP_NETCONN: 1 -----*/
> +#define LWIP_NETCONN 1
> +/*----- Value in opt.h for LWIP_SOCKET: 1 -----*/
> +#define LWIP_SOCKET 1
> +/*----- Value in opt.h for RECV_BUFSIZE_DEFAULT: INT_MAX -----*/
> +#define RECV_BUFSIZE_DEFAULT 2000000000
> +/*----- Value in opt.h for LWIP_STATS: 1 -----*/
> +#define LWIP_STATS 0
> +/*----- Value in opt.h for CHECKSUM_GEN_IP: 1 -----*/
> +#define CHECKSUM_GEN_IP 0
> +/*----- Value in opt.h for CHECKSUM_GEN_UDP: 1 -----*/
> +#define CHECKSUM_GEN_UDP 0
> +/*----- Value in opt.h for CHECKSUM_GEN_TCP: 1 -----*/
> +#define CHECKSUM_GEN_TCP 0
> +/*----- Value in opt.h for CHECKSUM_GEN_ICMP: 1 -----*/
> +#define CHECKSUM_GEN_ICMP 0
> +/*----- Value in opt.h for CHECKSUM_GEN_ICMP6: 1 -----*/
> +#define CHECKSUM_GEN_ICMP6 0
> +/*----- Value in opt.h for CHECKSUM_CHECK_IP: 1 -----*/
> +#define CHECKSUM_CHECK_IP 0
> +/*----- Value in opt.h for CHECKSUM_CHECK_UDP: 1 -----*/
> +#define CHECKSUM_CHECK_UDP 0
> +/*----- Value in opt.h for CHECKSUM_CHECK_TCP: 1 -----*/
> +#define CHECKSUM_CHECK_TCP 0
> +/*----- Value in opt.h for CHECKSUM_CHECK_ICMP: 1 -----*/
> +#define CHECKSUM_CHECK_ICMP 0
> +/*----- Value in opt.h for CHECKSUM_CHECK_ICMP6: 1 -----*/
> +#define CHECKSUM_CHECK_ICMP6 0
> +/*----- Default Value for ETHARP_DEBUG: LWIP_DBG_OFF ---*/
> +/*-----------------------------------------------------------------------------*/
> +/* USER CODE BEGIN 1 */
> +//#define LWIP_DEBUG 1
> +#define LWIP_ARP 1
> +
> +#define LWIP_NETIF_API 1
> +
> +#define NO_SYS_NO_TIMERS 0
> +
> +#define IP_REASSEMBLY                   0
> +#define IP_FRAG                         0
> +#define LWIP_IPV4                       1
> +#define LWIP_IPV6                       1
> +
> +#define LWIP_TCPIP_CORE_LOCKING         1
> +
> +#define LWIP_DHCP                       1
> +#define DHCP_DOES_ARP_CHECK             0
> +
> +#define LWIP_DNS                        1
> +
> +#define LWIP_AUTOIP                     1
> +#define LWIP_DHCP_AUTOIP_COOP           ((LWIP_DHCP) && (LWIP_AUTOIP))
> +
> +#define LWIP_TIMEVAL_PRIVATE 0
> +#define LWIP_COMPAT_SOCKETS 1
> +#define LWIP_RAW 0
> +
> +#define SO_REUSE 1
> +
> +#define tskIDLE_PRIORITY RTEMS_MAXIMUM_PRIORITY
> +#define portTICK_RATE_MS ( rtems_clock_get_ticks_per_second() * 1000 )
> +#define vTaskDelay( x ) sys_arch_delay( x )
The preceeding three definitions don't appear to be used in the STM32 
code. They were specifically for the Xilinx embeddedsw code import used 
by ZynqMP.
> +/* USER CODE END 1 */
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +#endif /*__LWIPOPTS__H__ */
> diff --git a/rtemslwip/stm32f4/netstart.c b/rtemslwip/stm32f4/netstart.c
> new file mode 100644
> index 0000000..88e846a
> --- /dev/null
> +++ b/rtemslwip/stm32f4/netstart.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR)
> + * Written by Kinsey Moore <kinsey.moore at oarcorp.com>
Update this copyright information.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <netstart.h>
> +#include <lwip/tcpip.h>
> +#include <ethernetif.h>
> +
> +int start_networking(
> +  struct netif  *net_interface,
> +  ip_addr_t     *ipaddr,
> +  ip_addr_t     *netmask,
> +  ip_addr_t     *gateway,
> +  unsigned char *mac_ethernet_address
> +)
> +{
> +  tcpip_init( NULL, NULL );
> +
> +  netif_add(net_interface, ipaddr, netmask, gw, NULL, &ethernetif_init, &tcpip_input);
> +
> +  netif_set_default(net_interface);
> +
> +  if (netif_is_link_up(net_interface)) {
> +    netif_set_up(net_interface);
> +  } else {
> +    netif_set_down(net_interface);
> +  }
> +
> +  return 0;
> +}


More information about the devel mailing list