Skip to content

UIAPduino Pro Micro CH32V003 V1.3Beta

New version is available.

The manual of V1.3 is not in maintained. If you have any previous version, and you would like to exchange to the new version, UIAP will ship you the latest product. Go V1.4!

V1.3 is beta edition that may have any hardware defects. Known issues:

  • プルアップ抵抗R2は回路図通りの3.3Vではなく5Vへ接続されています。
  • シルクに見えづらい部分があります。読み取れない場合はボードイメージを参照してください。
  • D+(+3.3V)、D-(+3.3V)がUSB規格のHigh論理電位を厳密に満足しません。低すぎます。
  • D+(+3.3V)、D-(+3.3V)とマイコンポートとの接続がcnlohr/rv003usbと反対です。

いずれの不具合も致命的ではなく、意図通りに動作するケースが確認されています。

V1.3外観V1.3動作状態

Overview

  • Adopt CH32V003 Running at 24 MHz, And Support Coding in Arduino IDE.
  • Supply Power and Write Program with Single USB Type-C.
  • Act as a USB 2.0 Low-speed Device, Which Means the HID Device Can Be Made.
  • Protect Your USB Port by On Board Fuses Powerfully.
  • Is Selectable That the Microcontroller Power Supply Is from 3.3 V or 5 V.
  • Can Be Mounted by H: 2.0 mm / P: 2.54 mm ConthroughⓇ (Only Low-Profile Edition).
  • Are Open-source Software and Open-source Hardware.
  • Is Lifetime Warranty.

クロック周波数は不具合の暫定対策として24MHzです。将来的に48MHzへ変更されます。

Getting Started

LEDを点滅させるプログラム(スケッチ)を書き込み、ボード上でLEDが点滅することを確認します。

手順で示されるまでボードをUSBポートへ接続してはいけません。短絡リスクを低減するためです。

動作確認環境

Windows

前提条件

バイナリファイル出力

Arduino IDEを起動し、ファイル -> 基本設定 -> 追加のボードマネージャのURL にhttps://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.jsonを追記します。ツール -> ボード -> ボードマネージャ でch32と検索し、CH32 MCU EVT Boards by WCH1.0.3をインストールします。

CH32 MCU EVT Boards by WCH 1.0.4不具合でWindowsのArduino IDEへインストールできません。

ツール -> ボード -> CH32 MCU EVT Boards -> CH32V00xを選択します。他の設定項目は全てデフォルトです。ファイル -> スケッチ例 -> 01.Basics -> Blink でLEDを点滅させるサンプルスケッチを開きます。setup()の前に#define LED_BUILTIN 2を追記し、Arduinoフォルダへ同名のBlinkで名前をつけて保存します。

cpp
// Define on board LED pin before setup()
#define LED_BUILTIN 2

// the setup function runs once when you press reset or power the board
void setup() {
...

スケッチ -> コンパイル済みバイナリをエクスポート と操作し、コンパイル完了と表示されることを確認します。コンパイル完了と表示されない場合は手順を見直します。 コンパイル完了表示

コンパイルが完了するとスケッチフォルダへバイナリファイルが出力されます。Blink -> build -> WCH.ch32v.CH32V00x_EVT -> Blink.ino.bin がバイナリファイルです。 バイナリファイル出力結果

書き込みの前に

書き込みツールを準備します。GitHubのcnlohr/ch32v003funリポジトリからminichlinklibusb-1.0.dllをダウンロード(警告される場合があります)し、任意のフォルダへ保存します。本説明ではDownloads(設定によってはダウンロードです)としています。先に出力したバイナリファイルBlink.ino.binをツールと同じフォルダへコピーします。 3ファイルが同一のフォルダ内にある

バイナリファイルの書き込み

ボードをパソコンのUSBポートへ接続し、コマンドプロンプトを開きます。 コマンドプロンプト

cd Downloadsと入力しEnterキーを押してDownloadsフォルダへ移動します。同様にminichlink.exe -w Blink.ino.bin flashと入力しEnterキーを押すと書き込みが開始され、Interface Setupと表示されるのでしばらく待ちます。 Interface Setup表示状態

Image writtenと表示されたら書き込み完了です。 Image written表示状態

これら煩雑な手順はV1.4以降で改善されます。

動作確認

プログラムを実行するにはAとBの2つの方法があります。

  1. リセットボタンを押します。(Low-Profile Editionにリセットボタンはありません。)
  2. パソコンのUSBポートからボードを外し、市販のUSB充電器(ACアダプタ)へ接続します。

どちらか一方の手順でボード中央のオレンジ色ダイオードが1秒ごとに点灯/消灯を繰り返していれば正常動作です。再度プログラムを書き込むにはUSBポートへ挿し直す必要があります。

USBポートへの挿し直しをせずにモード切り替え(シームレススイッチ)する方法もあります。

Linux

Windowsの項目を参考にしてください。

Documents

Schematic of the PCBPCB LayoutDownload Eagle Project

Pinout Diagram

Pinout Diagram

Arduino IDEでのポート名称の定義はopenwch/arduino_core_ch32variant_CH32V003F4.hvariant_CH32V003F4.cppを参照しています。

Knowledge

Factory Default

出荷時にcnlohr/rv003usbブートローダをカスタムしたものが書き込まれています。

c
#define SYSTEM_CORE_CLOCK 48000000
#define SYSTEM_CORE_CLOCK 24000000

#define BOOTLOADER_TIMEOUT_PWR 67
#define BOOTLOADER_TIMEOUT_PWR 3

//#define BOOTLOADER_TIMEOUT_USB 0
#define BOOTLOADER_TIMEOUT_USB 0
c
#define USB_PIN_DP 3   // [0-4] GPIO Number for USB D+ Pin
#define USB_PIN_DM 4   // [0-4] GPIO Number for USB D- Pin
#define USB_PIN_DP 4   // [0-4] GPIO Number for USB D+ Pin
#define USB_PIN_DM 3   // [0-4] GPIO Number for USB D- Pin

#define USB_PIN_DPU 5  // [0-7] GPIO for feeding the 1.5k Pull-Up on USB D- Pin; Comment out if not used / tied to 3V3!
// #define USB_PIN_DPU 5  // [0-7] GPIO for feeding the 1.5k Pull-Up on USB D- Pin; Comment out if not used / tied to 3V3!

Seamless Switch

書き込み待機モードとプログラム実行モードとをUSBポートへの挿し直しをせずに切り替え(シームレススイッチ)します。これら以外にもシームレススイッチできる仕組みがあるかも知れません。

By Reset Button

スケッチのsetup()に4行のコードを追記するとリセットボタンでシームレススイッチします。

cpp
// the setup function runs once when you press reset or power the board
void setup() {
  if (FLASH->STATR & (1<<14)) NVIC_SystemReset();
  SystemReset_StartMode(Start_Mode_BOOT);
  pinMode(PD3, OUTPUT);
  digitalWrite(PD3, LOW);
...

By USB Host

ボードは、電源ON直後にUSBホストから通信があると書き込み待機モードになり、通信がないとプログラム実行モードになります。USBホストの給電と通信を有効化/無効化すると、物理的な操作をせずにシームレススイッチします。

bash
# This code ran on Raspberry Pi 3 Model B Plus Rev 1.3, Actually.
# For installation, refer to https://github.com/billauer/hubpower

# Go Run-Mode
sudo uhubctl -l 1-1 -p 2 -a 0 # Bus power off
sudo hubpower 1:3 power 2 off # Disable signal from host
sudo uhubctl -l 1-1 -p 2 -a 1 # Bus power on

# Go Boot-Mode
sudo uhubctl -l 1-1 -p 2 -a 0 # Bus power off
sudo hubpower 1:3 power 2 on  # Enable signal from host
sudo uhubctl -l 1-1 -p 2 -a 1 # Bus power on

USBホストの給電を有効化/無効化するにはUSBハブがpower switchingに対応している必要があります。

Anti Dazzling

夜間のベッドルームなどではLEDが眩しく感じます。ボード内のLEDはジャンプパッドをカットすることで消灯できます。

FunctionColorSchematicJump PadDescription
Power onBlueLED1CUT1
USB signalOrangeLED2CUT2Be unwritable when cut.
Builtin LEDOrangeLED3No PadV1.4 or later will support.

V1.4以降ではCUT2がカットされても書き込み可能のままになる予定です。

Application Example

WS2812B Lighting

https://github.com/cnlohr/ch32v003fun/tree/master/examples/ws2812bdemo

Using Arduino Library

動作したArduinoライブラリとその時のスケッチです。

SevSeg

Show Arduino Sketch
cpp
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment object

void setup() {
  byte numDigits = 1;
  byte digitPins[] = {1};
  byte segmentPins[] = {3, 4, 2, 5, 9, 7, 8, 10};
  bool resistorsOnSegments = true; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
}

void loop() {
  sevseg.blank();
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(0, 0);  
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(1, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(2, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(3, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(4, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(5, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(6, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(7, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(8, 0);
  sevseg.refreshDisplay();
  delay(1000);
  sevseg.setNumber(9, 0);
  sevseg.refreshDisplay();
  delay(1000);
}

Reference

CH32V003

Tips

DIY

Development Stack

With USB

With Arduino IDE

With Rust

Pro Micro

USB

Thank You for

Review

Suggestion

  • Masashi Sasaki
  • Kojo Kimura
  • Tomoyuki Dansako

Character Design

  • Yuto
Last Updated 2024/09/15