0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows & ch32vでdebug print

Posted at

概要

ch32vを使うときにdebug printをするまでの手順を備忘録として残します。

ch32vからprintをする方法は

  • SWDIOピンからdebug print
  • UARTのTXピンから print
  • USBからprint

の3つがあるようです。今回はSWDIOピンからのdebug printをします。

この記事を読まなくてもここに書いてあります。
https://github.com/cnlohr/ch32fun/wiki/Installation#windows

シリアルモニタの準備

minichlinkを使います1。PlatformIOを使っている場合はplatformio.iniのupload_protocol=minichlinkとすればインストールされます。手動で入れてもいいと思います。

WindowsにWCH-LinkEを接続した状態でminichlinkを使うとポートが開けないとエラーが出ます。そこで、ch32funのinstallationにある通り、Zadigを使ってWinUSBのドライバをWCH-Link(Interface 0)が接続されているUSBポートにインストールします。

Zadigを起動してすぐはデバイス一覧が表示されていないと思うのでOptionsから"List All Devices"を選ぶと下の画像のように一覧が出てくるのでWCH-Link (Interface 0)を選んでから WinUSBをinstallします。
image.png

WCH-LinkEとch32vの接続

以下の通りに接続してください。

WCH-LinkEのピン ch32vのピン
SWDIO/TMS SWDIO
SWCLK/TCK SWCLK
GND VSS
3V3 VDD

ch32vのDebug printのコード

ch32v003fun.hを使用します。

main.c
#include "ch32v003fun.h"
#include <stdio.h>

int main(){
    SystemInit();
    SetupDebugPrintf();

	while(1)
	{
		printf("Hello World\n");
		Delay_Ms(100);
	}
}
funconfig.h
#ifndef _FUNCONFIG_H
#define _FUNCONFIG_H

#define FUNCONF_USE_DEBUGPRINTF 1
#define FUNCONF_DEBUGPRINTF_TIMEOUT (1<<31) // Wait for a very very long time.

#endif

funconfig.hに関しては無くてもdebug printされましたが一応メモとして残します。

シリアルモニタを開く

minichlink -T

このコマンドで開けます。おそらくminichlinkへのパスが通っていないと思うのでパスを通すなり、minichlinkがあるディレクトリ上でコマンドを実行するなり、フルパスを指定するなりすればOKです。
PlatformIOでminichlinkをinstallした場合はC:\Users\[user name]\.platformio\packages\tool-minichlink\minichlink.exeにあります。

  1. pio device monitorでシリアルモニタを開いた場合はWCH-LinkEのRX, TXに入ってきたUART信号がUSB変換されたデータが出てくるので今回のdebug printをするのには使えません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?