From a7102ab2dc541b05e9a8863656a56e1a9fdd71de Mon Sep 17 00:00:00 2001 From: murmur Date: Fri, 28 Apr 2023 11:39:00 +0800 Subject: [PATCH] =?UTF-8?q?add=20eth=20--//242.16=20KB=20/51556-64564-7086?= =?UTF-8?q?8=20add=20ETH=20=E6=97=A0ifconfig=20=E6=97=A0ping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 12 +++--- drivers/board.c | 75 ++++++++++++++++++++++++++++++++++++ drivers/board.h | 12 +++++- drivers/stm32f4xx_hal_conf.h | 2 +- rtconfig.h | 35 +++++++++++++++++ 5 files changed, 128 insertions(+), 8 deletions(-) diff --git a/applications/main.c b/applications/main.c index 36070bb..f8be1ef 100644 --- a/applications/main.c +++ b/applications/main.c @@ -15,11 +15,13 @@ #include #include -#define LED_HEART GET_PIN(E,3) -#define ETH_RESET_PIN GET_PIN(E, 7)//71 -//#define RESET_LB GET_PIN(E, 1) -//#define RESET_UB GET_PIN(E, 0) -//#define RESET_CE GET_PIN(G, 10) +//#define LED_HEART GET_PIN(E,3) +//#ifndef ETH_RESET_PIN +//#define ETH_RESET_PIN GET_PIN(E, 7)//71 +//#endif +////#define RESET_LB GET_PIN(E, 1) +////#define RESET_UB GET_PIN(E, 0) +////#define RESET_CE GET_PIN(G, 10) int main(void) { diff --git a/drivers/board.c b/drivers/board.c index 7f209d0..00e244a 100644 --- a/drivers/board.c +++ b/drivers/board.c @@ -98,4 +98,79 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) } } +//185.47kB/103180B no ETH +/** +* @brief ETH MSP Initialization +* This function configures the hardware resources used in this example +* @param heth: ETH handle pointer +* @retval None +*/ +void HAL_ETH_MspInit(ETH_HandleTypeDef* heth) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(heth->Instance==ETH) + { + /* USER CODE BEGIN ETH_MspInit 0 */ + /* USER CODE END ETH_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_ETH_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**ETH GPIO Configuration + PC1 ------> ETH_MDC + PA1 ------> ETH_REF_CLK + PA2 ------> ETH_MDIO + PA7 ------> ETH_CRS_DV + PC4 ------> ETH_RXD0 + PC5 ------> ETH_RXD1 + PG11 PB11 ------> ETH_TX_EN + PG13 PB12 ------> ETH_TXD0 + PG14 PB13 ------> ETH_TXD1 + */ + GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF11_ETH; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF11_ETH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_14|GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF11_ETH; + HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /* ETH interrupt Init */ + HAL_NVIC_SetPriority(ETH_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(ETH_IRQn); + /* USER CODE BEGIN ETH_MspInit 1 */ + + /* USER CODE END ETH_MspInit 1 */ + } + +} + + + +void phy_reset(void) +{ + rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT); + rt_pin_write(ETH_RESET_PIN, PIN_HIGH); + rt_thread_mdelay(50); + rt_pin_write(ETH_RESET_PIN, PIN_LOW); + rt_thread_mdelay(50); + rt_pin_write(ETH_RESET_PIN, PIN_HIGH); +} + +//242.16 KB /51556-64564-70868 add ETH diff --git a/drivers/board.h b/drivers/board.h index 89cf59d..154b338 100644 --- a/drivers/board.h +++ b/drivers/board.h @@ -301,11 +301,11 @@ extern "C" * */ -/*#define BSP_USING_ETH*/ +#define BSP_USING_ETH #ifdef BSP_USING_ETH /*#define PHY_USING_LAN8720A*/ /*#define PHY_USING_DM9161CEP*/ -/*#define PHY_USING_DP83848C*/ +#define PHY_USING_DP83848C #endif /*-------------------------- ETH CONFIG END --------------------------*/ @@ -369,6 +369,14 @@ extern "C" /*#define BSP_USING_ON_CHIP_FLASH*/ + +#define LED_HEART GET_PIN(E,3) +#ifndef ETH_RESET_PIN +#define ETH_RESET_PIN GET_PIN(E, 7)//71 +#endif +////#define RESET_LB GET_PIN(E, 1) +////#define RESET_UB GET_PIN(E, 0) +////#define RESET_CE GET_PIN(G, 10) /*-------------------------- ON_CHIP_FLASH CONFIG END --------------------------*/ #ifdef __cplusplus diff --git a/drivers/stm32f4xx_hal_conf.h b/drivers/stm32f4xx_hal_conf.h index 1ce355c..4590571 100644 --- a/drivers/stm32f4xx_hal_conf.h +++ b/drivers/stm32f4xx_hal_conf.h @@ -57,7 +57,7 @@ /* #define HAL_DAC_MODULE_ENABLED */ /* #define HAL_DCMI_MODULE_ENABLED */ /* #define HAL_DMA2D_MODULE_ENABLED */ -/* #define HAL_ETH_MODULE_ENABLED */ + #define HAL_ETH_MODULE_ENABLED /* #define HAL_NAND_MODULE_ENABLED */ /* #define HAL_NOR_MODULE_ENABLED */ /* #define HAL_PCCARD_MODULE_ENABLED */ diff --git a/rtconfig.h b/rtconfig.h index ceff590..be07d05 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -107,6 +107,7 @@ #define RT_USING_SERIAL_V1 #define RT_SERIAL_USING_DMA #define RT_SERIAL_RB_BUFSZ 4096 +#define RT_USING_PHY #define RT_USING_PIN #define RT_USING_ADC #define RT_USING_RTC @@ -140,6 +141,40 @@ /* Network */ +#define RT_USING_LWIP +#define RT_USING_LWIP212 +#define RT_USING_LWIP_VER_NUM 0x20102 +#define RT_LWIP_MEM_ALIGNMENT 4 + +/* Static IPv4 Address */ + +#define RT_LWIP_IPADDR "192.168.0.30" +#define RT_LWIP_GWADDR "192.168.0.1" +#define RT_LWIP_MSKADDR "255.255.255.0" +/* end of Static IPv4 Address */ +#define RT_LWIP_TCP +#define RT_MEMP_NUM_NETCONN 4 +#define RT_LWIP_PBUF_NUM 4 +#define RT_LWIP_RAW_PCB_NUM 4 +#define RT_LWIP_UDP_PCB_NUM 4 +#define RT_LWIP_TCP_PCB_NUM 4 +#define RT_LWIP_TCP_SEG_NUM 40 +#define RT_LWIP_TCP_SND_BUF 4096 +#define RT_LWIP_TCP_WND 4096 +#define RT_LWIP_TCPTHREAD_PRIORITY 10 +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +#define RT_LWIP_TCPTHREAD_STACKSIZE 1024 +#define RT_LWIP_ETHTHREAD_PRIORITY 12 +#define RT_LWIP_ETHTHREAD_STACKSIZE 1024 +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define SO_REUSE 1 +#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 +#define LWIP_SO_RCVBUF 1 +#define LWIP_SO_LINGER 0 +#define LWIP_NETIF_LOOPBACK 0 /* end of Network */ /* Utilities */