WCH MCU
2026-06-1011 min read

Building an Industrial Gateway with CH32V307

Practical guide: 8 serial ports, dual CAN, Gigabit Ethernet, and Modbus TCP/RTU conversion on a $3 RISC-V chip.

CH32V307IndustrialGatewayModbusCANEthernet

Overview

The CH32V307 is WCH's industrial-grade connectivity MCU based on the QingKe V4F RISC-V core at 144MHz. With Gigabit Ethernet MAC, 8 serial ports, dual CAN, and rich analog peripherals, it's purpose-built for industrial gateway applications — all for about $3.

Key Features for Industrial Use

CoreQingKe V4F (RISC-V) @144MHz with FPU
Flash / SRAM256KB / 64KB
EthernetGigabit MAC (external PHY required)
Serial Ports3x USART + 5x UART = 8 total
CAN2x CAN 2.0B Active
ADC2 units, 16ch, 12-bit
DAC2 channels, 12-bit
USBUSB 2.0 FS OTG
Operating Temp-40C to +85C (industrial)

Gateway Architecture

A typical industrial gateway needs to:

  1. Collect data from serial devices (sensors, PLCs, meters)
  2. Bridge CAN bus networks
  3. Provide Ethernet uplink to SCADA/cloud
  4. Convert protocols (Modbus RTU <-> Modbus TCP)
  5. Monitor analog inputs

The CH32V307 can do ALL of this on a single chip:

Hardware Design

Ethernet Interface

CH32V307 has a Gigabit MAC but no built-in PHY. Use an external PHY like RTL8211F or use CH32V317 instead which has built-in 10/100M PHY. For Gigabit, connect via RGMII interface.

CAN Interface

Each CAN port needs an external transceiver (TJA1050 or SN65HVD230). Connect CAN_TX/CAN_RX pins to the transceiver, then to the CAN bus.

Serial Isolation

For industrial environments, use optocouplers (6N137) or digital isolators (ADuM1201) on serial and CAN lines for galvanic isolation.

Software Architecture

FreeRTOS Tasks:
  Task 1: UART data collection (8 ports)
  Task 2: CAN message routing
  Task 3: Modbus TCP server (lwIP)
  Task 4: Modbus RTU master/slave
  Task 5: ADC monitoring
  Task 6: Watchdog & diagnostics

Modbus TCP/RTU Bridge

The gateway receives Modbus TCP requests over Ethernet, converts them to Modbus RTU on serial ports, and returns the response. This is a common industrial use case.

// Simplified Modbus TCP -> RTU bridge
void modbus_bridge_task(void *pv) {
    while(1) {
        // Wait for TCP Modbus request
        mbap_header_t *req = wait_tcp_request();
        // Forward to appropriate UART (RTU)
        uint8_t slave_id = req->unit_id;
        uart_send(slave_uart[slave_id], req->data, req->len);
        // Wait for RTU response
        uint8_t resp[256];
        int len = uart_recv(slave_uart[slave_id], resp, 256, 1000);
        // Send back over TCP
        send_tcp_response(resp, len);
    }
}

Performance

Serial throughput (per port)Up to 3 Mbps
CAN throughputUp to 1 Mbps (CAN 2.0B)
Ethernet throughputUp to 100 Mbps (with external PHY)
Modbus transactions/s~1000+ (depending on slave response)
Power consumption~45uA/MHz (run mode)

Why CH32V307 vs STM32?

FeatureCH32V307STM32F407
Price~$3~$8
CoreRISC-V V4F @144MHzARM Cortex-M4 @168MHz
Serial Ports8 (3 USART + 5 UART)6 (3 USART + 3 UART)
CAN22
Ethernet MACGigabit10/100M
FPUSingle precisionSingle precision
Flash/SRAM256KB/64KB1MB/192KB
ISA LicenseOpen (RISC-V)Proprietary (ARM)

Resources