Has anyone else tried using the Weact CH32X035 board? I'm interested in using it for its USB-PD sink abilities. However, while I can program it and get a blinky to work, I cannot seem to send to find a way to send output to the serial monitor. The board is connected via a WCH Link-E programmer.
If anyone else has this board, and can give me some clue as to how to get output to the serial monitor, I'd be grateful. Thanks.
I have the WeAct board. CDC is not ported (yet) to CH32X035. When you look at the "issue" list on github you'll find a patchset from september that enables TinyUSB for the board, but AFAICT the code in the Adafruit library is not yet complete --> you get a bunch of errors - I did not have the time to trace that.
For USB-PD only (without CDC) you'll need WCH arduino core "main" branch and not "1.0.4".
Thanks. I already have the USB-PD working (without printf).
However, I'm not at this stage trying to use the CH32x035's USB port for serial - I am using the wch-link-e programmer to upload the sketch, and that is where I want my serial output to go...
Hi @ralphrmartin. The WCH-Link programmers have RX and TX pins, and act as a USB to serial bridge adapter in addition to the primary function as a debug probe/programmer.
So it should be possible to do this by simply connecting the TX pin on the WCH-Link to the USART RX pin on the CH32X035 board and the RX pin on the WCH-Link to the USART TX pin on the CH32X035. Then select the serial port produced by the WCH-Link from Arduino IDE's Tools > Port menu.
I do have a CH32V003 board on hand, but haven't found the time to familiarize myself with it yet. And I don't have any experience with the CH32X035 either. So I don't know what needs to be done in terms of the Arduino sketch code in order to use the USART, but I have verified that the WCH-Link (I have the model marked "WCH-LinkE-RO-1v3") works just as I described as a USB to serial bridge adapter.
Thanks for those last 2 answers. This is indeed what I have been trying, but it does not work. Maybe my board is faulty? Zwieblum, have you actually tried this for real, with this particular Weact board? The reason I ask is below:
I selected the CH32X035G8U board, as it is the only choice for a CH32X035 board, even though it is a different board to the Weact one.
On looking at the sources for the WCH32x035 core, the file for variant_CH32X035G8U.h says
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 1
#endif
// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PB11
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PB10
#endif
However the Weact board has no physical pins for PB10 and PB11, so I tried using PA2 and PA3, with no success. File PeripheralPins.c indicates that PA2 and PA3 are connected to USART2 while PB10 and PB11 are connected to USART1.
So, I believe I need to tell my sketch to use USART2 instead of USART1 somehow. Does this need the creation of a whole new board variant? Or is there some way to do this from inside my sketch?
I tried this with the main branch from github (and with v 1.0.4), and then tried printing to Serial2, but I still get no output (with PA2 and PA3 connected to the Link-E RX and TX ports.
Summary for anyone who doesn't want to read the whole thread:
Download the latest CH32 core, unzip it and replace corresponding files in the arduino packages/WCH/hardware/ch32v/1.0.x/ folder with the unzipped ones..
Edit variants/CH32X035G8U/variant_CH32X035G8U.h to replace the code that looks similar to the below but refers to SERIAL_UART_INSTANCE 1 to say
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 2
#endif
// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA3
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA2
#endif
[/quote]
Connect pins RA2 , RA3 to RX and TX of the WCHLink-E respectively.
Now you can use Serial as expected, with the serial monitor.
[Keep reading below - the latest core today also breaks USB_PD, unfortunately].
This solution has the unfortunate side effect of breaking the USB_PD example, which was working with an unchanged v 1.0.4 (apart from the serial output!), as now it gives compilation errors:
HardwareTimer.cpp:(.text.TIM3_IRQHandler+0x0): multiple definition of TIM3_IRQHandler'`
/Users/ralph/Library/Arduino15/packages/WCH/tools/riscv-none-embed-gcc/8.2.0/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: /Users/ralph/Library/Caches/arduino/cores/4bc2b5ff1fea33627510baec3699fa75/core.a(HardwareTimer.cpp.o): in function TIM3_IRQHandler': HardwareTimer.cpp:(.text.TIM3_IRQHandler+0x0): multiple definition of TIM3_IRQHandler'; /Users/ralph/Library/Caches/arduino/sketches/F458F1554934B9A4D499223271D0F159/libraries/USBPD_SINK/usbpd_sink.c.o:usbpd_sink.c:(.text.TIM3_IRQHandler+0x0): first defined here
collect2: error: ld returned 1 exit status