feat: 完成TCP2UART透传核心集成
集成CH390驱动、LwIP协议栈和FreeRTOS多任务透传框架,确保TCP Server/Client与UART链路按配置稳定联动。
This commit is contained in:
+195
@@ -0,0 +1,195 @@
|
||||
========================================
|
||||
TCP2UART Keil 工程配置说明
|
||||
========================================
|
||||
|
||||
由于 Keil 工程文件格式复杂,建议在 Keil uVision 中手动添加以下配置。
|
||||
|
||||
========================================
|
||||
一、添加包含路径 (Include Paths)
|
||||
========================================
|
||||
|
||||
打开 Keil -> Project -> Options for Target -> C/C++ -> Include Paths
|
||||
|
||||
添加以下路径(用分号分隔):
|
||||
../Drivers/CH390
|
||||
../Drivers/LwIP/src/include
|
||||
../Drivers/LwIP/src/include/lwip
|
||||
../Drivers/LwIP/src/include/netif
|
||||
../Drivers/LwIP/src/include/arch
|
||||
../Drivers/LwIP/port
|
||||
../App
|
||||
|
||||
完整的 Include Paths 应该是:
|
||||
../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3;../Drivers/CH390;../Drivers/LwIP/src/include;../Drivers/LwIP/src/include/lwip;../Drivers/LwIP/src/include/netif;../Drivers/LwIP/src/include/arch;../Drivers/LwIP/port;../App
|
||||
|
||||
========================================
|
||||
二、添加源文件分组 (Source Groups)
|
||||
========================================
|
||||
|
||||
在 Project 窗口中右键 -> Add Group,创建以下分组并添加文件:
|
||||
|
||||
【1】Drivers/CH390
|
||||
添加文件:
|
||||
- ../Drivers/CH390/CH390.c
|
||||
- ../Drivers/CH390/CH390_Interface.c
|
||||
|
||||
【2】Drivers/LwIP/core
|
||||
添加文件:
|
||||
- ../Drivers/LwIP/src/core/def.c
|
||||
- ../Drivers/LwIP/src/core/dns.c
|
||||
- ../Drivers/LwIP/src/core/inet_chksum.c
|
||||
- ../Drivers/LwIP/src/core/init.c
|
||||
- ../Drivers/LwIP/src/core/ip.c
|
||||
- ../Drivers/LwIP/src/core/mem.c
|
||||
- ../Drivers/LwIP/src/core/memp.c
|
||||
- ../Drivers/LwIP/src/core/netif.c
|
||||
- ../Drivers/LwIP/src/core/pbuf.c
|
||||
- ../Drivers/LwIP/src/core/raw.c
|
||||
- ../Drivers/LwIP/src/core/stats.c
|
||||
- ../Drivers/LwIP/src/core/sys.c
|
||||
- ../Drivers/LwIP/src/core/tcp.c
|
||||
- ../Drivers/LwIP/src/core/tcp_in.c
|
||||
- ../Drivers/LwIP/src/core/tcp_out.c
|
||||
- ../Drivers/LwIP/src/core/timeouts.c
|
||||
- ../Drivers/LwIP/src/core/udp.c
|
||||
|
||||
IPv4 支持(在 core/ipv4 子目录):
|
||||
- ../Drivers/LwIP/src/core/ipv4/autoip.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/dhcp.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/etharp.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/icmp.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/igmp.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/ip4.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/ip4_addr.c
|
||||
- ../Drivers/LwIP/src/core/ipv4/ip4_frag.c
|
||||
|
||||
【3】Drivers/LwIP/api
|
||||
添加文件:
|
||||
- ../Drivers/LwIP/src/api/api_lib.c
|
||||
- ../Drivers/LwIP/src/api/api_msg.c
|
||||
- ../Drivers/LwIP/src/api/err.c
|
||||
- ../Drivers/LwIP/src/api/netbuf.c
|
||||
- ../Drivers/LwIP/src/api/netdb.c
|
||||
- ../Drivers/LwIP/src/api/netifapi.c
|
||||
- ../Drivers/LwIP/src/api/sockets.c
|
||||
- ../Drivers/LwIP/src/api/tcpip.c
|
||||
|
||||
【4】Drivers/LwIP/netif
|
||||
添加文件:
|
||||
- ../Drivers/LwIP/src/netif/ethernetif.c
|
||||
|
||||
【5】Drivers/LwIP/port
|
||||
添加文件:
|
||||
- ../Drivers/LwIP/port/sys_arch.c
|
||||
|
||||
【6】App
|
||||
添加文件:
|
||||
- ../App/tcp_server.c
|
||||
- ../App/tcp_client.c
|
||||
- ../App/uart_trans.c
|
||||
- ../App/config.c
|
||||
- ../App/flash_param.c
|
||||
|
||||
========================================
|
||||
三、预处理器宏定义 (Preprocessor Defines)
|
||||
========================================
|
||||
|
||||
打开 Keil -> Project -> Options for Target -> C/C++ -> Define
|
||||
|
||||
保持现有定义,不需要额外添加:
|
||||
USE_HAL_DRIVER,STM32F103xB
|
||||
|
||||
========================================
|
||||
四、编译优化设置
|
||||
========================================
|
||||
|
||||
建议设置:
|
||||
- Optimization: Level 2 (-O2)
|
||||
- 勾选 "One ELF Section per Function"
|
||||
- Warning Level: All Warnings
|
||||
|
||||
========================================
|
||||
五、目标内存配置
|
||||
========================================
|
||||
|
||||
确认 ROM 和 RAM 配置正确:
|
||||
- IROM1: 0x08000000, Size: 0x10000 (64KB)
|
||||
- IRAM1: 0x20000000, Size: 0x5000 (20KB)
|
||||
|
||||
========================================
|
||||
六、编译验证
|
||||
========================================
|
||||
|
||||
配置完成后:
|
||||
1. 按 F7 编译整个工程
|
||||
2. 检查是否有编译错误
|
||||
3. 常见问题:
|
||||
- "file not found" -> 检查包含路径
|
||||
- "undefined reference" -> 检查是否添加了所有源文件
|
||||
- 链接错误 -> 检查 ROM/RAM 大小配置
|
||||
|
||||
========================================
|
||||
七、烧录配置
|
||||
========================================
|
||||
|
||||
Debug 选项卡:
|
||||
- 选择正确的调试器(ST-Link/J-Link)
|
||||
- 勾选 "Reset and Run"
|
||||
|
||||
Utilities 选项卡:
|
||||
- 选择正确的 Flash 算法
|
||||
- STM32F10x Med-density Flash (64KB)
|
||||
|
||||
========================================
|
||||
快速添加方法(可选)
|
||||
========================================
|
||||
|
||||
如果源文件太多手动添加麻烦,可以:
|
||||
|
||||
1. 在 Keil 中右键分组 -> Add Existing Files
|
||||
2. 选择 "All Files (*.*)"
|
||||
3. 导航到对应目录
|
||||
4. 按住 Ctrl 多选所有 .c 文件
|
||||
5. 点击 Add
|
||||
|
||||
========================================
|
||||
文件结构参考
|
||||
========================================
|
||||
|
||||
TCP2UART/
|
||||
├── App/
|
||||
│ ├── tcp_server.c/h
|
||||
│ ├── tcp_client.c/h
|
||||
│ ├── uart_trans.c/h
|
||||
│ ├── config.c/h
|
||||
│ └── flash_param.c/h
|
||||
├── Core/
|
||||
│ ├── Inc/
|
||||
│ └── Src/
|
||||
├── Drivers/
|
||||
│ ├── CH390/
|
||||
│ │ ├── CH390.c/h
|
||||
│ │ └── CH390_Interface.c/h
|
||||
│ ├── LwIP/
|
||||
│ │ ├── port/
|
||||
│ │ │ └── sys_arch.c
|
||||
│ │ └── src/
|
||||
│ │ ├── api/
|
||||
│ │ ├── core/
|
||||
│ │ │ └── ipv4/
|
||||
│ │ ├── include/
|
||||
│ │ │ ├── arch/
|
||||
│ │ │ │ ├── cc.h
|
||||
│ │ │ │ ├── lwipopts.h
|
||||
│ │ │ │ └── sys_arch.h
|
||||
│ │ │ ├── lwip/
|
||||
│ │ │ └── netif/
|
||||
│ │ └── netif/
|
||||
│ │ └── ethernetif.c/h
|
||||
│ └── STM32F1xx_HAL_Driver/
|
||||
├── MDK-ARM/
|
||||
│ └── TCP2UART.uvprojx
|
||||
└── Middlewares/
|
||||
└── Third_Party/FreeRTOS/
|
||||
|
||||
========================================
|
||||
Reference in New Issue
Block a user