[PATCH rtems-lwip v2 5/7] RTEMS port of lwIP for STM32 and STM32F4 BSP

Kinsey Moore kinsey.moore at oarcorp.com
Tue Sep 6 19:30:05 UTC 2022


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 <stm32f4xx_hal.h>
>   /* 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 2000000000
> +//#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 -----*/
> @@ -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_DNS                        1
>   
> 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 <netstart.h>
>   #include <lwip/tcpip.h>
> -#include <ethernetif.h>
> +#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, &ethernetif_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 0000000..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 0000000..8a2b03a
> --- /dev/null
> +++ b/rtemslwip/stm32f4/stm32f4_lwip.h
> @@ -0,0 +1,9 @@
> +#ifndef LIPLWIP_RTEMSLWIP_STM32F4_STM32F4_LWIP_H
> +#define LIPLWIP_RTEMSLWIP_STM32F4_STM32F4_LWIP_H
> +
> +#include <stm32f4xx_hal.h>
> +
> +void ErrorHandler(void);
> +void ETH_IRQHandler(void);
> +
> +#endif /* LIPLWIP_RTEMSLWIP_STM32F4_STM32F4_LWIP_H */
> diff --git a/stm32/ethernetif.c b/stm32/ethernetif.c
> index e54c8b6..a8e9f76 100644
> --- a/stm32/ethernetif.c
> +++ b/stm32/ethernetif.c
> @@ -19,10 +19,14 @@
>   /* USER CODE END Header */
>   
>   /* Includes ------------------------------------------------------------------*/
> +#ifndef __rtems__
>   #include "main.h"
> +#endif /* __rtems__ */
> +#ifdef __rtems__
The preceeding two lines can be condensed into a #else, applies elsewhere.
> +#include <bsp.h>
> +#include <bsp/irq.h>
> +#endif /* __rtems__ */
>   #include "lwip/opt.h"
> -#include "lwip/mem.h"
> -#include "lwip/memp.h"
Bad removal, applies elsewhere.
>   #include "lwip/timeouts.h"
>   #include "netif/ethernet.h"
>   #include "netif/etharp.h"
> @@ -30,6 +34,10 @@
>   #include "ethernetif.h"
>   #include "dp83848.h"
>   #include <string.h>
> +#ifndef __rtems__
> +#include "cmsis_os.h"
> +#endif /* __rtems__ */
> +#include "lwip/tcpip.h"
Bad addition, applies elsewhere.
>   
>   /* Within 'USER CODE' section, code will be kept by default at each generation */
>   /* USER CODE BEGIN 0 */
> @@ -37,7 +45,18 @@
>   /* USER CODE END 0 */
>   
>   /* Private define ------------------------------------------------------------*/
> -
> +/* The time to block waiting for input. */
> +#ifndef __rtems__
> +#define TIME_WAITING_FOR_INPUT ( portMAX_DELAY )
> +#endif /* __rtems__ */
> +#ifdef __rtems__
> +#define TIME_WAITING_FOR_INPUT ( RTEMS_NO_TIMEOUT )
> +#endif /* __rtems__ */
> +
> +/* USER CODE BEGIN OS_THREAD_STACK_SIZE_WITH_RTOS */
> +/* Stack size of the interface thread */
> +#define INTERFACE_THREAD_STACK_SIZE ( 350 )
> +/* USER CODE END OS_THREAD_STACK_SIZE_WITH_RTOS */
>   /* Network interface name */
>   #define IFNAME0 's'
>   #define IFNAME1 't'
> @@ -104,9 +123,20 @@ ETH_DMADescTypeDef  DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptor
>   
>   /* USER CODE END 2 */
>   
> +#ifndef __rtems__
> +osSemaphoreId RxPktSemaphore = NULL;   /* Semaphore to signal incoming packets */
> +osSemaphoreId TxPktSemaphore = NULL;   /* Semaphore to signal transmit packet complete */
> +#else
> +rtems_id RxPktSemaphore;   /* Semaphore to signal incoming packets */
> +rtems_id TxPktSemaphore;   /* Semaphore to signal transmit packet complete */
> +#endif /* __rtems__ */
> +
>   /* Global Ethernet handle */
>   ETH_HandleTypeDef heth;
>   ETH_TxPacketConfig TxConfig;
> +#ifdef __rtems__
> +static uint8_t *MACAddr;
> +#endif /* __rtems__ */
>   
>   /* Private function prototypes -----------------------------------------------*/
>   int32_t ETH_PHY_IO_Init(void);
> @@ -129,8 +159,56 @@ dp83848_IOCtx_t  DP83848_IOCtx = {ETH_PHY_IO_Init,
>   /* Private functions ---------------------------------------------------------*/
>   void pbuf_free_custom(struct pbuf *p);
>   
> -/* USER CODE BEGIN 4 */
> +/**
> +  * @brief  Ethernet Rx Transfer completed callback
> +  * @param  handlerEth: ETH handler
> +  * @retval None
> +  */
> +void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *handlerEth)
> +{
> +#ifndef __rtems__
> +  osSemaphoreRelease(RxPktSemaphore);
> +#else
> +  rtems_semaphore_release(RxPktSemaphore);
> +#endif /* __rtems__ */
> +}
> +/**
> +  * @brief  Ethernet Tx Transfer completed callback
> +  * @param  handlerEth: ETH handler
> +  * @retval None
> +  */
> +void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *handlerEth)
> +{
> +#ifndef __rtems__
> +  osSemaphoreRelease(TxPktSemaphore);
> +#else
> +  rtems_semaphore_release(TxPktSemaphore);
> +#endif /* __rtems__ */
> +}
> +/**
> +  * @brief  Ethernet DMA transfer error callback
> +  * @param  handlerEth: ETH handler
> +  * @retval None
> +  */
> +void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *handlerEth)
> +{
> +  if((HAL_ETH_GetDMAError(handlerEth) & ETH_DMASR_RBUS) == ETH_DMASR_RBUS)
> +  {
> +#ifndef __rtems__
> +    osSemaphoreRelease(RxPktSemaphore);
> +#else
> +    rtems_semaphore_release(RxPktSemaphore);
> +#endif /* __rtems__ */
> +  }
> +}
>   
> +/* USER CODE BEGIN 4 */
> +#ifdef __rtems__
> +void set_mac_addr(uint8_t *mac_addr)
> +{
> +  MACAddr = mac_addr;
> +}
> +#endif /* __rtems__ */
>   /* USER CODE END 4 */
>   
>   /*******************************************************************************
> @@ -146,17 +224,33 @@ void pbuf_free_custom(struct pbuf *p);
>   static void low_level_init(struct netif *netif)
>   {
>     HAL_StatusTypeDef hal_eth_init_status = HAL_OK;
> +/* USER CODE BEGIN OS_THREAD_ATTR_CMSIS_RTOS_V2 */
> +#ifndef __rtems__
> +  osThreadAttr_t attributes;
> +#endif /* __rtems__ */
> +/* USER CODE END OS_THREAD_ATTR_CMSIS_RTOS_V2 */
> +  uint32_t duplex, speed = 0;
> +  int32_t PHYLinkState = 0;
> +  ETH_MACConfigTypeDef MACConf = {0};
>     /* Start ETH HAL Init */
>   
> +#ifndef __rtems__
>      uint8_t MACAddr[6] ;
> +#endif /* __rtems__ */
>     heth.Instance = ETH;
> +#ifndef __rtems__
>     MACAddr[0] = 0x02;
>     MACAddr[1] = 0x00;
>     MACAddr[2] = 0x00;
>     MACAddr[3] = 0x00;
>     MACAddr[4] = 0x00;
>     MACAddr[5] = 0x01;
> +#endif /* __rtems__ */
> +#ifndef __rtems__
>     heth.Init.MACAddr = &MACAddr[0];
> +#else
> +  heth.Init.MACAddr = MACAddr;
> +#endif /* __rtems__ */
>     heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
>     heth.Init.TxDesc = DMATxDscrTab;
>     heth.Init.RxDesc = DMARxDscrTab;
> @@ -202,6 +296,51 @@ static void low_level_init(struct netif *netif)
>       netif->flags |= NETIF_FLAG_BROADCAST;
>     #endif /* LWIP_ARP */
>   
> +  /* create a binary semaphore used for informing ethernetif of frame reception */
> +#ifndef __rtems__
> +  RxPktSemaphore = osSemaphoreNew(1, 1, NULL);
> +#else
> +  rtems_semaphore_create(
> +    rtems_build_name('R', 'x', 'p', 'k'),
> +    1,
> +    RTEMS_SIMPLE_BINARY_SEMAPHORE,
> +    0,
> +    &RxPktSemaphore
> +  );
> +#endif /* __rtems__ */
> +
> +  /* create a binary semaphore used for informing ethernetif of frame transmission */
> +#ifndef __rtems__
> +  TxPktSemaphore = osSemaphoreNew(1, 1, NULL);
> +#else
> +  rtems_semaphore_create(
> +    rtems_build_name('T', 'x', 'p', 'k'),
> +    1,
> +    RTEMS_SIMPLE_BINARY_SEMAPHORE,
> +    0,
> +    &TxPktSemaphore
> +  );
> +#endif /* __rtems__ */
> +
> +  /* create the task that handles the ETH_MAC */
> +/* USER CODE BEGIN OS_THREAD_NEW_CMSIS_RTOS_V2 */
> +#ifndef __rtems__
> +  memset(&attributes, 0x0, sizeof(osThreadAttr_t));
> +  attributes.name = "EthIf";
> +  attributes.stack_size = INTERFACE_THREAD_STACK_SIZE;
> +  attributes.priority = osPriorityRealtime;
> +  osThreadNew(ethernetif_input, netif, &attributes);
> +#else
> +  sys_thread_new(
> +    "ethernetif_input_thread",
> +    ethernetif_input,
> +    netif,
> +    RTEMS_MINIMUM_STACK_SIZE,
> +    DEFAULT_THREAD_PRIO
> +  );
> +#endif /* __rtem__ */
> +/* USER CODE END OS_THREAD_NEW_CMSIS_RTOS_V2 */
> +
>   /* USER CODE BEGIN PHY_PRE_CONFIG */
>   
>   /* USER CODE END PHY_PRE_CONFIG */
> @@ -213,8 +352,64 @@ static void low_level_init(struct netif *netif)
>   
>     if (hal_eth_init_status == HAL_OK)
>     {
> -  /* Get link state */
> -  ethernet_link_check_state(netif);
> +    PHYLinkState = DP83848_GetLinkState(&DP83848);
> +
> +    /* Get link state */
> +    if(PHYLinkState <= DP83848_STATUS_LINK_DOWN)
> +    {
> +      netif_set_link_down(netif);
> +      netif_set_down(netif);
> +    }
> +    else
> +    {
> +      switch (PHYLinkState)
> +      {
> +      case DP83848_STATUS_100MBITS_FULLDUPLEX:
> +        duplex = ETH_FULLDUPLEX_MODE;
> +        speed = ETH_SPEED_100M;
> +        break;
> +      case DP83848_STATUS_100MBITS_HALFDUPLEX:
> +        duplex = ETH_HALFDUPLEX_MODE;
> +        speed = ETH_SPEED_100M;
> +        break;
> +      case DP83848_STATUS_10MBITS_FULLDUPLEX:
> +        duplex = ETH_FULLDUPLEX_MODE;
> +        speed = ETH_SPEED_10M;
> +        break;
> +      case DP83848_STATUS_10MBITS_HALFDUPLEX:
> +        duplex = ETH_HALFDUPLEX_MODE;
> +        speed = ETH_SPEED_10M;
> +        break;
> +      default:
> +        duplex = ETH_FULLDUPLEX_MODE;
> +        speed = ETH_SPEED_100M;
> +        break;
> +      }
> +
> +    /* Get MAC Config MAC */
> +    HAL_ETH_GetMACConfig(&heth, &MACConf);
> +    MACConf.DuplexMode = duplex;
> +    MACConf.Speed = speed;
> +    HAL_ETH_SetMACConfig(&heth, &MACConf);
> +
> +#ifdef __rtems__
> +    rtems_interrupt_handler_install(
> +            STM32F4_IRQ_ETH,
> +            NULL,
> +            RTEMS_INTERRUPT_UNIQUE,
> +            HAL_ETH_IRQHandler,
> +            &heth
> +    );
> +#endif /* __rtems__ */
> +    HAL_ETH_Start_IT(&heth);
> +    netif_set_up(netif);
> +    netif_set_link_up(netif);
> +
> +/* USER CODE BEGIN PHY_POST_CONFIG */
> +
> +/* USER CODE END PHY_POST_CONFIG */
> +    }
> +
>     }
>     else
>     {
> @@ -277,7 +472,20 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
>     TxConfig.TxBuffer = Txbuffer;
>     TxConfig.pData = p;
>   
> -  HAL_ETH_Transmit(&heth, &TxConfig, ETH_DMA_TRANSMIT_TIMEOUT);
> +  pbuf_ref(p);
> +
> +  HAL_ETH_Transmit_IT(&heth, &TxConfig);
> +#ifndef __rtems__
> +  while(osSemaphoreAcquire(TxPktSemaphore, TIME_WAITING_FOR_INPUT)!=osOK)
> +#else
> +  while (rtems_semaphore_obtain(TxPktSemaphore, RTEMS_DEFAULT_OPTIONS,
> +          TIME_WAITING_FOR_INPUT) != RTEMS_SUCCESSFUL)
> +#endif /* __rtems__ */
> +
> +  {
> +  }
> +
> +  HAL_ETH_ReleaseTxPacket(&heth);
>   
>     return errval;
>   }
> @@ -311,21 +519,33 @@ static struct pbuf * low_level_input(struct netif *netif)
>    *
>    * @param netif the lwip network interface structure for this ethernetif
>    */
> -void ethernetif_input(struct netif *netif)
> +void ethernetif_input(void* argument)
>   {
>     struct pbuf *p = NULL;
> +  struct netif *netif = (struct netif *) argument;
>   
> -  do
> +  for( ;; )
>     {
> -    p = low_level_input( netif );
> -    if (p != NULL)
> +#ifndef __rtems__
> +    if (osSemaphoreAcquire(RxPktSemaphore, TIME_WAITING_FOR_INPUT) == osOK)
> +#else
> +    if (rtems_semaphore_obtain(RxPktSemaphore, RTEMS_DEFAULT_OPTIONS,
> +            TIME_WAITING_FOR_INPUT) == RTEMS_SUCCESSFUL)
> +#endif /* __rtems__ */
>       {
> -      if (netif->input( p, netif) != ERR_OK )
> +      do
>         {
> -        pbuf_free(p);
> -      }
> +        p = low_level_input( netif );
> +        if (p != NULL)
> +        {
> +          if (netif->input( p, netif) != ERR_OK )
> +          {
> +            pbuf_free(p);
> +          }
> +        }
> +      } while(p!=NULL);
>       }
> -  } while(p!=NULL);
> +  }
>   }
>   
>   #if !LWIP_ARP
> @@ -423,12 +643,17 @@ void pbuf_free_custom(struct pbuf *p)
>     if (RxAllocStatus == RX_ALLOC_ERROR)
>     {
>       RxAllocStatus = RX_ALLOC_OK;
> -    RxPkt = 1 ;
> +#ifndef __rtems__
> +    osSemaphoreRelease(RxPktSemaphore);
> +#else
> +    rtems_semaphore_release(RxPktSemaphore);
> +#endif /* __rtems__ */
>     }
>   }
>   
>   /* USER CODE BEGIN 6 */
>   
> +#ifndef __rtems__
>   /**
>   * @brief  Returns the current time in milliseconds
>   *         when LWIP_TIMERS == 1 and NO_SYS == 1
> @@ -439,6 +664,7 @@ u32_t sys_now(void)
>   {
>     return HAL_GetTick();
>   }
> +#endif /* __rtems__ */
>   
>   /* USER CODE END 6 */
>   
> @@ -488,6 +714,11 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle)
>       GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
>       HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
>   
> +    /* Peripheral interrupt init */
> +#ifndef __rtems__
> +    HAL_NVIC_SetPriority(ETH_IRQn, 5, 0);
> +    HAL_NVIC_EnableIRQ(ETH_IRQn);
> +#endif /* __rtems__ */
>     /* USER CODE BEGIN ETH_MspInit 1 */
>   
>     /* USER CODE END ETH_MspInit 1 */
> @@ -521,6 +752,9 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef* ethHandle)
>   
>       HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13);
>   
> +    /* Peripheral interrupt Deinit*/
> +    HAL_NVIC_DisableIRQ(ETH_IRQn);
> +
>     /* USER CODE BEGIN ETH_MspDeInit 1 */
>   
>     /* USER CODE END ETH_MspDeInit 1 */
> @@ -605,17 +839,24 @@ int32_t ETH_PHY_IO_GetTick(void)
>     * @param  argument: netif
>     * @retval None
>     */
> -void ethernet_link_check_state(struct netif *netif)
> +void ethernet_link_thread(void* argument)
>   {
>     ETH_MACConfigTypeDef MACConf = {0};
>     int32_t PHYLinkState = 0;
>     uint32_t linkchanged = 0U, speed = 0U, duplex = 0U;
>   
> +  struct netif *netif = (struct netif *) argument;
> +/* USER CODE BEGIN ETH link init */
> +
> +/* USER CODE END ETH link init */
> +
> +  for(;;)
> +  {
>     PHYLinkState = DP83848_GetLinkState(&DP83848);
>   
>     if(netif_is_link_up(netif) && (PHYLinkState <= DP83848_STATUS_LINK_DOWN))
>     {
> -    HAL_ETH_Stop(&heth);
> +    HAL_ETH_Stop_IT(&heth);
>       netif_set_down(netif);
>       netif_set_link_down(netif);
>     }
> @@ -660,6 +901,16 @@ void ethernet_link_check_state(struct netif *netif)
>       }
>     }
>   
> +/* USER CODE BEGIN ETH link Thread core code for User BSP */
> +
> +/* USER CODE END ETH link Thread core code for User BSP */
> +
> +#ifndef __rtems__
> +    osDelay(100);
> +#else
> +    sys_arch_delay(100);
> +#endif /* __rtems__ */
> +  }
>   }
>   
>   void HAL_ETH_RxAllocateCallback(uint8_t **buff)
> @@ -735,3 +986,4 @@ void HAL_ETH_TxFreeCallback(uint32_t * buff)
>   
>   /* USER CODE END 8 */
>   
> +
> diff --git a/stm32/ethernetif.h b/stm32/ethernetif.h
> index 76eb91b..552671a 100644
> --- a/stm32/ethernetif.h
> +++ b/stm32/ethernetif.h
> @@ -23,23 +23,31 @@
>   
>   #include "lwip/err.h"
>   #include "lwip/netif.h"
> +#ifndef __rtems__
> +#include "cmsis_os.h"
> +#endif /* __rtems__ */
>   
>   /* Within 'USER CODE' section, code will be kept by default at each generation */
>   /* USER CODE BEGIN 0 */
> -
> +#ifdef __rtems__
> +void set_mac_addr(uint8_t *mac_addr);
> +#endif /* __rtems__ */
>   /* USER CODE END 0 */
>   
>   /* Exported functions ------------------------------------------------------- */
>   err_t ethernetif_init(struct netif *netif);
>   
> -void ethernetif_input(struct netif *netif);
> -void ethernet_link_check_state(struct netif *netif);
> +void ethernetif_input(void* argument);
> +void ethernet_link_thread(void* argument );
Why is the signature of this function being changed? The implementation 
is altered to blindly cast to this type, as well.
>   
>   void Error_Handler(void);
>   u32_t sys_jiffies(void);
> +#ifndef __rtems__
>   u32_t sys_now(void);
> +#endif /* __rtems__ */
>   
>   /* USER CODE BEGIN 1 */
>   
>   /* USER CODE END 1 */
>   #endif
> +
> diff --git a/stm32/lwip.c b/stm32/lwip.c
> index 9b2af8a..82a09fe 100644
> --- a/stm32/lwip.c
> +++ b/stm32/lwip.c
> @@ -19,6 +19,7 @@
>   /* USER CODE END Header */
>   
>   /* Includes ------------------------------------------------------------------*/
> +#ifndef __rtems__
>   #include "lwip.h"
>   #include "lwip/init.h"
>   #include "lwip/netif.h"
> @@ -26,29 +27,29 @@
>   #include "lwip/sio.h"
>   #endif /* MDK ARM Compiler */
>   #include "ethernetif.h"
> +#include <string.h>
>   
>   /* USER CODE BEGIN 0 */
>   
>   /* USER CODE END 0 */
>   /* Private function prototypes -----------------------------------------------*/
>   static void ethernet_link_status_updated(struct netif *netif);
> -static void Ethernet_Link_Periodic_Handle(struct netif *netif);
>   /* ETH Variables initialization ----------------------------------------------*/
>   void Error_Handler(void);
>   
>   /* USER CODE BEGIN 1 */
>   
>   /* USER CODE END 1 */
> -uint32_t EthernetLinkTimer;
>   
>   /* Variables Initialization */
>   struct netif gnetif;
>   ip4_addr_t ipaddr;
>   ip4_addr_t netmask;
>   ip4_addr_t gw;
> -uint8_t IP_ADDRESS[4];
> -uint8_t NETMASK_ADDRESS[4];
> -uint8_t GATEWAY_ADDRESS[4];
> +/* USER CODE BEGIN OS_THREAD_ATTR_CMSIS_RTOS_V2 */
> +#define INTERFACE_THREAD_STACK_SIZE ( 1024 )
> +osThreadAttr_t attributes;
> +/* USER CODE END OS_THREAD_ATTR_CMSIS_RTOS_V2 */
>   
>   /* USER CODE BEGIN 2 */
>   
> @@ -59,33 +60,16 @@ uint8_t GATEWAY_ADDRESS[4];
>     */
>   void MX_LWIP_Init(void)
You've made a bunch of changes to this function, but it's prototype has 
been #if'd out of the header. Is this file or the associated header even 
necessary?

Kinsey



More information about the devel mailing list