开发环境:野火的STM32f407,rt-thread studio版本为版本:2.2.6,stm32f4的资源包为0.2.2,Agile Modbus软件包版本为v1.1.2。新选择芯片工作。 修改工程使用外部晶振,可参考第一篇文章rt-thread studio新建stm32f407工程。 查看野火工程的资料,可知芯片的使用引脚为: PG11 : RMII_TX_EN; PG13 : RMII_TXD0; PG14 : RMII_TXD1; PC5 : RMII_RXD1; PC4 : RMII_RXD0; PA7 : RMII_CRSDV; PA1 : RMII_REF_CLK; PC1 : RMII_MDC; PA2 : RMII_MDIO; 复位脚:NRST脚。 连接方式:笔记本连接路由器,野火开发板也连接路由器。 根据文档需要做的步骤如下: /*if you want to use eth you can use the following instructions. * * STEP 1, define macro related to the eth * such as BSP_USING_ETH * * STEP 2, copy your eth init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file * such as void HAL_ETH_MspInit(ETH_HandleTypeDef* heth) * * STEP 3, modify your stm32xxxx_hal_config.h file to support eth peripherals. define macro related to the peripherals * such as #define HAL_ETH_MODULE_ENABLED * * STEP 4, config your phy type * such as #define PHY_USING_LAN8720A * #define PHY_USING_DM9161CEP * #define PHY_USING_DP83848C * STEP 5, implement your phy reset function in the end of board.c file * void phy_reset(void) * * STEP 6, config your lwip or other network stack */ 按照要修改即可,主要讲STEP2和STEP6的修改。STEP2中的代码使用cubmx生成,生成的代码如下: void HAL_ETH_MspInit(ETH_HandleTypeDef* ethHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(ethHandle-》Instance==ETH) { /* USER CODE BEGIN ETH_MspInit 0 */ /* USER CODE END ETH_MspInit 0 */ /* ETH clock enable */ __HAL_RCC_ETH_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOG_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 ------》 ETH_TX_EN PG13 ------》 ETH_TXD0 PG14 ------》 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_13|GPIO_PIN_14; 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); /* USER CODE BEGIN ETH_MspInit 1 */ /* USER CODE END ETH_MspInit 1 */ } } step6中lwip的栈栈,rt - thread设置,选择选择组件,选择lwip。lwip lwip lwip lwip选择选择项配置可。
对程序进行编译,编译正常下载,查看打印信息。 在中途,可看到打印信息lwIP-2.0.2已初始化!。使用ping指令ping笔记本ip,可正常ping通。 |