開發(fā)環(huán)境:野火的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;
復(fù)位腳 :NRST腳。
接線方式: 筆記本連接路由器,野火開發(fā)板也連接路由器。
根據(jù)文檔需要做的步驟如下:
/*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的協(xié)議棧,雙擊工程下的RT—Thread Settings,選擇組件,選擇lwIP。右鍵lwIP選擇配置項(xiàng)進(jìn)行配置,選擇版本等參數(shù)。選擇的是v2.0.2。保存配置,等待下載即可。
對(duì)程序進(jìn)行編譯,編譯正常下載,查看打印信息。
在中斷,可看到打印信息 lwIP-2.0.2 initialized! 。使用ping指令ping 筆記本ip,可正常ping通。
-
路由器
+關(guān)注
關(guān)注
22文章
3693瀏覽量
113426 -
LwIP協(xié)議棧
+關(guān)注
關(guān)注
0文章
19瀏覽量
7330 -
LAN8720
+關(guān)注
關(guān)注
0文章
4瀏覽量
11022 -
STM32F407
+關(guān)注
關(guān)注
15文章
187瀏覽量
29332 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1261瀏覽量
39838
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論