feat: 完成TCP2UART透传核心集成

集成CH390驱动、LwIP协议栈和FreeRTOS多任务透传框架,确保TCP Server/Client与UART链路按配置稳定联动。
This commit is contained in:
2026-03-30 11:39:40 +08:00
parent d5803ca7dd
commit 4996b451d9
235 changed files with 80607 additions and 27 deletions
+307
View File
@@ -0,0 +1,307 @@
/**
* @file lwipopts.h
* @brief LwIP configuration for STM32F103 + FreeRTOS + CH390 Ethernet
*
* This configuration is optimized for:
* - STM32F103 with limited RAM (~20KB available)
* - FreeRTOS integration (NO_SYS=0)
* - TCP Server + Client dual link transparent transmission
* - CH390 Ethernet controller
*/
#ifndef LWIP_LWIPOPTS_H
#define LWIP_LWIPOPTS_H
/*-----------------------------------------------------------------------------
* Platform and OS Options
*---------------------------------------------------------------------------*/
/* Use FreeRTOS - this enables the sequential API (netconn, sockets) */
#define NO_SYS 0
/* Enable socket API */
#define LWIP_SOCKET 1
#define LWIP_NETCONN 1
#define LWIP_NETIF_API 0
/* Critical section protection */
#define SYS_LIGHTWEIGHT_PROT 1
/* Use FreeRTOS memory allocation */
#define MEM_LIBC_MALLOC 0
#define MEMP_MEM_MALLOC 0
/*-----------------------------------------------------------------------------
* Memory Configuration (optimized for STM32F103 with ~20KB RAM)
*---------------------------------------------------------------------------*/
/* Memory alignment (ARM Cortex-M3 = 4 byte alignment) */
#define MEM_ALIGNMENT 4
/* Heap size for dynamic memory allocation */
#define MEM_SIZE (4 * 1024) /* 4KB for LwIP heap */
/* Number of pbufs in pool */
#define PBUF_POOL_SIZE 8
/* Size of each pbuf in pool (must hold one Ethernet frame) */
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)
/* Number of memp struct pbufs */
#define MEMP_NUM_PBUF 8
/* Number of raw PCBs */
#define MEMP_NUM_RAW_PCB 2
/* Number of UDP PCBs */
#define MEMP_NUM_UDP_PCB 4
/* Number of simultaneously active TCP connections */
#define MEMP_NUM_TCP_PCB 4
/* Number of listening TCP connections */
#define MEMP_NUM_TCP_PCB_LISTEN 2
/* Number of simultaneously queued TCP segments */
#define MEMP_NUM_TCP_SEG 12
/* Number of simultaneously active timeouts */
#define MEMP_NUM_SYS_TIMEOUT 8
/* Number of netbufs (for sequential API) */
#define MEMP_NUM_NETBUF 4
/* Number of netconns */
#define MEMP_NUM_NETCONN 6
/* TCPIP message queue size */
#define MEMP_NUM_TCPIP_MSG_API 8
#define MEMP_NUM_TCPIP_MSG_INPKT 8
/*-----------------------------------------------------------------------------
* IP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_IPV4 1
#define LWIP_IPV6 0
/* No IP forwarding (single interface device) */
#define IP_FORWARD 0
/* IP fragment reassembly */
#define IP_REASSEMBLY 0
#define IP_FRAG 0
/* IP options processing */
#define IP_OPTIONS_ALLOWED 1
/*-----------------------------------------------------------------------------
* ICMP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_ICMP 1
#define ICMP_TTL 255
/*-----------------------------------------------------------------------------
* ARP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_ARP 1
#define ARP_TABLE_SIZE 10
#define ARP_QUEUEING 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
/*-----------------------------------------------------------------------------
* DHCP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_DHCP 1
#define DHCP_DOES_ARP_CHECK 1
/*-----------------------------------------------------------------------------
* UDP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_UDP 1
#define UDP_TTL 255
/*-----------------------------------------------------------------------------
* TCP Configuration (optimized for transparent transmission)
*---------------------------------------------------------------------------*/
#define LWIP_TCP 1
#define TCP_TTL 255
/* TCP Maximum Segment Size */
#define TCP_MSS 536 /* Conservative value for compatibility */
/* TCP sender buffer space (bytes) */
#define TCP_SND_BUF (4 * TCP_MSS)
/* TCP sender buffer space (pbufs) */
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
/* TCP receive window */
#define TCP_WND (4 * TCP_MSS)
/* TCP writable space threshold */
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1)
/* Enable TCP keepalive */
#define LWIP_TCP_KEEPALIVE 1
/* TCP segment queue handling */
#define TCP_QUEUE_OOSEQ 0 /* Disable out-of-order segment queuing to save RAM */
/* Maximum number of retransmissions */
#define TCP_MAXRTX 12
#define TCP_SYNMAXRTX 6
/* TCP listen backlog */
#define TCP_LISTEN_BACKLOG 1
/* TCP timestamp option */
#define LWIP_TCP_TIMESTAMPS 0
/*-----------------------------------------------------------------------------
* RAW API (used for ping, etc.)
*---------------------------------------------------------------------------*/
#define LWIP_RAW 1
/*-----------------------------------------------------------------------------
* DNS Configuration
*---------------------------------------------------------------------------*/
#define LWIP_DNS 0 /* Disable DNS to save RAM */
/*-----------------------------------------------------------------------------
* IGMP Configuration
*---------------------------------------------------------------------------*/
#define LWIP_IGMP 0 /* Disable IGMP to save RAM */
/*-----------------------------------------------------------------------------
* Callback Configuration
*---------------------------------------------------------------------------*/
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
/*-----------------------------------------------------------------------------
* Checksum Configuration
*---------------------------------------------------------------------------*/
/* Use software checksums (CH390 doesn't have checksum offload) */
#define CHECKSUM_GEN_IP 1
#define CHECKSUM_GEN_UDP 1
#define CHECKSUM_GEN_TCP 1
#define CHECKSUM_GEN_ICMP 1
#define CHECKSUM_CHECK_IP 1
#define CHECKSUM_CHECK_UDP 1
#define CHECKSUM_CHECK_TCP 1
#define CHECKSUM_CHECK_ICMP 1
/*-----------------------------------------------------------------------------
* Statistics (disabled to save RAM)
*---------------------------------------------------------------------------*/
#define LWIP_STATS 0
#define LWIP_STATS_DISPLAY 0
/*-----------------------------------------------------------------------------
* Debug Options (disabled for production)
*---------------------------------------------------------------------------*/
#define LWIP_DEBUG 0
#if LWIP_DEBUG
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define IGMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TIMERS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#endif /* LWIP_DEBUG */
/*-----------------------------------------------------------------------------
* FreeRTOS Specific Options
*---------------------------------------------------------------------------*/
/* Task stack sizes */
#define TCPIP_THREAD_STACKSIZE 512
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
#define DEFAULT_THREAD_STACKSIZE 256
#define DEFAULT_THREAD_PRIO (configMAX_PRIORITIES - 3)
/* Mailbox sizes */
#define TCPIP_MBOX_SIZE 8
#define DEFAULT_RAW_RECVMBOX_SIZE 4
#define DEFAULT_UDP_RECVMBOX_SIZE 4
#define DEFAULT_TCP_RECVMBOX_SIZE 8
#define DEFAULT_ACCEPTMBOX_SIZE 4
/* Thread name length */
#define LWIP_NETCONN_SEM_PER_THREAD 1
/*-----------------------------------------------------------------------------
* Ethernet Specific
*---------------------------------------------------------------------------*/
/* Ethernet MTU */
#define LWIP_ETHERNET 1
/* Link layer header overhead */
#define PBUF_LINK_HLEN 14 /* Ethernet header size */
#define PBUF_LINK_ENCAPSULATION_HLEN 0
/* Use static Ethernet address (configured at runtime) */
#define LWIP_NETIF_HOSTNAME 1
/*-----------------------------------------------------------------------------
* Socket Options
*---------------------------------------------------------------------------*/
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVBUF 0
#define SO_REUSE 1
/*-----------------------------------------------------------------------------
* Additional Options
*---------------------------------------------------------------------------*/
/* Enable loop interface for testing */
#define LWIP_HAVE_LOOPIF 0
#define LWIP_NETIF_LOOPBACK 0
/* Random number generator (required for some TCP operations) */
#define LWIP_RAND() ((uint32_t)rand())
#endif /* LWIP_LWIPOPTS_H */