项目介绍

loboris/GD32VF_USB_UART_BRIDGE 是一个托管在 GitHub 上的开源项目,主要使用 C 编写,目前获得 31 个 Star、3 次 Fork。

仓库全名
loboris/GD32VF_USB_UART_BRIDGE
Star 数
31
Fork 数
3

README 摘要

GD32VF103 USB to UART bridge This project shows how to use GD32VF103 board as USBtoUART bridge. The project is intended to be run on Longan Nano board. If testing on another board (without a display), edit lib/usbcdc/include/cdcacmcore.h to remove display and/or LED support. Features: The project implements USB CDC/ACM device with some additional features. Bridging USB to two UARTS is supported. Display support,…

完整内容见 GitHub 原始 README 或本页 。

常见问题

GD32VF_USB_UART_BRIDGE 用什么语言开发?

主要使用 C 编写,目前有 31 个 Star。

如何获取 GD32VF_USB_UART_BRIDGE 的源码?

可以直接克隆仓库:git clone https://github.com/loboris/GD32VF_USB_UART_BRIDGE.git,默认分支为 master;安装与运行步骤见仓库 README。

GD32VF_USB_UART_BRIDGE 最近还在维护吗?

仓库最近一次更新为 2020年1月27日,当前没有未关闭的 Issue;Star 数为 31,可作为社区活跃度的参考。

关于

USB to UART bridge for GD32VF103

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
41
价值分
19
活跃状态
活跃

README


GD32VF103 USB to UART bridge


This project shows how to use GD32VF103 board as USBtoUART bridge.

The project is intended to be run on Longan Nano board.
If testing on another board (without a display), edit lib/usbcdc/include/cdc_acm_core.h to remove display and/or LED support.

Features:

  • The project implements USB CDC/ACM device with some additional features.
  • Bridging USB to two UARTS is supported.
  • Display support, displays status and statistics.
  • Baudrates from 2400 ~ 4000000 Bd are supported
  • Python CDC driver with examples included

Pins used for UARTs:

UART0:

  • PA9 Tx
  • PA10 Rx
  • PA13 RTS
  • PA14 DTR

UART1:

  • PB10 Tx
  • PB11 Rx
  • PB13 RTS
  • PB14 DTR

Details

After the board is connected to PC it will be enumerated as USB device 28e9:018a.

Bus 003 Device 028: ID 28e9:018a  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x28e9 
  idProduct          0x018a 
  bcdDevice            1.00
  iManufacturer           1 GigaDevice
  iProduct                2 GD32VF USB CDC ACM in FS Mode
  iSerial                 3 GD32VF-3.0.0-012020
  bNumConfigurations      1
...

The device can be accessed for serial communication as /dev/ttyACMn, for example via Minicom, Putty etc.

[24377.013615] usb 3-9: new full-speed USB device number 28 using xhci_hcd
[24377.167007] usb 3-9: New USB device found, idVendor=28e9, idProduct=018a, bcdDevice= 1.00
[24377.167011] usb 3-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[24377.167013] usb 3-9: Product: GD32VF USB CDC ACM in FS Mode
[24377.167015] usb 3-9: Manufacturer: GigaDevice
[24377.167017] usb 3-9: SerialNumber: GD32VF-3.0.0-012020
[24377.168506] cdc_acm 3-9:1.0: ttyACM0: USB ACM device

As the device has some non-standard CDC features, it is recommended to use it via the provided Python driver cdc_driver.py.

Switching UARTS

GD32VF103 does not have enough USB endpoints to implement a composite CDC device.
The UART ports can be changed using one of two methods:

  • sending a break condition, this is usually used from standard communication program
  • sending a special CDC command, this is fully supported and described in cdc_driver.py

Notes

If Longan Nano is used and USE_LEDS is enabled in configuration, green LED will be active when UART1 is selected.

If Longan Nano is used and USE_DISPLAY is enabled in configuration, UART format and DTR/RTS status will be shown on display.
Special CDC command can be used to display the communication statistics (USB number of sent/received bytes, UART number of sent/received byted, number of UART receive errors,…).

DTR and RTS outputs can be configured as push-pull or open colector (UARTn_RTS_DTR_MODE define in lib/usbcdc/include/cdc_acm_core.h).

Using break for UART change can be disabled/enabled using UART_USE_BREAK_TO_CHANGE define in lib/usbcdc/include/cdc_acm_core.h.


Functions supported in cdc_driver.py:

# -------------------------------------------------------
# Show the current status on the device display (if used)
# If the 'reset' argument is 1, reset the counters
# -------------------------------------------------------
showStatus(reset = 0)

# -----------------------------------
# Set DTR and RTS line state
# -----------------------------------
setLineState(dtr=1, rts=1)

# ------------------------------------------------------
# Set active device UART, 0 or 1 can be used as argument
# ------------------------------------------------------
setUART(uartno=0)

# -----------------------------------------------------------
# Set the UART communication format
#    bdr: baudrate, 2400 - 4000000
#   bits: 8 or 7
# parity: 0 - None; 2 - Even, 3 - Odd
#   stop: number of stop bits; 0 = 1, 1 = 0.5, 2 = 2, 3 = 1.5
# -----------------------------------------------------------
setFormat(bdr=115200, bits=8, parity=0, stop=0)

# ----------------------------------------------------------
# Get the current UART communication format from the device
# If 'prn' argument is True, prints the format
# Returns tuple: (bdr, stop, parity, bits)
# ----------------------------------------------------------
getFormat(prn=False)

# --------------------------------------------
# Get the current transmition status
# If 'prn' argument is True, prints the status
# Returns tuple:
#   (
#    active_uart,
#    dtr_state,
#    rts_state,
#    usb_sent,
#    usb_received,
#    uart_sent,
#    uart_received,
#    uart_receive_errors
#   )
# --------------------------------------------
getStatus(prn=False)

# -------------------------------------------------
# Return number of received bytes in receive buffer
# -------------------------------------------------
received()

# ----------------------------------
# Read data from receive buffer
# count: max number of bytes to read
# Returns array of bytes
# ----------------------------------
read(count=1)

# -------------------------------------------------
# Read data from receive buffer converted to string
# count: max number of bytes to read
# -------------------------------------------------
readString(count=1)

# --------------------
# Write data
# --------------------
write(data)

评论

暂无评论