LwIP 2.2.1在STM32F407VET6平台 移植
This commit is contained in:
15
ThirdParty/lwip-2.2.1/port/CMakeLists.txt
vendored
Normal file
15
ThirdParty/lwip-2.2.1/port/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# LwIP port for STM32F407VET6
|
||||
|
||||
# Add port sources to lwip library
|
||||
target_sources(lwip PRIVATE
|
||||
sys_arch.c
|
||||
ethernetif.c
|
||||
)
|
||||
|
||||
# Add include directories for port
|
||||
target_include_directories(lwip PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
../../../../HAL/Inc
|
||||
../../../../BSP/Inc
|
||||
../../../../Core/Inc
|
||||
)
|
||||
16
ThirdParty/lwip-2.2.1/port/arch/bpstruct.h
vendored
Normal file
16
ThirdParty/lwip-2.2.1/port/arch/bpstruct.h
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* bpstruct.h - STM32F407VET6 平台的 LwIP 字节打包结构体配置文件
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_BPSTRUCT_H__
|
||||
#define __ARCH_BPSTRUCT_H__
|
||||
|
||||
/* ---------- 字节打包结构体配置 ---------- */
|
||||
|
||||
/* 打包结构体宏定义 */
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#endif /* __ARCH_BPSTRUCT_H__ */
|
||||
58
ThirdParty/lwip-2.2.1/port/arch/cc.h
vendored
Normal file
58
ThirdParty/lwip-2.2.1/port/arch/cc.h
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* cc.h - STM32F407VET6 平台的 LwIP 架构特定配置文件
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_CC_H__
|
||||
#define __ARCH_CC_H__
|
||||
|
||||
/* 包含标准库头文件 */
|
||||
#include <stdio.h>
|
||||
|
||||
/* 包含错误码定义 */
|
||||
#include "errno.h"
|
||||
|
||||
/* 使用系统提供的struct timeval定义 */
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
|
||||
/* ---------- 编译器配置 ---------- */
|
||||
|
||||
/* 内联函数 */
|
||||
#define LWIP_INLINE inline
|
||||
|
||||
/* 打包结构体 */
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_USE_INCLUDES
|
||||
|
||||
/* 编译器特定的属性 */
|
||||
#define LWIP_UNUSED(x) (void)(x)
|
||||
|
||||
/* ---------- 调试配置 ---------- */
|
||||
|
||||
/* 调试输出函数 */
|
||||
#define LWIP_PLATFORM_DIAG(x) printf x
|
||||
|
||||
/* 平台断言函数 */
|
||||
#define LWIP_PLATFORM_ASSERT(msg) \
|
||||
do { \
|
||||
printf("Assertion failed at %s:%d: %s\n", __FILE__, __LINE__, msg); \
|
||||
while (1); \
|
||||
} while (0)
|
||||
|
||||
/* ---------- 编译器屏障 ---------- */
|
||||
|
||||
/* 编译器屏障指令 */
|
||||
#define LWIP_COMPILER_BARRIER() __asm__ volatile ("" ::: "memory")
|
||||
|
||||
/* ---------- 优化配置 ---------- */
|
||||
|
||||
/* 启用内联函数 */
|
||||
#define LWIP_NO_INLINE 0
|
||||
|
||||
/* 启用快速内存分配 */
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
#endif /* __ARCH_CC_H__ */
|
||||
16
ThirdParty/lwip-2.2.1/port/arch/epstruct.h
vendored
Normal file
16
ThirdParty/lwip-2.2.1/port/arch/epstruct.h
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* epstruct.h - STM32F407VET6 平台的 LwIP 结构体打包配置文件
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_EPSTRUCT_H__
|
||||
#define __ARCH_EPSTRUCT_H__
|
||||
|
||||
/* ---------- 扩展结构体打包配置 ---------- */
|
||||
|
||||
/* 打包结构体宏定义 */
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#endif /* __ARCH_EPSTRUCT_H__ */
|
||||
147
ThirdParty/lwip-2.2.1/port/arch/errno.h
vendored
Normal file
147
ThirdParty/lwip-2.2.1/port/arch/errno.h
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* errno.h - STM32F407VET6 平台的错误码定义文件
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_ERRNO_H__
|
||||
#define __ARCH_ERRNO_H__
|
||||
|
||||
/* ---------- 错误码定义 ---------- */
|
||||
|
||||
/* 系统错误码 */
|
||||
extern int errno;
|
||||
|
||||
/* 基本错误码 */
|
||||
#define EPERM 1 /* 操作不允许 */
|
||||
#define ENOENT 2 /* 没有这样的文件或目录 */
|
||||
#define ESRCH 3 /* 没有这样的进程 */
|
||||
#define EINTR 4 /* 中断系统调用 */
|
||||
#define EIO 5 /* I/O 错误 */
|
||||
#define ENXIO 6 /* 没有这样的设备或地址 */
|
||||
#define E2BIG 7 /* 参数列表太长 */
|
||||
#define ENOEXEC 8 /* 执行格式错误 */
|
||||
#define EBADF 9 /* 错误的文件描述符 */
|
||||
#define ECHILD 10 /* 没有子进程 */
|
||||
#define EAGAIN 11 /* 资源暂时不可用 */
|
||||
#define ENOMEM 12 /* 内存不足 */
|
||||
#define EACCES 13 /* 权限被拒绝 */
|
||||
#define EFAULT 14 /* 错误的地址 */
|
||||
#define ENOTBLK 15 /* 块设备需要 */
|
||||
#define EBUSY 16 /* 设备或资源忙 */
|
||||
#define EEXIST 17 /* 文件已存在 */
|
||||
#define EXDEV 18 /* 跨设备链接 */
|
||||
#define ENODEV 19 /* 没有这样的设备 */
|
||||
#define ENOTDIR 20 /* 不是目录 */
|
||||
#define EISDIR 21 /* 是目录 */
|
||||
#define EINVAL 22 /* 参数无效 */
|
||||
#define ENFILE 23 /* 系统中打开的文件太多 */
|
||||
#define EMFILE 24 /* 进程打开的文件太多 */
|
||||
#define ENOTTY 25 /* 不是类型化的终端 */
|
||||
#define ETXTBSY 26 /* 文本文件忙 */
|
||||
#define EFBIG 27 /* 文件太大 */
|
||||
#define ENOSPC 28 /* 设备上没有空间 */
|
||||
#define ESPIPE 29 /* 非法搜索 */
|
||||
#define EROFS 30 /* 只读文件系统 */
|
||||
#define EMLINK 31 /* 太多链接 */
|
||||
#define EPIPE 32 /* 断开的管道 */
|
||||
#define EDOM 33 /* 数学参数超出域 */
|
||||
#define ERANGE 34 /* 数学结果超出范围 */
|
||||
#define EDEADLK 35 /* 资源死锁会发生 */
|
||||
#define ENAMETOOLONG 36 /* 文件名太长 */
|
||||
#define ENOLCK 37 /* 没有可用的锁 */
|
||||
#define ENOSYS 38 /* 功能未实现 */
|
||||
#define ENOTEMPTY 39 /* 目录不为空 */
|
||||
#define ELOOP 40 /* 太多符号链接级别 */
|
||||
#define ENOMSG 42 /* 没有所需类型的消息 */
|
||||
#define EIDRM 43 /* 标识符已被删除 */
|
||||
#define ECHRNG 44 /* 通道数超出范围 */
|
||||
#define EL2NSYNC 45 /* 级别 2 未同步 */
|
||||
#define EL3HLT 46 /* 级别 3 停止 */
|
||||
#define EL3RST 47 /* 级别 3 重置 */
|
||||
#define ELNRNG 48 /* 链接数超出范围 */
|
||||
#define EUNATCH 49 /* 协议驱动程序未附加 */
|
||||
#define ENOCSI 50 /* 没有 CSI 进程可用于继承 */
|
||||
#define EL2HLT 51 /* 级别 2 停止 */
|
||||
#define EBADE 52 /* 无效的交换 */
|
||||
#define EBADR 53 /* 无效的请求描述符 */
|
||||
#define EXFULL 54 /* 交换已满 */
|
||||
#define ENOANO 55 /* 没有此阳极 */
|
||||
#define EBADRQC 56 /* 无效的请求代码 */
|
||||
#define EBADSLT 57 /* 无效的插槽 */
|
||||
#define EDEADLOCK 58 /* 资源死锁会发生 */
|
||||
#define EBFONT 59 /* 错误的字体文件格式 */
|
||||
#define ENOSTR 60 /* 设备不是流 */
|
||||
#define ENODATA 61 /* 无可用数据 */
|
||||
#define ETIME 62 /* 定时器已过期 */
|
||||
#define ENOSR 63 /* 流资源不足 */
|
||||
#define ENONET 64 /* 机器不在网络上 */
|
||||
#define ENOPKG 65 /* 包未安装 */
|
||||
#define EREMOTE 66 /* 对象是远程的 */
|
||||
#define ENOLINK 67 /* 链接已断开 */
|
||||
#define EADV 68 /* 广告错误 */
|
||||
#define ESRMNT 69 /* 挂载点被拒绝 */
|
||||
#define ECOMM 70 /* 通信错误在发送时 */
|
||||
#define EPROTO 71 /* 协议错误 */
|
||||
#define EMULTIHOP 72 /* 多跳尝试 */
|
||||
#define EDOTDOT 73 /* 尝试 .. 超出挂载点 */
|
||||
#define EBADMSG 74 /* 错误的消息 */
|
||||
#define EOVERFLOW 75 /* 值太大,无法存储在数据类型中 */
|
||||
#define ENOTUNIQ 76 /* 名称在网络上不唯一 */
|
||||
#define EBADFD 77 /* 文件描述符处于错误状态 */
|
||||
#define EREMCHG 78 /* 远程地址已更改 */
|
||||
#define ELIBACC 79 /* 无法访问所需的共享库 */
|
||||
#define ELIBBAD 80 /* 访问的共享库损坏 */
|
||||
#define ELIBSCN 81 /* .lib 部分损坏或格式错误 */
|
||||
#define ELIBMAX 82 /* 尝试链接太多共享库 */
|
||||
#define ELIBEXEC 83 /* 无法直接执行共享库 */
|
||||
#define EILSEQ 84 /* 非法字节序列 */
|
||||
#define ERESTART 85 /* 应重新启动被中断的系统调用 */
|
||||
#define ESTRPIPE 86 /* 流管道错误 */
|
||||
#define EUSERS 87 /* 超出最大用户数 */
|
||||
#define ENOTSOCK 88 /* 操作在非套接字上 */
|
||||
#define EDESTADDRREQ 89 /* 需要目标地址 */
|
||||
#define EMSGSIZE 90 /* 消息太大 */
|
||||
#define EPROTOTYPE 91 /* 套接字协议类型错误 */
|
||||
#define ENOPROTOOPT 92 /* 协议不可用 */
|
||||
#define EPROTONOSUPPORT 93 /* 协议不受支持 */
|
||||
#define ESOCKTNOSUPPORT 94 /* 套接字类型不受支持 */
|
||||
#define EOPNOTSUPP 95 /* 操作不受支持 */
|
||||
#define EPFNOSUPPORT 96 /* 协议族不受支持 */
|
||||
#define EAFNOSUPPORT 97 /* 地址族不受支持 */
|
||||
#define EADDRINUSE 98 /* 地址已在使用中 */
|
||||
#define EADDRNOTAVAIL 99 /* 无法分配请求的地址 */
|
||||
#define ENETDOWN 100 /* 网络已关闭 */
|
||||
#define ENETUNREACH 101 /* 网络不可达 */
|
||||
#define ENETRESET 102 /* 网络已重置连接 */
|
||||
#define ECONNABORTED 103 /* 连接被对方中止 */
|
||||
#define ECONNRESET 104 /* 连接被重置 */
|
||||
#define ENOBUFS 105 /* 没有可用的缓冲区空间 */
|
||||
#define EISCONN 106 /* 套接字已连接 */
|
||||
#define ENOTCONN 107 /* 套接字未连接 */
|
||||
#define ESHUTDOWN 108 /* 无法在已关闭发送端的套接字上发送 */
|
||||
#define ETOOMANYREFS 109 /* 对参考的引用过多 */
|
||||
#define ETIMEDOUT 110 /* 连接超时 */
|
||||
#define ECONNREFUSED 111 /* 连接被拒绝 */
|
||||
#define EHOSTDOWN 112 /* 主机已关闭 */
|
||||
#define EHOSTUNREACH 113 /* 无到主机的路由 */
|
||||
#define EALREADY 114 /* 操作已在进行中 */
|
||||
#define EINPROGRESS 115 /* 操作现在正在进行中 */
|
||||
#define ESTALE 116 /* 过时的文件句柄 */
|
||||
#define EUCLEAN 117 /* 结构需要清洁 */
|
||||
#define ENOTNAM 118 /* 不是 XENIX 命名的类型文件 */
|
||||
#define ENAVAIL 119 /* 没有 XENIX 语义可用 */
|
||||
#define EISNAM 120 /* 是一个命名类型文件 */
|
||||
#define EREMOTEIO 121 /* 远程 I/O 错误 */
|
||||
#define EDQUOT 122 /* 超出磁盘配额限制 */
|
||||
#define ENOMEDIUM 123 /* 无介质插入 */
|
||||
#define EMEDIUMTYPE 124 /* 介质类型错误 */
|
||||
#define ECANCELED 125 /* 操作已取消 */
|
||||
#define ENOKEY 126 /* 所需的密钥不可用 */
|
||||
#define EKEYEXPIRED 127 /* 密钥已过期 */
|
||||
#define EKEYREVOKED 128 /* 密钥已被撤销 */
|
||||
#define EKEYREJECTED 129 /* 密钥被服务拒绝 */
|
||||
#define EOWNERDEAD 130 /* 所有者死亡 */
|
||||
#define ENOTRECOVERABLE 131 /* 状态不可恢复 */
|
||||
#define ERFKILL 132 /* 操作被 RF 杀死 */
|
||||
#define EHWPOISON 133 /* 内存页已中毒 */
|
||||
|
||||
#endif /* __ARCH_ERRNO_H__ */
|
||||
203
ThirdParty/lwip-2.2.1/port/ethernetif.c
vendored
Normal file
203
ThirdParty/lwip-2.2.1/port/ethernetif.c
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* ethernetif.c - STM32F407VET6 平台的 LwIP 以太网接口实现
|
||||
*
|
||||
* 连接 LwIP 与 STM32 HAL 以太网驱动
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/prot/ethernet.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "bsp_eth.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include <string.h>
|
||||
|
||||
/* 以太网接口状态结构 */
|
||||
struct ethernetif {
|
||||
struct eth_addr *ethaddr;
|
||||
/* 其他私有数据 */
|
||||
};
|
||||
|
||||
/* 全局以太网接口结构 */
|
||||
static struct netif gnetif;
|
||||
static struct ethernetif ethernetif;
|
||||
|
||||
/* 以太网接收回调函数 */
|
||||
static void ethernetif_input(void *arg)
|
||||
{
|
||||
struct netif *netif = (struct netif *)arg;
|
||||
struct pbuf *p = NULL;
|
||||
uint8_t buffer[1520];
|
||||
uint16_t length;
|
||||
int ret;
|
||||
|
||||
/* 从以太网驱动接收数据包 */
|
||||
ret = hal_eth_receive(HAL_ETH_INSTANCE_1, buffer, &length);
|
||||
if (ret == HAL_RET_OK && length > 0) {
|
||||
/* 为接收到的数据分配 pbuf */
|
||||
p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
|
||||
if (p != NULL) {
|
||||
/* 复制数据到 pbuf */
|
||||
memcpy(p->payload, buffer, length);
|
||||
|
||||
/* 处理接收到的数据包 */
|
||||
if (netif->input(p, netif) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 以太网发送函数 */
|
||||
static err_t ethernetif_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct pbuf *q;
|
||||
uint8_t buffer[1520];
|
||||
uint16_t length = 0;
|
||||
int ret;
|
||||
|
||||
/* 检查参数 */
|
||||
if (netif == NULL || p == NULL) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
/* 复制 pbuf 链中的数据到发送缓冲区 */
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
if (length + q->len <= sizeof(buffer)) {
|
||||
memcpy(buffer + length, q->payload, q->len);
|
||||
length += q->len;
|
||||
} else {
|
||||
return ERR_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
/* 发送数据包 */
|
||||
ret = hal_eth_transmit(HAL_ETH_INSTANCE_1, buffer, length);
|
||||
if (ret != HAL_RET_OK) {
|
||||
return ERR_IF;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* 以太网接口初始化函数 */
|
||||
static err_t ethernetif_init(struct netif *netif)
|
||||
{
|
||||
struct ethernetif *ethernetif = netif->state;
|
||||
bsp_eth_config_t eth_config;
|
||||
hal_ret_t ret;
|
||||
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
|
||||
/* 设置网络接口参数 */
|
||||
netif->name[0] = 'e';
|
||||
netif->name[1] = 'n';
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = ethernetif_output;
|
||||
netif->state = ðernetif;
|
||||
netif->mtu = 1500;
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
||||
|
||||
/* 设置 MAC 地址 */
|
||||
hal_eth_mac_addr_t mac_addr;
|
||||
ret = bsp_eth_get_mac_addr(&mac_addr);
|
||||
if (ret == HAL_RET_OK) {
|
||||
netif->hwaddr[0] = mac_addr.byte[0];
|
||||
netif->hwaddr[1] = mac_addr.byte[1];
|
||||
netif->hwaddr[2] = mac_addr.byte[2];
|
||||
netif->hwaddr[3] = mac_addr.byte[3];
|
||||
netif->hwaddr[4] = mac_addr.byte[4];
|
||||
netif->hwaddr[5] = mac_addr.byte[5];
|
||||
netif->hwaddr_len = ETH_HWADDR_LEN;
|
||||
}
|
||||
|
||||
/* 初始化以太网硬件 */
|
||||
eth_config.enable = 1;
|
||||
eth_config.instance = HAL_ETH_INSTANCE_1;
|
||||
eth_config.mode = HAL_ETH_MODE_FULLDUPLEX;
|
||||
eth_config.speed = HAL_ETH_SPEED_100MBPS;
|
||||
eth_config.phy_addr = LAN8720_PHY_ADDRESS;
|
||||
eth_config.auto_negotiation = 1;
|
||||
eth_config.interrupt_enable = 1;
|
||||
|
||||
ret = bsp_eth_init(ð_config);
|
||||
if (ret != HAL_RET_OK) {
|
||||
return ERR_IF;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: STM32F407VET6 Ethernet initialized\n"));
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* 初始化以太网接口 */
|
||||
void ethernetif_create(void)
|
||||
{
|
||||
ip4_addr_t ipaddr, netmask, gw;
|
||||
|
||||
/* 初始化 LwIP 核心 */
|
||||
lwip_init();
|
||||
|
||||
/* 设置 IP 地址 */
|
||||
IP4_ADDR(&ipaddr, 192, 168, 1, 100);
|
||||
IP4_ADDR(&netmask, 255, 255, 255, 0);
|
||||
IP4_ADDR(&gw, 192, 168, 1, 1);
|
||||
|
||||
/* 添加网络接口 */
|
||||
#if NO_SYS
|
||||
/* 无操作系统环境:使用以太网输入函数 */
|
||||
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ethernet_input);
|
||||
#else
|
||||
/* 有操作系统环境:使用 TCP/IP 输入函数 */
|
||||
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
|
||||
#endif
|
||||
|
||||
/* 设置默认网络接口 */
|
||||
netif_set_default(&gnetif);
|
||||
|
||||
/* 启用网络接口 */
|
||||
netif_set_up(&gnetif);
|
||||
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_create: Network interface created\n"));
|
||||
}
|
||||
|
||||
/* 以太网中断处理函数 */
|
||||
void ETH_IRQHandler(void)
|
||||
{
|
||||
/* 处理以太网中断 */
|
||||
hal_eth_irq_handler(HAL_ETH_INSTANCE_1);
|
||||
|
||||
/* 触发数据包处理 */
|
||||
ethernetif_input(&gnetif);
|
||||
}
|
||||
|
||||
/* 获取网络接口 */
|
||||
struct netif *ethernetif_get_netif(void)
|
||||
{
|
||||
return &gnetif;
|
||||
}
|
||||
|
||||
/* 网络接口状态检查 */
|
||||
void ethernetif_check_link(void)
|
||||
{
|
||||
uint8_t link_up;
|
||||
hal_ret_t ret;
|
||||
|
||||
ret = bsp_eth_check_link(&link_up);
|
||||
if (ret == HAL_RET_OK) {
|
||||
if (link_up && !(gnetif.flags & NETIF_FLAG_LINK_UP)) {
|
||||
/* 链接已建立 */
|
||||
netif_set_link_up(&gnetif);
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_check_link: Link up\n"));
|
||||
} else if (!link_up && (gnetif.flags & NETIF_FLAG_LINK_UP)) {
|
||||
/* 链接已断开 */
|
||||
netif_set_link_down(&gnetif);
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_check_link: Link down\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
ThirdParty/lwip-2.2.1/port/ethernetif.h
vendored
Normal file
19
ThirdParty/lwip-2.2.1/port/ethernetif.h
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* ethernetif.h - STM32F407VET6 平台的 LwIP 以太网接口头文件
|
||||
*/
|
||||
|
||||
#ifndef ETHERNETIF_H
|
||||
#define ETHERNETIF_H
|
||||
|
||||
#include "lwip/netif.h"
|
||||
|
||||
/* 以太网接口初始化函数 */
|
||||
void ethernetif_init(struct netif *netif);
|
||||
|
||||
/* 以太网接口输入处理函数 */
|
||||
void ethernetif_input(void *arg);
|
||||
|
||||
/* 以太网接口状态更新函数 */
|
||||
void ethernetif_update_status(struct netif *netif);
|
||||
|
||||
#endif /* ETHERNETIF_H */
|
||||
110
ThirdParty/lwip-2.2.1/port/lwipopts.h
vendored
Normal file
110
ThirdParty/lwip-2.2.1/port/lwipopts.h
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* lwipopts.h - STM32F407VET6 平台的 LwIP 配置文件
|
||||
*
|
||||
* 根据 STM32F407VET6 硬件特性优化配置
|
||||
*/
|
||||
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
/* ---------- 平台特定配置 ---------- */
|
||||
|
||||
/* 无操作系统配置 */
|
||||
#define NO_SYS 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 0
|
||||
#define NO_SYS_NO_TIMERS 1
|
||||
#define NO_SYS_NO_SYS_TIMEOUT 1
|
||||
|
||||
/* 内存配置(STM32F407VET6 有 192KB RAM) */
|
||||
#define MEM_SIZE 16384 /* 16KB 内存池 */
|
||||
#define MEMP_NUM_PBUF 16 /* PBUF 数量 */
|
||||
#define MEMP_NUM_UDP_PCB 8 /* UDP PCB 数量 */
|
||||
#define MEMP_NUM_TCP_PCB 8 /* TCP PCB 数量 */
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 4 /* TCP 监听 PCB 数量 */
|
||||
#define MEMP_NUM_TCP_SEG 16 /* TCP 段数量 */
|
||||
|
||||
/* PBUF 配置 */
|
||||
#define PBUF_POOL_SIZE 16 /* PBUF 池大小 */
|
||||
#define PBUF_POOL_BUFSIZE 1520 /* PBUF 缓冲区大小(以太网 MTU + 头部) */
|
||||
|
||||
/* 网络接口配置 */
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1 /* 启用链接状态回调 */
|
||||
#define LWIP_NETIF_HOSTNAME 1 /* 启用主机名 */
|
||||
#define NETIF_MAX_HWADDR_LEN 6 /* MAC 地址长度 */
|
||||
|
||||
/* ---------- 协议栈配置 ---------- */
|
||||
|
||||
/* IPv4 配置 */
|
||||
#define LWIP_IPV4 1 /* 启用 IPv4 */
|
||||
#define LWIP_ARP 1 /* 启用 ARP */
|
||||
#define LWIP_ICMP 1 /* 启用 ICMP(Ping) */
|
||||
#define LWIP_IGMP 0 /* 禁用 IGMP */
|
||||
#define LWIP_DHCP 1 /* 启用 DHCP */
|
||||
|
||||
/* IPv6 配置 */
|
||||
#define LWIP_IPV6 0 /* 禁用 IPv6 */
|
||||
|
||||
/* TCP 配置 */
|
||||
#define LWIP_TCP 1 /* 启用 TCP */
|
||||
#define LWIP_TCP_KEEPALIVE 1 /* 启用 TCP 保活 */
|
||||
#define TCP_TTL 255 /* TCP TTL */
|
||||
#define TCP_WND 2048 /* TCP 窗口大小 */
|
||||
#define TCP_MAXSEG 1460 /* TCP 最大段大小 */
|
||||
|
||||
/* UDP 配置 */
|
||||
#define LWIP_UDP 1 /* 启用 UDP */
|
||||
#define UDP_TTL 255 /* UDP TTL */
|
||||
|
||||
/* DNS 配置 */
|
||||
#define LWIP_DNS 1 /* 启用 DNS */
|
||||
|
||||
/* ---------- 应用层配置 ---------- */
|
||||
|
||||
/* 套接字 API - 在无操作系统环境中禁用 */
|
||||
#define LWIP_SOCKET 0 /* 禁用套接字 API */
|
||||
|
||||
/* 网络接口 API - 在无操作系统环境中禁用 */
|
||||
#define LWIP_NETIF_API 0 /* 禁用网络接口 API */
|
||||
|
||||
/* 网络连接 API - 在无操作系统环境中禁用 */
|
||||
#define LWIP_NETCONN 0 /* 禁用网络连接 API */
|
||||
|
||||
/* ---------- 性能优化 ---------- */
|
||||
|
||||
/* 校验和配置 */
|
||||
#define CHECKSUM_BY_HARDWARE 1 /* 启用硬件校验和 */
|
||||
|
||||
/* 内存优化 */
|
||||
#define MEM_ALIGNMENT 4 /* 内存对齐 */
|
||||
#define MEM_SIZE_ALIGNED 1 /* 内存大小对齐 */
|
||||
|
||||
/* ---------- 调试配置 ---------- */
|
||||
|
||||
/* 调试级别 */
|
||||
#define LWIP_DEBUG 1 /* 启用调试 */
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
|
||||
/* 具体模块调试 */
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
#define DNS_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/* ---------- 平台特定定义 ---------- */
|
||||
|
||||
/* STM32F407VET6 特定定义 */
|
||||
#define STM32F407xx 1
|
||||
#define LAN8720_PHY_ADDRESS 0x00 /* LAN8720 PHY 地址 */
|
||||
|
||||
/* 硬件校验和支持 */
|
||||
#define ETH_PAD_SIZE 0
|
||||
#define LWIP_CHECKSUM_ON_COPY 0
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
45
ThirdParty/lwip-2.2.1/port/sys_arch.c
vendored
Normal file
45
ThirdParty/lwip-2.2.1/port/sys_arch.c
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* sys_arch.c - STM32F407VET6 平台的 LwIP 系统移植层
|
||||
*
|
||||
* 实现无操作系统版本的 LwIP 系统接口
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/debug.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* 系统错误处理 */
|
||||
void sys_assert(const char *msg)
|
||||
{
|
||||
/* 打印错误信息并停机 */
|
||||
printf("Assertion failed: %s\n", msg);
|
||||
while (1);
|
||||
}
|
||||
|
||||
/* 获取当前系统时间(毫秒) */
|
||||
u32_t sys_now(void)
|
||||
{
|
||||
return HAL_GetTick();
|
||||
}
|
||||
|
||||
/* 内存分配函数 */
|
||||
void *sys_malloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
/* 内存释放函数 */
|
||||
void sys_free(void *mem)
|
||||
{
|
||||
free(mem);
|
||||
}
|
||||
|
||||
/* 初始化系统接口 */
|
||||
void sys_init(void)
|
||||
{
|
||||
/* 系统时间已经由 HAL_Init() 初始化 */
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_init: STM32F407VET6 sys_arch initialized\n"));
|
||||
}
|
||||
Reference in New Issue
Block a user