[PATCH rtems-lwip v2 0/7] lwIP port for STM32F4 BSP
This patch set aims to port RTEMS lwIP for STM32F4 BSP. It also contains generic drivers for STM32 chips in general. It is tested with a TCP echo server application on STM32F407 Discovery Board. Prerequisite: this patch set requires my STM32F4 patches to be applied because it uses STM32 HAL. v2: - Changes the arch and BSP check to use rtems.arch and rtems.bsp - Updates #4714: replace os.walk by ant_glob - Group STM32F4 BSP-specific files together Duc Doan (7): lwip.py: Change arch and bsp check method lwip.py: Use ant_glob instead of os.walk() Add STM32 Ethernet source rtemslwip: Add STM32F4 lwipopts.h and netstart.c RTEMS port of lwIP for STM32 and STM32F4 BSP lwip.py: Add STM32 lwIP port to build stm32: Convert to Unix line endings lwip.py | 66 ++- rtemslwip/stm32f4/lwipopts.h | 151 + rtemslwip/stm32f4/netstart.c | 75 +++ rtemslwip/stm32f4/stm32f4_lwip.c | 14 + rtemslwip/stm32f4/stm32f4_lwip.h | 9 + stm32/driver/dp83848.c | 664 + stm32/driver/dp83848.h | 436 ++ stm32/ethernetif.c | 989 +++ stm32/ethernetif.h | 53 ++ stm32/lwip.c | 207 +++ stm32/lwip.h | 78 +++ 11 files changed, 2718 insertions(+), 24 deletions(-) create mode 100644 rtemslwip/stm32f4/lwipopts.h create mode 100644 rtemslwip/stm32f4/netstart.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.h create mode 100644 stm32/driver/dp83848.c create mode 100644 stm32/driver/dp83848.h create mode 100644 stm32/ethernetif.c create mode 100644 stm32/ethernetif.h create mode 100644 stm32/lwip.c create mode 100644 stm32/lwip.h -- 2.37.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems-lwip v2 1/7] lwip.py: Change arch and bsp check method
--- lwip.py | 30 +- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lwip.py b/lwip.py index 84eef2c..9db5348 100644 --- a/lwip.py +++ b/lwip.py @@ -99,6 +99,8 @@ def build(bld): drv_incl = [] arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP) +arch = rtems.arch(bld.env.RTEMS_ARCH_BSP) +bsp = rtems.bsp(bld.env.RTEMS_ARCH_BSP) with open('file-import.json', 'r') as cf: files = json.load(cf) for f in files['files-to-import']: @@ -118,27 +120,29 @@ def build(bld): sources.append(os.path.join(path, name)) return sources -# These files will not compile for BSPs other than TMS570 -if bld.env.RTEMS_ARCH_BSP.startswith('arm-rtems6-tms570ls3137_hdk'): -drv_incl.append('uLan/ports/driver/tms570_emac') -drv_incl.append('uLan/ports/os') -driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) +if arch == 'arm': +# These files will not compile for BSPs other than TMS570 +if bsp.startswith('tms570ls3137_hdk'): +drv_incl.append('uLan/ports/driver/tms570_emac') +drv_incl.append('uLan/ports/os') +driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) + +# These files will only compile for BeagleBone BSPs +if bsp.startswith('beaglebone'): +driver_source.extend(walk_sources('rtemslwip/beaglebone')) +drv_incl.append('rtemslwip/beaglebone') +drv_incl.append('cpsw/src/include') +driver_source.extend(walk_sources('cpsw/src')) -# These files will only compile for BeagleBone BSPs -if bld.env.RTEMS_ARCH_BSP.startswith('arm-rtems6-beaglebone'): -driver_source.extend(walk_sources('rtemslwip/beaglebone')) -drv_incl.append('rtemslwip/beaglebone') -drv_incl.append('cpsw/src/include') -driver_source.extend(walk_sources('cpsw/src')) # These files will only compile for BSPs on Xilinx hardware is_xilinx_bsp = False is_aarch64_bsp = False is_qemu = False -if bld.env.RTEMS_ARCH_BSP.startswith('aarch64-rtems6-xilinx_zynqmp'): +if arch == 'aarch64' and bsp.startswith('xilinx_zynqmp'): is_xilinx_bsp = True is_aarch64_bsp = True -if bld.env.RTEMS_ARCH_BSP.endswith('_qemu'): +if bsp.endswith('_qemu'): is_qemu = True if is_xilinx_bsp: drv_incl.extend(xilinx_drv_incl) -- 2.37.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems-lwip v2 2/7] lwip.py: Use ant_glob instead of os.walk()
Updates #4714 --- lwip.py | 10 +- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lwip.py b/lwip.py index 9db5348..9425dc8 100644 --- a/lwip.py +++ b/lwip.py @@ -110,15 +110,7 @@ def build(bld): source_files.extend(common_source_files) def walk_sources(path): -sources = [] -for root, dirs, files in os.walk(path): -for name in files: -ext = os.path.splitext(name)[1] -src_root = os.path.split(root) -path = os.path.join(src_root[0], src_root[1]) -if ext == '.c' or ext == '.S': -sources.append(os.path.join(path, name)) -return sources +return bld.path.ant_glob([path + '/**/*.c', path + '/**/*.S']) if arch == 'arm': # These files will not compile for BSPs other than TMS570 -- 2.37.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems-lwip v2 3/7] Add STM32 Ethernet source
This patch adds ST's Ethernet and lwIP port and DP83848 driver. The files are generated using STM32CubeIDE with STM32F4 Cube FW v1.27.1, under no RTOS mode. --- stm32/driver/dp83848.c | 664 + stm32/driver/dp83848.h | 436 stm32/ethernetif.c | 737 + stm32/ethernetif.h | 45 +++ stm32/lwip.c | 260 +++ stm32/lwip.h | 76 + 6 files changed, 2218 insertions(+) create mode 100644 stm32/driver/dp83848.c create mode 100644 stm32/driver/dp83848.h create mode 100644 stm32/ethernetif.c create mode 100644 stm32/ethernetif.h create mode 100644 stm32/lwip.c create mode 100644 stm32/lwip.h diff --git a/stm32/driver/dp83848.c b/stm32/driver/dp83848.c new file mode 100644 index 000..2c5d59b --- /dev/null +++ b/stm32/driver/dp83848.c @@ -0,0 +1,664 @@ +/** + ** + * @filedp83848.c + * @author MCD Application Team + * @brief This file provides a set of functions needed to manage the DP83848 + * PHY devices. + ** + * @attention + * + * © Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + *opensource.org/licenses/BSD-3-Clause + * + ** + */ + +/* Includes --*/ +#include "dp83848.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup Component + * @{ + */ + +/** @defgroup DP83848 DP83848 + * @{ + */ + +/* Private typedef ---*/ +/* Private define */ +/** @defgroup DP83848_Private_Defines DP83848 Private Defines + * @{ + */ +#define DP83848_SW_RESET_TO((uint32_t)500U) +#define DP83848_INIT_TO((uint32_t)2000U) +#define DP83848_MAX_DEV_ADDR ((uint32_t)31U) +/** + * @} + */ + +/* Private macro -*/ +/* Private variables -*/ +/* Private function prototypes ---*/ +/* Private functions -*/ +/** @defgroup DP83848_Private_Functions DP83848 Private Functions + * @{ + */ + +/** + * @brief Register IO functions to component object + * @param pObj: device object of DP83848_Object_t. + * @param ioctx: holds device IO functions. + * @retval DP83848_STATUS_OK if OK + * DP83848_STATUS_ERROR if missing mandatory function + */ +int32_t DP83848_RegisterBusIO(dp83848_Object_t *pObj, dp83848_IOCtx_t *ioctx) +{ + if(!pObj || !ioctx->ReadReg || !ioctx->WriteReg || !ioctx->GetTick) + { +return DP83848_STATUS_ERROR; + } + + pObj->IO.Init = ioctx->Init; + pObj->IO.DeInit = ioctx->DeInit; + pObj->IO.ReadReg = ioctx->ReadReg; + pObj->IO.WriteReg = ioctx->WriteReg; + pObj->IO.GetTick = ioctx->GetTick; + + return DP83848_STATUS_OK; +} + +/** + * @brief Initialize the DP83848 and configure the needed hardware resources + * @param pObj: device object DP83848_Object_t. + * @retval DP83848_STATUS_OK if OK + * DP83848_STATUS_ADDRESS_ERROR if cannot find device address + * DP83848_STATUS_READ_ERROR if connot read register + * DP83848_STATUS_WRITE_ERROR if connot write to register + * DP83848_STATUS_RESET_TIMEOUT if cannot perform a software reset + */ + int32_t DP83848_Init(dp83848_Object_t *pObj) + { + uint32_t tickstart = 0, regvalue = 0, addr = 0; + int32_t status = DP83848_STATUS_OK; + + if(pObj->Is_Initialized == 0) + { + if(pObj->IO.Init != 0) + { + /* GPIO and Clocks initialization */ + pObj->IO.Init(); + } + + /* for later check */ + pObj->DevAddr = DP83848_MAX_DEV_ADDR + 1; + + /* Get the device address from special mode register */ + for(addr = 0; addr <= DP83848_MAX_DEV_ADDR; addr ++) + { + if(pObj->IO.ReadReg(addr, DP83848_SMR, ®value) < 0) + { + status = DP83848_STATUS_READ_ERROR; + /* Can't read from this device address +continue with next address */ + continue; + } + + if((regvalue & DP83848_SMR_PHY_ADDR) == addr) + { + pObj->DevAddr = addr; + status = DP83848_STATUS_OK; + break; + } + } + + if(pObj->DevAddr > DP83848_MAX_DEV_ADDR) + { + status = DP83848_STATUS_ADDRESS_ERROR; + } + + /* if device address is matched */ + i
[PATCH rtems-lwip v2 5/7] RTEMS port of lwIP for STM32 and STM32F4 BSP
--- rtemslwip/stm32f4/lwipopts.h | 24 ++- rtemslwip/stm32f4/netstart.c | 29 +++- rtemslwip/stm32f4/stm32f4_lwip.c | 14 ++ rtemslwip/stm32f4/stm32f4_lwip.h | 9 + stm32/ethernetif.c | 288 +-- stm32/ethernetif.h | 14 +- stm32/lwip.c | 103 +++ stm32/lwip.h | 2 + 8 files changed, 374 insertions(+), 109 deletions(-) create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.h diff --git a/rtemslwip/stm32f4/lwipopts.h b/rtemslwip/stm32f4/lwipopts.h index 49a19e4..41cc68f 100644 --- a/rtemslwip/stm32f4/lwipopts.h +++ b/rtemslwip/stm32f4/lwipopts.h @@ -28,7 +28,7 @@ /* Within 'USER CODE' section, code will be kept by default at each generation */ /* USER CODE BEGIN 0 */ - +#include /* USER CODE END 0 */ #ifdef __cplusplus @@ -38,7 +38,7 @@ /* 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 +#define WITH_RTOS 1 /*- CHECKSUM_BY_HARDWARE disabled -*/ #define CHECKSUM_BY_HARDWARE 0 /*-*/ @@ -50,11 +50,11 @@ /*- 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 +#define SYS_LIGHTWEIGHT_PROT 1 /*- Value in opt.h for MEM_ALIGNMENT: 1 -*/ #define MEM_ALIGNMENT 4 /*- Default Value for H7 devices: 0x30044000 -*/ -#define LWIP_RAM_HEAP_POINTER 0x20017f58 +//#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 -*/ @@ -70,13 +70,13 @@ /*- 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 +//#define LWIP_NETIF_LINK_CALLBACK 0 /*- 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 20 +//#define RECV_BUFSIZE_DEFAULT 20 /*- Value in opt.h for LWIP_STATS: 1 -*/ #define LWIP_STATS 0 /*- Value in opt.h for CHECKSUM_GEN_IP: 1 -*/ @@ -115,9 +115,19 @@ #define LWIP_IPV6 1 #define LWIP_TCPIP_CORE_LOCKING 1 +#define TCPIP_THREAD_STACKSIZE 1024 +#define TCPIP_THREAD_PRIO 24 +#define TCPIP_MBOX_SIZE 6 +#define SLIPIF_THREAD_STACKSIZE 1024 +#define SLIPIF_THREAD_PRIO 3 +#define DEFAULT_THREAD_STACKSIZE 1024 +#define DEFAULT_THREAD_PRIO 3 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 +#define DEFAULT_ACCEPTMBOX_SIZE 6 #define LWIP_DHCP 1 -#define DHCP_DOES_ARP_CHECK 0 +#define DHCP_DOES_ARP_CHECK 1 #define LWIP_DNS1 diff --git a/rtemslwip/stm32f4/netstart.c b/rtemslwip/stm32f4/netstart.c index 88e846a..6ddcc81 100644 --- a/rtemslwip/stm32f4/netstart.c +++ b/rtemslwip/stm32f4/netstart.c @@ -26,7 +26,10 @@ #include #include -#include +#include "lwip.h" +#include "lwip/init.h" +#include "lwip/netif.h" +#include "ethernetif.h" int start_networking( struct netif *net_interface, @@ -38,15 +41,35 @@ int start_networking( { tcpip_init( NULL, NULL ); - netif_add(net_interface, ipaddr, netmask, gw, NULL, ðernetif_init, &tcpip_input); + set_mac_addr(mac_ethernet_address); + + netif_add( +net_interface, +&ipaddr->u_addr.ip4, +&netmask->u_addr.ip4, +&gateway->u_addr.ip4, +NULL, +ethernetif_init, +tcpip_input + ); netif_set_default(net_interface); if (netif_is_link_up(net_interface)) { netif_set_up(net_interface); + +sys_thread_new( + "stm32f4_ethernet_link_thread", + ethernet_link_thread, + net_interface, + 1024, + DEFAULT_THREAD_PRIO +); + +return 0; } else { netif_set_down(net_interface); } - return 0; + return -1; } diff --git a/rtemslwip/stm32f4/stm32f4_lwip.c b/rtemslwip/stm32f4/stm32f4_lwip.c new file mode 100644 index 000..1f4f07e --- /dev/null +++ b/rtemslwip/stm32f4/stm32f4_lwip.c @@ -0,0 +1,14 @@ +#include "stm32f4_lwip.h" + +extern ETH_HandleTypeDef heth; + +__attribute__((weak)) void Error_Handler(void) { +__disable_irq(); +while (1) +{ +} +} + +void ETH_IRQHandler(void) { +HAL_ETH_IRQHandler(&heth); +} diff --git a/rtemslwip/stm32f4/stm32f4_lwip.h b/rtemslwip/stm32f4/stm32f4_lwip.h new file mode 100644 index 000..8a2b03a --- /dev/null ++
[PATCH rtems-lwip v2 6/7] lwip.py: Add STM32 lwIP port to build
--- lwip.py | 22 ++ 1 file changed, 22 insertions(+) diff --git a/lwip.py b/lwip.py index 9425dc8..bb382cd 100644 --- a/lwip.py +++ b/lwip.py @@ -92,6 +92,21 @@ common_source_files = [ 'rtemslwip/bsd_compat/rtems-kernel-program.c' ] +stm32_drv_incl = [ +'stm32', +'stm32/driver' +] + +stm32_drv_src = [ +'stm32/ethernetif.c', +'stm32/lwip.c', +'stm32/driver/dp83848.c' +] + +stm32_stm32f4_drv_incl = [ +'rtemslwip/stm32f4' +] + def build(bld): source_files = [] @@ -126,6 +141,13 @@ def build(bld): drv_incl.append('cpsw/src/include') driver_source.extend(walk_sources('cpsw/src')) +# These files will only compile for STM32F4 BSPs +if bsp == 'stm32f4': +driver_source.extend(walk_sources('rtemslwip/stm32f4')) +drv_incl.extend(stm32_drv_incl) +driver_source.extend(stm32_drv_src) +drv_incl.extend(stm32_stm32f4_drv_incl) + # These files will only compile for BSPs on Xilinx hardware is_xilinx_bsp = False -- 2.37.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH rtems-lwip v2 4/7] rtemslwip: Add STM32F4 lwipopts.h and netstart.c
--- 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 000..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 20 +/*- 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 -
Re: [PATCH rtems-lwip v2 1/7] lwip.py: Change arch and bsp check method
I'm not opposed to this change since it reduces repetition a bit, but was there a particular reason for it beyond that? Kinsey On 9/6/2022 11:20, Duc Doan wrote: --- lwip.py | 30 +- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lwip.py b/lwip.py index 84eef2c..9db5348 100644 --- a/lwip.py +++ b/lwip.py @@ -99,6 +99,8 @@ def build(bld): drv_incl = [] arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP) +arch = rtems.arch(bld.env.RTEMS_ARCH_BSP) +bsp = rtems.bsp(bld.env.RTEMS_ARCH_BSP) with open('file-import.json', 'r') as cf: files = json.load(cf) for f in files['files-to-import']: @@ -118,27 +120,29 @@ def build(bld): sources.append(os.path.join(path, name)) return sources -# These files will not compile for BSPs other than TMS570 -if bld.env.RTEMS_ARCH_BSP.startswith('arm-rtems6-tms570ls3137_hdk'): -drv_incl.append('uLan/ports/driver/tms570_emac') -drv_incl.append('uLan/ports/os') -driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) +if arch == 'arm': +# These files will not compile for BSPs other than TMS570 +if bsp.startswith('tms570ls3137_hdk'): +drv_incl.append('uLan/ports/driver/tms570_emac') +drv_incl.append('uLan/ports/os') +driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) + +# These files will only compile for BeagleBone BSPs +if bsp.startswith('beaglebone'): +driver_source.extend(walk_sources('rtemslwip/beaglebone')) +drv_incl.append('rtemslwip/beaglebone') +drv_incl.append('cpsw/src/include') +driver_source.extend(walk_sources('cpsw/src')) -# These files will only compile for BeagleBone BSPs -if bld.env.RTEMS_ARCH_BSP.startswith('arm-rtems6-beaglebone'): -driver_source.extend(walk_sources('rtemslwip/beaglebone')) -drv_incl.append('rtemslwip/beaglebone') -drv_incl.append('cpsw/src/include') -driver_source.extend(walk_sources('cpsw/src')) # These files will only compile for BSPs on Xilinx hardware is_xilinx_bsp = False is_aarch64_bsp = False is_qemu = False -if bld.env.RTEMS_ARCH_BSP.startswith('aarch64-rtems6-xilinx_zynqmp'): +if arch == 'aarch64' and bsp.startswith('xilinx_zynqmp'): is_xilinx_bsp = True is_aarch64_bsp = True -if bld.env.RTEMS_ARCH_BSP.endswith('_qemu'): +if bsp.endswith('_qemu'): is_qemu = True if is_xilinx_bsp: drv_incl.extend(xilinx_drv_incl) ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH rtems-lwip v2 3/7] Add STM32 Ethernet source
This should also add a ORIGIN.stm32 and a COPYING.stm32 to describe the imported sources. The information in the commit message you have here should suffice as the majority of the content of ORIGIN.stm32. Kinsey On 9/6/2022 11:20, Duc Doan wrote: This patch adds ST's Ethernet and lwIP port and DP83848 driver. The files are generated using STM32CubeIDE with STM32F4 Cube FW v1.27.1, under no RTOS mode. --- stm32/driver/dp83848.c | 664 + stm32/driver/dp83848.h | 436 stm32/ethernetif.c | 737 + stm32/ethernetif.h | 45 +++ stm32/lwip.c | 260 +++ stm32/lwip.h | 76 + 6 files changed, 2218 insertions(+) create mode 100644 stm32/driver/dp83848.c create mode 100644 stm32/driver/dp83848.h create mode 100644 stm32/ethernetif.c create mode 100644 stm32/ethernetif.h create mode 100644 stm32/lwip.c create mode 100644 stm32/lwip.h diff --git a/stm32/driver/dp83848.c b/stm32/driver/dp83848.c new file mode 100644 index 000..2c5d59b --- /dev/null +++ b/stm32/driver/dp83848.c @@ -0,0 +1,664 @@ +/** + ** + * @filedp83848.c + * @author MCD Application Team + * @brief This file provides a set of functions needed to manage the DP83848 + * PHY devices. + ** + * @attention + * + * © Copyright (c) 2021 STMicroelectronics. + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + *opensource.org/licenses/BSD-3-Clause + * + ** + */ + +/* Includes --*/ +#include "dp83848.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup Component + * @{ + */ + +/** @defgroup DP83848 DP83848 + * @{ + */ + +/* Private typedef ---*/ +/* Private define */ +/** @defgroup DP83848_Private_Defines DP83848 Private Defines + * @{ + */ +#define DP83848_SW_RESET_TO((uint32_t)500U) +#define DP83848_INIT_TO((uint32_t)2000U) +#define DP83848_MAX_DEV_ADDR ((uint32_t)31U) +/** + * @} + */ + +/* Private macro -*/ +/* Private variables -*/ +/* Private function prototypes ---*/ +/* Private functions -*/ +/** @defgroup DP83848_Private_Functions DP83848 Private Functions + * @{ + */ + +/** + * @brief Register IO functions to component object + * @param pObj: device object of DP83848_Object_t. + * @param ioctx: holds device IO functions. + * @retval DP83848_STATUS_OK if OK + * DP83848_STATUS_ERROR if missing mandatory function + */ +int32_t DP83848_RegisterBusIO(dp83848_Object_t *pObj, dp83848_IOCtx_t *ioctx) +{ + if(!pObj || !ioctx->ReadReg || !ioctx->WriteReg || !ioctx->GetTick) + { +return DP83848_STATUS_ERROR; + } + + pObj->IO.Init = ioctx->Init; + pObj->IO.DeInit = ioctx->DeInit; + pObj->IO.ReadReg = ioctx->ReadReg; + pObj->IO.WriteReg = ioctx->WriteReg; + pObj->IO.GetTick = ioctx->GetTick; + + return DP83848_STATUS_OK; +} + +/** + * @brief Initialize the DP83848 and configure the needed hardware resources + * @param pObj: device object DP83848_Object_t. + * @retval DP83848_STATUS_OK if OK + * DP83848_STATUS_ADDRESS_ERROR if cannot find device address + * DP83848_STATUS_READ_ERROR if connot read register + * DP83848_STATUS_WRITE_ERROR if connot write to register + * DP83848_STATUS_RESET_TIMEOUT if cannot perform a software reset + */ + int32_t DP83848_Init(dp83848_Object_t *pObj) + { + uint32_t tickstart = 0, regvalue = 0, addr = 0; + int32_t status = DP83848_STATUS_OK; + + if(pObj->Is_Initialized == 0) + { + if(pObj->IO.Init != 0) + { + /* GPIO and Clocks initialization */ + pObj->IO.Init(); + } + + /* for later check */ + pObj->DevAddr = DP83848_MAX_DEV_ADDR + 1; + + /* Get the device address from special mode register */ + for(addr = 0; addr <= DP83848_MAX_DEV_ADDR; addr ++) + { + if(pObj->IO.ReadReg(addr, DP83848_SMR, ®value) < 0) + { + status = DP83848_STATUS_READ_ERROR; + /* Can't read from this device address +continue with next address */ + continue; + } + + if((regvalue & DP83848_SMR_PHY_ADDR) == addr) + {
Re: [PATCH rtems-lwip v2 4/7] rtemslwip: Add STM32F4 lwipopts.h and netstart.c
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 000..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 20 +/*- 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 +/*- Defa
Re: [PATCH rtems-lwip v2 5/7] RTEMS port of lwIP for STM32 and STM32F4 BSP
I think you may have accidentally squashed the lwipopts.h and netstart.c changes into this commit instead of 4/7. Changes to imported code should follow the same rules as rtems-libbsd for easier updating. It looks like you did this in most places, but a few instances are called out below where you didn't. More comments inline below. On 9/6/2022 11:20, Duc Doan wrote: --- rtemslwip/stm32f4/lwipopts.h | 24 ++- rtemslwip/stm32f4/netstart.c | 29 +++- rtemslwip/stm32f4/stm32f4_lwip.c | 14 ++ rtemslwip/stm32f4/stm32f4_lwip.h | 9 + stm32/ethernetif.c | 288 +-- stm32/ethernetif.h | 14 +- stm32/lwip.c | 103 +++ stm32/lwip.h | 2 + 8 files changed, 374 insertions(+), 109 deletions(-) create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.h diff --git a/rtemslwip/stm32f4/lwipopts.h b/rtemslwip/stm32f4/lwipopts.h index 49a19e4..41cc68f 100644 --- a/rtemslwip/stm32f4/lwipopts.h +++ b/rtemslwip/stm32f4/lwipopts.h @@ -28,7 +28,7 @@ /* Within 'USER CODE' section, code will be kept by default at each generation */ /* USER CODE BEGIN 0 */ - +#include /* USER CODE END 0 */ #ifdef __cplusplus @@ -38,7 +38,7 @@ /* 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 +#define WITH_RTOS 1 /*- CHECKSUM_BY_HARDWARE disabled -*/ #define CHECKSUM_BY_HARDWARE 0 /*-*/ @@ -50,11 +50,11 @@ /*- 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 +#define SYS_LIGHTWEIGHT_PROT 1 /*- Value in opt.h for MEM_ALIGNMENT: 1 -*/ #define MEM_ALIGNMENT 4 /*- Default Value for H7 devices: 0x30044000 -*/ -#define LWIP_RAM_HEAP_POINTER 0x20017f58 +//#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 -*/ @@ -70,13 +70,13 @@ /*- 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 +//#define LWIP_NETIF_LINK_CALLBACK 0 /*- 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 20 +//#define RECV_BUFSIZE_DEFAULT 20 /*- Value in opt.h for LWIP_STATS: 1 -*/ #define LWIP_STATS 0 /*- Value in opt.h for CHECKSUM_GEN_IP: 1 -*/ @@ -115,9 +115,19 @@ #define LWIP_IPV6 1 #define LWIP_TCPIP_CORE_LOCKING 1 +#define TCPIP_THREAD_STACKSIZE 1024 +#define TCPIP_THREAD_PRIO 24 +#define TCPIP_MBOX_SIZE 6 +#define SLIPIF_THREAD_STACKSIZE 1024 +#define SLIPIF_THREAD_PRIO 3 +#define DEFAULT_THREAD_STACKSIZE 1024 +#define DEFAULT_THREAD_PRIO 3 +#define DEFAULT_UDP_RECVMBOX_SIZE 6 +#define DEFAULT_TCP_RECVMBOX_SIZE 6 +#define DEFAULT_ACCEPTMBOX_SIZE 6 #define LWIP_DHCP 1 -#define DHCP_DOES_ARP_CHECK 0 +#define DHCP_DOES_ARP_CHECK 1 #define LWIP_DNS1 diff --git a/rtemslwip/stm32f4/netstart.c b/rtemslwip/stm32f4/netstart.c index 88e846a..6ddcc81 100644 --- a/rtemslwip/stm32f4/netstart.c +++ b/rtemslwip/stm32f4/netstart.c @@ -26,7 +26,10 @@ #include #include -#include +#include "lwip.h" +#include "lwip/init.h" +#include "lwip/netif.h" +#include "ethernetif.h" int start_networking( struct netif *net_interface, @@ -38,15 +41,35 @@ int start_networking( { tcpip_init( NULL, NULL ); - netif_add(net_interface, ipaddr, netmask, gw, NULL, ðernetif_init, &tcpip_input); + set_mac_addr(mac_ethernet_address); + + netif_add( +net_interface, +&ipaddr->u_addr.ip4, +&netmask->u_addr.ip4, +&gateway->u_addr.ip4, +NULL, +ethernetif_init, +tcpip_input + ); netif_set_default(net_interface); if (netif_is_link_up(net_interface)) { netif_set_up(net_interface); + +sys_thread_new( + "stm32f4_ethernet_link_thread", + ethernet_link_thread, + net_interface, + 1024, + DEFAULT_THREAD_PRIO +); + +return 0; } else { netif_set_down(net_interface); } - return 0; + return -1; } diff --git a/rtemslwip/stm32f4/stm32f4_lwip.c b/rtemslwip/stm32f4/stm32f4_lwip.c new file mode 100644 index 000..1f4f07e --- /
Re: [PATCH rtems-lwip v2 1/7] lwip.py: Change arch and bsp check method
On 7/9/2022 4:41 am, Kinsey Moore wrote: I'm not opposed to this change since it reduces repetition a bit, but was there a particular reason for it beyond that? Yes there is. The arch/bsp checks ... - if bld.env.RTEMS_ARCH_BSP.startswith('arm-rtems6-tms570ls3137_hdk'): ... included the major version of RTEMS which breaks once we move to 7, 8 And I have left `RTEMS_ARCH_BSP` in the environment but it is really an internal working variable of rtems_waf. - drv_incl.append('uLan/ports/driver/tms570_emac') - drv_incl.append('uLan/ports/os') - driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) + if arch == 'arm': + # These files will not compile for BSPs other than TMS570 + if bsp.startswith('tms570ls3137_hdk'): Duc, please make the check exact. A BSP name should be a one to match and if you have to match more than one I suggest you use: if bsp in ['tms570ls3137_hdk', 'tms570ls3137_hdk.extra']: Chris ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel