Re: [PATCH rtems-lwip v3 5/7] RTEMS port of lwIP for STM32 and STM32F4 BSP
There are a few places noted below where the code import rules aren't being followed. On 9/8/2022 11:34, Duc Doan wrote: --- rtemslwip/stm32f4/stm32f4_lwip.c | 14 rtemslwip/stm32f4/stm32f4_lwip.h | 9 +++ stm32/ethernetif.c | 110 ++- stm32/ethernetif.h | 8 ++- stm32/lwip.h | 2 + 5 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.h 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 +++ 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 + +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 7a82c51..e71ac8f 100644 --- a/stm32/ethernetif.c +++ b/stm32/ethernetif.c @@ -19,7 +19,12 @@ /* USER CODE END Header */ /* Includes --*/ +#ifndef __rtems__ #include "main.h" +#else +#include +#include +#endif /* __rtems__ */ #include "lwip/opt.h" #include "lwip/timeouts.h" #include "netif/ethernet.h" @@ -28,7 +33,9 @@ #include "ethernetif.h" #include "dp83848.h" #include +#ifndef __rtems__ #include "cmsis_os.h" +#endif /* __rtems__ */ #include "lwip/tcpip.h" /* Within 'USER CODE' section, code will be kept by default at each generation */ @@ -38,7 +45,12 @@ /* Private define */ /* The time to block waiting for input. */ +#ifndef __rtems__ #define TIME_WAITING_FOR_INPUT ( portMAX_DELAY ) +#else +#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 ) @@ -109,12 +121,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); @@ -144,7 +164,11 @@ void pbuf_free_custom(struct pbuf *p); */ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *handlerEth) { +#ifndef __rtems__ osSemaphoreRelease(RxPktSemaphore); +#else + rtems_semaphore_release(RxPktSemaphore); +#endif /* __rtems__ */ } /** * @brief Ethernet Tx Transfer completed callback @@ -153,7 +177,11 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *handlerEth) */ void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *handlerEth) { +#ifndef __rtems__ osSemaphoreRelease(TxPktSemaphore); +#else + rtems_semaphore_release(TxPktSemaphore); +#endif /* __rtems__ */ } /** * @brief Ethernet DMA transfer error callback @@ -164,12 +192,21 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *handlerEth) { if((HAL_ETH_GetDMAError(handlerEth) & ETH_DMASR_RBUS) == ETH_DMASR_RBUS) { - osSemaphoreRelease(RxPktSemaphore); It looks like this was just an accidental spacing issue. +#ifndef __rtems__ +osSemaphoreRelease(RxPktSemaphore); +#else +rtems_semaphore_release(RxPktSemaphore); +#endif /* __rtems__ */ } } /* USER CODE BEGIN 4 */ - Removed newline. +#ifdef __rtems__ +void set_mac_addr(uint8_t *mac_addr) +{ + MACAddr = mac_addr; +} +#endif /* __rtems__ */ /* USER CODE END 4 */ /*** @@ -186,15 +223,20 @@ 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_
[PATCH rtems-lwip v3 5/7] RTEMS port of lwIP for STM32 and STM32F4 BSP
--- rtemslwip/stm32f4/stm32f4_lwip.c | 14 rtemslwip/stm32f4/stm32f4_lwip.h | 9 +++ stm32/ethernetif.c | 110 ++- stm32/ethernetif.h | 8 ++- stm32/lwip.h | 2 + 5 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.c create mode 100644 rtemslwip/stm32f4/stm32f4_lwip.h 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 +++ 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 + +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 7a82c51..e71ac8f 100644 --- a/stm32/ethernetif.c +++ b/stm32/ethernetif.c @@ -19,7 +19,12 @@ /* USER CODE END Header */ /* Includes --*/ +#ifndef __rtems__ #include "main.h" +#else +#include +#include +#endif /* __rtems__ */ #include "lwip/opt.h" #include "lwip/timeouts.h" #include "netif/ethernet.h" @@ -28,7 +33,9 @@ #include "ethernetif.h" #include "dp83848.h" #include +#ifndef __rtems__ #include "cmsis_os.h" +#endif /* __rtems__ */ #include "lwip/tcpip.h" /* Within 'USER CODE' section, code will be kept by default at each generation */ @@ -38,7 +45,12 @@ /* Private define */ /* The time to block waiting for input. */ +#ifndef __rtems__ #define TIME_WAITING_FOR_INPUT ( portMAX_DELAY ) +#else +#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 ) @@ -109,12 +121,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); @@ -144,7 +164,11 @@ void pbuf_free_custom(struct pbuf *p); */ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *handlerEth) { +#ifndef __rtems__ osSemaphoreRelease(RxPktSemaphore); +#else + rtems_semaphore_release(RxPktSemaphore); +#endif /* __rtems__ */ } /** * @brief Ethernet Tx Transfer completed callback @@ -153,7 +177,11 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *handlerEth) */ void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *handlerEth) { +#ifndef __rtems__ osSemaphoreRelease(TxPktSemaphore); +#else + rtems_semaphore_release(TxPktSemaphore); +#endif /* __rtems__ */ } /** * @brief Ethernet DMA transfer error callback @@ -164,12 +192,21 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *handlerEth) { if((HAL_ETH_GetDMAError(handlerEth) & ETH_DMASR_RBUS) == ETH_DMASR_RBUS) { - osSemaphoreRelease(RxPktSemaphore); +#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 */ /*** @@ -186,15 +223,20 @@ 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; MACAd