首先准备几份资料:
(1)资料
1.lwip2.1.3 最新版 例程最新版contrib-2.1.0
下载地址
下载的是稳定版的2.1.3
lwip.git - lwIP - A Lightweight TCPIP stack
2.freertos 10 最新版 FreeRTOS - Market leading RTOS (Real Time Operating System) for embedded systems with Internet of Things extensions
3.stm固件库 我上传到云盘了
4.stm网口驱动程序
STSW-STM32070 - STM32F4x7微控制器的LwIP TCP/IP堆栈演示(AN3966) - STMicroelectronics
(2)移植freertos:(本次移植是带操作系统的)
具体移植看教程:
FreeRTOS实时操作系统系统移植(常见问题,基础总步骤)_IT小生lkc的博客-CSDN博客_freertos移植步骤
(3)目录结导入:
lwip工程结构:基本的外设库导入这里就不提及了
1.将lwip包放进目录下
主要工程目录:LWIP_API LWIP_CORE LWIP_NETIF LWIP_ARCH
将下载包内下src目录下的文件,移动到工程目录ThirtyParty下
2.将lwip文件导入工程
导入lwip api 全部文件
导入LWIP_CORE: core目录下以及ipv4目录下全部文件
LWIP_NETIF:除了ppp都添加
3.添加头文件:
注意:关于缺少的头文件,放进一个可以索引的头文件目录就可以,不必太在意我放在哪个目录
(4)基本出现的问题:
开始运行一遍:
问题1:
..\ThirtyParty\lwip\include\lwip/opt.h(51): error: #5: cannot open source input file "lwipopts.h": No such file or directory
提示没有lwipopts.h 也就是没有整个lwip的配置文件
解决:在例程文件中搜索lwipopts.h 使用例程的lwipopts.h
LWIP\source\contrib-2.1.0\examples\example_app
推荐下边这个lwipopts,比较容易调试
LWIP\source\STM32F4x7_ETH_LwIP_V1.1.1\Project\FreeRTOS\udptcp_echo_server_netconn\inc
放在头文件的目录里边,我暂且将该文件放在User中,其实都是一样的
问题2:
然后继续运行
..\ThirtyParty\lwip\include\lwip/arch.h(48): error: #5: cannot open source input file "arch/cc.h": No such file or directory
提示没有cc.h,cc.h其实是代表cpu
接续在例程中搜索,其实有两个win32和unix其实都是可以的,这里我们选择unix
LWIP\source\contrib-2.1.0\ports\unix\port\include\arch
这里我们也暂时将这个文件放在User里边,新建一个arch,放在arch里边
问题3:
..\User\arch/cc.h(51): error: #5: cannot open source input file "sys/time.h": No such file or directory
在例程搜索:然后在User新建sys,将time.h放进去,因为原先的存在这个,这个头文件可能后边没有使用,但是引用了,暂时将其导入
问题4:
..\ThirtyParty\lwip\include\lwip/sys.h(95): error: #5: cannot open source input file "arch/sys_arch.h": No such file or directory
将arch里边的sys_arch.c和sys_arch.h都放到User下的arch
LWIP\source\contrib-2.1.0\ports\freertos\include\arch
问题5:
..\User\sys/time.h(7): error: #20: identifier "time_t" is undefined
查看了一下原先的定义,是long,重命名一下就可以了
问题6: 这里是我的问题,忘记导入网卡的驱动
..\ThirtyParty\lwip\api\sockets.c(486): error: #20: identifier "EBADF" is undefined
导入网口驱动:,这里的驱动是上边stm的一个网口驱动例程里的
LWIP\source\STM32F4x7_ETH_LwIP_V1.1.1\Libraries
导入头文件
问题7:
..\ThirtyParty\lwip\api\err.c(51): error: #20: identifier "ENOBUFS" is undefined
显示这些没有被定义,应该是跟头文件有关系,但是头文件都导入了,使用sourceinsight 全局搜索了一下,在errno.h定义了,头文件也包含了,发现宏定义
LWIP_PROVIDE_ERRNO应该是没有被定义,所以在lwipopts.h配置文件中定义该红一定
问题8:
..\Library\STM32F4x7_ETH_Driver\inc\stm32f4x7_eth.h(38): error: #5: cannot open source input file "stm32f4x7_eth_conf.h": No such file or directory
随便找一个网口驱动找freertos中的这个配置:
C:\Users\lkc\Desktop\project\csdn\LWIP\source\STM32F4x7_ETH_LwIP_V1.1.1\Project\FreeRTOS\udptcp_echo_server_netconn\inc
也放到User中吧
问题9:
..\Library\STM32F4x7_ETH_Driver\src\stm32f4x7_eth.c(377): warning: #223-D: function "Delay" declared implicitly
这里使用freertos中的延时
问题10:
LWIP\source\STM32F4x7_ETH_LwIP_V1.1.1\Utilities\Third_Party\lwip-1.4.1\port\STM32F4x7\FreeRTOS
这里是驱动和lwip的底层接口,可以直接使用stm例程
拷贝到User
问题11:
最后一个错误:因为拷贝的ethernetif是1.4版本写的,所以期间到2.1.3修改了名字,现在叫timerouts.h
..\User\ethernetif.c(50): error: #5: cannot open source input file "lwip/timers.h": No such file or directory
问题12:
..\User\ethernetif.c(74): error: #20: identifier "xSemaphoreHandle" is undefined
缺少这个,因为是头文件没有在文件中声明
我统一把头文件声明在一个文件,当然如果你想声明在其他文件也没问题,只要能引入到就行
问题13:固件库网卡例程关于mac地址等等的定义
最后还是DELAY函数没有,还有这些mac地址,主要是因为网卡驱动的main,.h中的东西自己没有引用过来
将基本的mac地址和delay函数声明复制到自己的main.h