以太网配置
内核配置主要是通过 scons --menuconfig
命令进行 以太网的功能配置, 配置完成后的项目存储在
“target/configs/xxx_defconfig” 文件中
MAC 参数配置
Board options ---> [*] Using Gmac0 gmac0 parameter ---> (PE.6) gmac0 phy reset gpio Select gmac0 bus (RMII) ---> Select phy clk (external clk) ---> (12) gmac0 rx delay (12) gmac0 tx delay (192.168.1.2) gmac0 IPv4 addr (192.168.1.1) gmac0 Gateway (255.255.255.0) gmac0 Subnet Mask (002244887766) gmac0 MAC addr (1) gmac0 PHY MDIO addr
- gmac0 phy reset gpio
外部 PHY 芯片的复位脚相连接的 IO 引脚,根据板卡设计决定
- Select gmac0 bus
选择 MAC 与 PHY 相连接的接口类型,根据板卡决定是 RGMII 还是 RMII
- Select phy clk
选择 MAC 使用的总线参考时钟类型是 external clk (外部时钟)还是 internal clk (内部时钟)。如果选用的是 RGMII 接口,且硬件没有连接 GMAC_CLKIN 引脚的前提下,只能使用 internal clk ,除此之外,建议全部选用
external clk
- gmac0 rx delay
gmac 的接收时延,适用于 RGMII 接口模式下, MAC 匹配 PHY 芯片的数据建立时间和保留时 间(单位:0.17ns), 需要根据外部使用的 PHY 芯片调整。一般情况下,设置为 12 ,即 2.04ns
- gmac0 tx delay
gmac0 的发送时延,适用于 RGMII 接口模式下,MAC 匹配 PHY 芯片的数据建立时间和保留时间 (单位:0.17ns),需要根据外部使用的 PHY 芯片调整。一般情况下,可设置为 12,即 2.04ns
- gmac0 IPv4 addr
当前网卡的初始静态 IP 地址,如打开 DHCP 功能,此处设置无效
- gmac0 Gateway
当前网卡的初始静态网关地址,如打开 DHCP 功能,此处设置无效
- gmac0 Subnet Mask
当前网卡初始静态子网掩码,如打开 DHCP 功能,此处设置无效
- gmac0 MAC addr
gmac0 默认 MAC 地址
- gmac0 PHY MDIO addr
PHY 在 总线上的挂载地址,PHY 芯片地址一般取决于 PHY 芯片外部电路设计,请根据板卡设计决定
LwIP 协议配置
scons --menuconfig
进行裁剪。
Luban-Lite 提供的可裁剪属性如下,如有其他特别需求,可自行配置
packages/third-party/lwip/lwipopts.h
配置文件Local packages options ---> Third-party packages options ---> [*] LwIP: light weight TCP/IP stack ---> [ ] IPV6 protocol [*] LwIP Example [ ] IGMP protocol [*] ICMP protocol [ ] SNMP protocol [ ] Enable DNS for name resolution [ ] Enable alloc ip address through DHCP [*] UDP protocol [*] TCP protocol [*] RAW protocol [ ] PPP protocol (8) the number of struct netconns (16) the number of PBUF (15360) the size of LwIP's dynamic memory (4) the number of raw connection (4) the number of UDP socket (4) the number of TCP socket (40) the number of TCP segment (8196) the size of send buffer (8196) the size of TCP send window (10) the priority level value of lwIP thread (8) the number of mail in the lwIP thread mailbox (3072) the stack size of lwIP thread [ ] Enable IP reassembly and frag [ ] Enable lwIP statistics [ ] Enable tx hardware generate checksum [ ] Enable rx hardware check checksum [ ] Enable ping features ---- [ ] Using socket interface during ping requests ( ) the priority level value of ping thread [ ] Using MQTT protocol [ ] Enable lwIP Debugging Options ----
- IPV6 protocol
LwIP 支持 IPV6 协议
- LwIP Example
SDK 提供的初始化以太网示例,示例程序源码在“packages/third-party/lwip/contrib/examples/example_app/” 目录下的
test.c
netif_start.c
netif_start.h
。打开此选项后,SDK 会在启动过程中自动 初始化以太网。用户可根据自身需求定义以太网初始化流程。如果不开启此选项,则需要用户自己编写以太网 的初始化程序 - IGMP protocol
以太网支持 IGMP 协议,使用组播功能时打开
- ICMP protocol
以太网支持 ICMP 协议,使用 ping 命令时打开
- SNMP protocol
以太网支持 SNMP 协议,需要时打开
- Enable DNS for name resolution
支持 DNS 客户端功能,需要时打开
- Enable alloc ip address through DHCP
支持 DHCP 客户端功能,需要时打开。如果打开 DHCP 选项,默认 IP 地址会失效,如果 IP 申请失败,则此时 IP 地址为 0.0.0.0
- UDP protocol
支持 UDP 协议,默认打开
- TCP protocol
支持 TCP 协议,默认打开
- RAW protocol
支持原始套接字接口,如需要编写基于 RAW 套接字的程序时,需要打开
- PPP protocol
支持 PPP 协议,需要时打开
- the number of struct netconns
struct netconns 接口的数量,默认为 8 个,可根据需求自行修改
- the number of PBUF
pbuf 结构的数量,如果需要发送较多的 ROM 类型消息,可自行修改
- the size of LwIP’s dynamic memory
LwIP 堆空间大小,与数据发送有关,不建议修改
- the number of raw connection
RAW 控制块数量,根据需求修改
- the number of UDP socket
UDP 控制块数量,根据需求修改
- the number of TCP socket
TCP 控制块数量,根据需求修改
- the number of TCP segment
TCP 等待队列的个数,这个值应该不小于 TCP 的发送队列的个数
- the size of send buffer
TCP 发送缓存大小,如无特别需求,请保持默认值
- the size of TCP send window
TCP 滑动窗口大小,如无特别需求,请保持默认值
- the priority level value of lwIP thread
LwIP 协议栈任务优先级,为防止网络丢包,建议保持较高优先级
- the number of mail in the lwIP thread mailbox
消息邮箱数量,如无特别需求,不建议修改此数量
- the stack size of lwIP thread
LwIP 协议栈任务的栈空间大小,如没有添加基于 RAW 接口的应用程序,不建议修改任务栈。 否则,应该加大协议栈任务的栈空间
- Enable IP reassembly and frag
使能 IP 包的分片重装功能
- Enable lwIP statistics
使能 LwIP 统计信息
- Enable tx hardware generate checksum
使能发送时自动生成硬件校验和
- Enable rx hardware check checksum
使能接收时硬件检查校验和
- Enable ping features —-
ping 命令支持,使能此选项后,可在终端中使用 ping 命令
- Using MQTT protocol
支持 MQTT 协议
- Enable lwIP Debugging Options —-
LwIP 调试信息选项,可根据自身需求进行打开
pinmux 配置
#ifdef AIC_USING_GMAC0 /* gmac0 */ {6, PIN_PULL_DIS, 3, "PE.0"}, {6, PIN_PULL_DIS, 3, "PE.1"}, {6, PIN_PULL_DIS, 3, "PE.2"}, {6, PIN_PULL_DIS, 3, "PE.3"}, {6, PIN_PULL_DIS, 3, "PE.4"}, {6, PIN_PULL_DIS, 3, "PE.5"}, {6, PIN_PULL_DIS, 3, "PE.7"}, {6, PIN_PULL_DIS, 3, "PE.8"}, {6, PIN_PULL_DIS, 3, "PE.9"}, /* phy0 reset gpio */ {1, PIN_PULL_DIS, 3, "PE.6"}, /* clk_out2 */ {6, PIN_PULL_DIS, 3, "PE.10"}, #endif