From 64bb06f292c5d5def968616d3f79cf99cc76646d Mon Sep 17 00:00:00 2001 From: kuwoyuki Date: Fri, 12 Dec 2025 23:05:27 +0600 Subject: [PATCH] fix: idk --- ch32fun | 2 +- inc/hw_i2c.h | 9 +++++---- port/ethernetif.c | 36 ++++++++++++++++-------------------- port/lwipopts.h | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/ch32fun b/ch32fun index d38b104..b076400 160000 --- a/ch32fun +++ b/ch32fun @@ -1 +1 @@ -Subproject commit d38b104838595e0203eed5a6067e83fe7fc56c8c +Subproject commit b0764004f578628ba40f5066cbe924eb57f58f90 diff --git a/inc/hw_i2c.h b/inc/hw_i2c.h index 6b2f5b9..659d3d1 100644 --- a/inc/hw_i2c.h +++ b/inc/hw_i2c.h @@ -150,10 +150,11 @@ static inline void i2c_init(void) { RCC->APB2PCENR |= RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO; RCC->APB1PCENR |= RCC_APB1Periph_I2C1; - // PB6 (SCL) and PB7 (SDA) - GPIOB->CFGLR &= ~(0xFF << (4 * 6)); - GPIOB->CFGLR |= ((GPIO_Speed_10MHz | GPIO_CNF_OUT_OD_AF) << (4 * 6)) | - ((GPIO_Speed_10MHz | GPIO_CNF_OUT_OD_AF) << (4 * 7)); + AFIO->PCFR1 |= AFIO_PCFR1_I2C1_REMAP; // I2C1_RM: 1 + + // PB8 (SCL) and PB9 (SDA) + funPinMode(PB8, GPIO_CFGLR_OUT_10Mhz_AF_OD); + funPinMode(PB9, GPIO_CFGLR_OUT_10Mhz_AF_OD); // Reset I2C1 to init all regs RCC->APB1PRSTR |= RCC_APB1Periph_I2C1; diff --git a/port/ethernetif.c b/port/ethernetif.c index 20e68c4..0dcc44e 100644 --- a/port/ethernetif.c +++ b/port/ethernetif.c @@ -70,6 +70,15 @@ err_t ethernetif_init(struct netif* netif) { static err_t low_level_output(struct netif* netif, struct pbuf* p) { (void)netif; + // single-segment pbuf + if (p->next == NULL && p->len <= ETH_TX_BUF_SIZE) { + if (eth_send_packet(p->payload, p->len) == 0) { + LINK_STATS_INC(link.xmit); + return ERR_OK; + } + } + + // chain of pbufs static uint8_t tx_buffer[ETH_TX_BUF_SIZE]; uint32_t total_len = 0; @@ -82,21 +91,13 @@ static err_t low_level_output(struct netif* netif, struct pbuf* p) { total_len += q->len; } - // send packet via driver - int result = eth_send_packet(tx_buffer, total_len); - - if (result == -1) { - // tx queue full - LINK_STATS_INC(link.drop); - return ERR_BUF; - } else if (result == -2) { - // invalid length - LINK_STATS_INC(link.err); - return ERR_ARG; + if (eth_send_packet(tx_buffer, total_len) == 0) { + LINK_STATS_INC(link.xmit); + return ERR_OK; } - LINK_STATS_INC(link.xmit); - return ERR_OK; + LINK_STATS_INC(link.drop); + return ERR_BUF; } void ethernetif_input(struct netif* netif) { @@ -108,13 +109,8 @@ void ethernetif_input(struct netif* netif) { struct pbuf* p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL); if (p != NULL) { - // copy packet into pbuf chain - uint32_t offset = 0; - for (struct pbuf* q = p; q != NULL; q = q->next) { - memcpy(q->payload, packet + offset, q->len); - offset += q->len; - } - + // usually contiguous in PBUF_POOL + pbuf_take(p, packet, length); LINK_STATS_INC(link.recv); // pass to lwIP diff --git a/port/lwipopts.h b/port/lwipopts.h index 7a57d25..26188cf 100644 --- a/port/lwipopts.h +++ b/port/lwipopts.h @@ -11,7 +11,7 @@ // #define ETHARP_DEBUG LWIP_DBG_ON #define NO_SYS 1 -#define SYS_LIGHTWEIGHT_PROT 1 +#define SYS_LIGHTWEIGHT_PROT 0 #define LWIP_NETCONN 0 #define LWIP_SOCKET 0