cnlohr / ch32v003fun

Open source minimal stack for the ch32 line of WCH processors, including the ch32v003, a 10¢ 48 MHz RISC-V Microcontroller - as well as many other chips within the ch32v/x line.
MIT License
916 stars 143 forks source link

Printf over SWIO? #334

Closed Rockwell1799 closed 3 months ago

Rockwell1799 commented 3 months ago

Hello I have problem with Printf using SWIO.Using Printf over Uart is working fine. I have this line in my funconfig.h:

define FUNCONF_USE_DEBUGPRINTF 1

The problem, I have nothing coming in my Terminal. I think I'm missing something! Is there any connection I have to do before? If someone can help, it would be appreciated! Thank you in advance

eeucalyptus commented 3 months ago

Did you run the SystemInit() before printing? Also have you tried out the "debugprintfdemo" example?

Rockwell1799 commented 3 months ago

Yes, I run SystemInit(); this is my code:

`

SystemInit();
funGpioInitAll();

funPinMode( PC0, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP );

while(1)
{

    funDigitalWrite( PC0, FUN_HIGH );

    Delay_Ms( 100 );

    funDigitalWrite( PC0, FUN_LOW );

    Delay_Ms( 100 );
    printf("\n %d",count++);
}

}`

I haven't checked "debugprintfdemo" example yet, but I'm going to take a look at it now! Thank you

cnlohr commented 3 months ago
  1. What programmer are you using?
  2. Let us know when you get a chance to try the debugprintf example. You can run it with make clean all monitor and that will make sure to build from scratch.
Rockwell1799 commented 3 months ago

Hello 1-I have this programmer: Screenshot 2024-07-04 at 21-10-53 WCH LinkE Online Download Debugger Support WCH RISC-V Architecture MCU_SWD Interface ARM Chip 1 Serial Port to USB Channel - AliExpress

2-I tried the debugprintf example, but no joy!

maxgerhardt commented 3 months ago

I have nothing coming in my Terminal

Just to sanity check you, you open the SWIO (or, SDI) printf monitor by executing minichlink -T, yeah?

Rockwell1799 commented 3 months ago

minichlink -T

Sorry, my bad, I was using an external terminal viewer, but with minchlink it's working fine.

maxgerhardt commented 3 months ago

And for completeness' sake: If you have a WCH-LinkE, you can actually make the SDI printfs show up in the regular COM port and thus your terminal viewer, with a special feature from the wlink program: Just use wlink sdi-print enable. Not sure if it persists across replugging the WCH-LinkE though.

And yeah the -T or "SDI printf monitor" is quite hidden in the README section (https://github.com/cnlohr/ch32v003fun?tab=readme-ov-file#a-fast-printf-debug-over-the-programming-interface)

Rockwell1799 commented 3 months ago

Thank you for the heads-up, it's very much appreciated

wanggaoteng commented 2 months ago

And for completeness' sake: If you have a WCH-LinkE, you can actually make the SDI printfs show up in the regular COM port and thus your terminal viewer, with a special feature from the wlink program: Just use wlink sdi-print enable. Not sure if it persists across replugging the WCH-LinkE though.

And yeah the -T or "SDI printf monitor" is quite hidden in the README section (https://github.com/cnlohr/ch32v003fun?tab=readme-ov-file#a-fast-printf-debug-over-the-programming-interface)

@maxgerhardt Hi, can you give me some instructions about how to get the "SDI printf monitor" ? I have click the "Enable SDI Printf" button on the left panel of vscode/platformio, and then execute the "minichlink -T" in the terminal, but get: image Does my operation is wrong?

cnlohr commented 2 months ago

@wanggaoteng Please follow the directions here https://github.com/cnlohr/ch32v003fun/wiki/Installation#windows and install the drivers for the wch link e.

cnlohr commented 2 months ago

I added an extra warning with that link if that event happens to future users. https://github.com/cnlohr/ch32v003fun/commit/50ce2c924b5d3926ecc7a1578c3f6a4cd00e37c3

wanggaoteng commented 2 months ago

@wanggaoteng Please follow the directions here https://github.com/cnlohr/ch32v003fun/wiki/Installation#windows and install the drivers for the wch link e.

Thank you @cnlohr

wanggaoteng commented 2 months ago

@wanggaoteng Please follow the directions here https://github.com/cnlohr/ch32v003fun/wiki/Installation#windows and install the drivers for the wch link e.

Hi, @cnlohr I use zadig to install WinUSB to the WCH-Link interface 0, then, sdi printf works, messages printed in the serial monitor. But...errors appeared when clicking the upload button of vscode/platformio: image I'm very frustrated by this error, it prevents me upload anything to the target chip (ch32v003), can you give me some instructions ?

maxgerhardt commented 2 months ago

Set

upload_protocol = minichlink

In the platformio.ini.

After you changed the drivers to WinUSB/libusb, WCH's openocd version can't speak to the programmer anymore.

wanggaoteng commented 2 months ago

upload_protocol = minichlink

Thank you @maxgerhardt It works. But...can you give me some instructions about how to change the driver (now it is winusb) to the old one (namely, the driver before winusb)? According to the figure below, there are 3 drivers when clicking the downward triangle in the red circle, such as libusb-win32, libusbk, USB Serial (CDC). I try to change winusb to one of them, hope to get the old one, but the errors appeared when clicking the upload button everytime. image image

cnlohr commented 2 months ago

@maxgerhardt is there a reasonable way to "guess" which interface to use?

@wanggaoteng You will need to remove the driver and install the one from WCH. But also, why do you need their tool?

maxgerhardt commented 2 months ago

To get back to MounRiver drivers, you can open your Windows Device Manager, use View -> Device by Container, then search for your WCHLink device, then use "Update Drivers" with the target path of C:\MounRiver\MounRiver_Studio\LinkDrv\WCHLink (assuming you have a regular MounRiver installation)

grafik

Mhm the interface driver is not that simple.. Since each method has different capabilities as of now

wanggaoteng commented 2 months ago

To get back to MounRiver drivers, you can open your Windows Device Manager, use View -> Device by Container, then search for your WCHLink device, then use "Update Drivers" with the target path of C:\MounRiver\MounRiver_Studio\LinkDrv\WCHLink (assuming you have a regular MounRiver installation)

grafik

Mhm the interface driver is not that simple.. Since each method has different capabilities as of now

  • WCH's OpenOCD version can only interact with the WCH driver for the WCHLinkE and can flash and debug and decode SDI prints in the style of their SDK, not ch32v003fun, when nudged to do so via wlink
  • minichlink can only interact with the WinUSB driver for the WCHLinkE and can flash and decode SDI prints in the style of ch32v003fun. (integration with the debugging capabilities is still not done, have to revisit after minichlink doesn't support gdb "load" #159 is now done)
  • interestingly, wlink can interact with the WCHLink in both driver flavors. I don't yet know how they do it.

Thank you a lot @maxgerhardt