配置 LAN8720A 接入网络
参考链接
cubeMX 配置
启用 Eth 模块
1 2
| 选择 RMII 对比实际板的原理图,修改引脚位置,注意rst引脚的位置
|
项目配置
修改 ports/phy_reset.c 内 rst 引脚位置, 复制 ports 目录到 board 下,修改 SConscript
1 2 3 4
| path += [cwd + '/ports']
if GetDepend(['BSP_USING_ETH']): src += Glob('ports/phy_reset.c')
|
board/Kconfig 配置
Kconfig 里面,menu “Onboard Peripheral Drivers”内添加
1 2 3 4 5 6 7
| config PHY_USING_LAN8720A bool config BSP_USING_ETH bool "Enable Ethernet" default n select RT_USING_LWIP select PHY_USING_LAN8720A
|
1 2 3 4 5 6 7 8
| RT-Thread Components > Network > Socket abstraction layer [*] Enable socket abstraction layer [*] Enable BSD socket operated by file system API light weight TCP/IP stack [] Enable alloc ip address through DHCP [*] Enable lwIP stack
|
在light weight TCP/IP stack里面, 选项 Enable alloc ip address through DHCP来控制 dhcp 或者固定 ip
打开调试开关
libraries/HAL_Drivers/drv_eth.c
1 2 3
| #define ETH_RX_DUMP #define ETH_TX_DUMP #define DRV_DEBUG
|
相关代码
phy_reset.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <board.h>
#define RESET_IO GET_PIN(H, 2)
void phy_reset(void) { rt_pin_write(RESET_IO, PIN_LOW); rt_thread_mdelay(50); rt_pin_write(RESET_IO, PIN_HIGH); }
int phy_init(void) { rt_pin_mode(RESET_IO, PIN_MODE_OUTPUT); rt_pin_write(RESET_IO, PIN_HIGH); return RT_EOK; } INIT_BOARD_EXPORT(phy_init);
|