Giter Club home page Giter Club logo

ch32-pio-projects's Introduction

CH32 PlatformIO Projects

Smoke-test examples GitHub pull-requests GitHub issues

Description

This repository contains a collection of example projects to be used with the newly developed CH32V PlatformIO integration.

The examples range from using the NoneOS SDK over to FreeRTOS and TencentOS projects and more.

General Usage Notes

As these are PlatformIO projects, the PlatformIO documentation at https://docs.platformio.org/ always applies. Especially useful are the Getting started with VSCode + PlatformIO, CLI reference and platformio.ini options pages.

Installing the CH32V Platform

It is assumed that you have either installed VSCode + PlatformIO or PlatformIO on the CLI following the documentation above.

Open VSCode, expand the PlatformIO sidebar (ant icon) and click "PIO Home".

pio home

In the resulting PIO Home window, click on the "Platforms" sidebar and chose "Advanced Installation"

platform install

You will be asked for a repistory. Enter the URL and press "Install".

https://github.com/Community-PIO-CH32V/platform-ch32v.git

platform install 2

The platform should now be successfully installed.

Experienced PlatformIO CLI users can also use the short-hand command

pio pkg install -g -p https://github.com/Community-PIO-CH32V/platform-ch32v.git

Updating the CH32V Platform

Inevitibly, the platform version you installed at one point will become outdated.

There are two ways to update:

Update via PlatformIO Home GUI

The PIO Home -> Platforms screen lists all installed platforms. This can be filtered by CH32. If a (git) update is available, there will be an "Update" button available.

ch32 platform

Update via PlatformIO Core CLI

In the PlatformIO CLI, execute

pio pkg update -g -p https://github.com/Community-PIO-CH32V/platform-ch32v.git

Importing Examples

Clone this repository in an arbitrary folder.

git clone https://github.com/Community-PIO-CH32V/ch32-pio-projects

When using VSCode, open the PIO Home screen, e.g. via the toolbar. Use the "Open Project" open to navigate to one of the projects in the repository that you just cloned, e.g., blinky-none-os.

open project open folder

After opening the project, trust the VSCode workspace in the popup dialog. Your workspace should now contain the new project.

Board selection

The available boards for an example are listed in the platformio.ini file of the project. For each board, there is an [env:board] section describing the build parameters. Refer to the documentation linked above for detailed information.

For example, the blinky-none-os project contains

[env]
platform = ch32v
framework = noneos-sdk
monitor_speed = 115200

[env:ch32v003f4p6_evt_r0]
board = ch32v003f4p6_evt_r0

[env:genericCH32V003A4M6]
board = genericCH32V003A4M6

[env:genericCH32V103C6T6]
board = genericCH32V103C6T6

[env:genericCH32V203F6T6]
board = genericCH32V203F6T6

[env:genericCH32V208CBU6]
board= genericCH32V208CBU6

[env:ch32v307_evt]
board = ch32v307_evt
framework = arduino
#....

Thus all these chips / development boards are available.

The available board values are the boards available in the platform. Note that not every board supports every framework. The CH32V003 series does not support frameworks other than noneos-sdk due its small RAM and Flash sizes.

In VSCode, to select a certain board environment (and project), you must use the project environment switcher in the bottom blue taskbar. Make sure your wanted board and project are selected before continuing. After selecting a new environment, the IntelliSense will be reloaded, which might take a bit.

For CLI users, the target environment is given as the -e switch in the pio run command, see documentation.

Compiling

In VSCode, use the project tasks list in the left PIO sidebar as normal to trigger the "Build" action, or a different action, for a certain environment. The environment you have previously selected as your default will be the expanded one.

project tasks

For CLI users, executue the pio run -e <environment> command, as documentend above.

Compilation should result in a success, e.g.:

> pio run -e ch32v307_evt
Processing ch32v307_evt (board: ch32v307_evt; platform: ch32v; framework: noneos-sdk)
-----------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ch32v/ch32v307_evt.html
PLATFORM: WCH CH32V (1.0.0) > CH32V307 EVT
HARDWARE: CH32V307VCT6 144MHz, 32KB RAM, 288KB Flash
DEBUG: Current (wch-link) On-board (wch-link)       
PACKAGES:
 - framework-wch-noneos-sdk @ 2.10000.0+sha.afaf2a4 
 - tool-openocd-riscv-wch @ 2.1100.230103 (11.0)    
 - toolchain-riscv @ 1.80300.190927+sha.cb60df7
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\ch32v307_evt\FrameworkNoneOSCore\core_riscv.o
[..]
Indexing .pio\build\ch32v307_evt\libFrameworkNoneOSVariant.a
Linking .pio\build\ch32v307_evt\firmware.elf
Checking size .pio\build\ch32v307_evt\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.3% (used 2080 bytes from 32768 bytes)
Flash: [          ]   0.6% (used 1812 bytes from 294912 bytes)
Building .pio\build\ch32v307_evt\firmware.bin
================ [SUCCESS] Took 2.97 seconds ================

Uploading

Note that the default upload method and available upload method is listed in the board manifest, e.g. for the CH32V307EVT board, wch-link is the default, attempting to upload via a WCH-Link(E) probe connected to the chip via SWD (or the 1-pin interface used on CH32V003), using OpenOCD as tool. Uploading via the USB bootloader for the chips that have it (all but CH32V003) is also supported.

To change the upload method, change upload_protocol accordingly. SWD based upload methods can also be used as debug_tool for live-debugging. For USB bootloader upload, use upload_protocol = isp.

For VSCode users, use the project task "Upload".

For CLI users, use pio run -t upload -e <environment> as documented above.

Example of upload:

Configuring upload protocol...
AVAILABLE: wch-link
CURRENT: upload_protocol = wch-link
Uploading .pio\build\ch32v003f4p6_evt_r0\firmware.elf
Open On-Chip Debugger 0.11.0+dev-02415-gfad123a16-dirty (2023-01-03-10:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

Warn : Transport "sdi" was already selected
Ready for Remote Connections
[wch_riscv.cpu.0] Target successfully examined.
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
================= [SUCCESS] Took 2.37 seconds =================

Serial Monitor

For examples using serial output, you need to connect your WCH-Link(E)'s UART signals, or a USB-UART converter, to the target's UART pins to be able to observe it. For all chip series, when the debug.h code is used, this is by default UART1 on TX = PD5, RX = PD6. Note that the UART adapter and the target board should also share a common GND connection.

To access the serial montior in VSCode, execute the "Monitor" project task, as shown above.

To access it from the CLI, execute pio device monitor.

The monitor is aborted by pressing the standard Ctrl+C combination.

Settings like the baud rate or adapter to use (if not auto-detected) are to be found in the monitor section of the platformio.ini.

Example:

>  Executing task in folder uart-printf-none-os: C:\Users\Max\AppData\Roaming\Python\Python311\Scripts\platformio.exe run --target upload --target monitor --environment ch32v003f4p6_evt_r0 

--- Terminal on COM4 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
SystemClk: 48000000
DeviceID: 00000500
This is printf example
Program over, press reset button

Debugging

If a SWD capable debug probe is connected to the target, and configured via debug_tool, you can open the "Debug" sidebar in VSCode. In the upper left, the configuration "PIO Debug (your-project-name)" should be selected. By pressing the the "Play" button then, PlatformIO will start compiling the project in debug mode, start the debug server (e.g., OpenOCD) and connect to it with the appropriate GDB client.

Note: Currently, only the WCH-Link(E) is supported as debugging adapter.

It should hit a breakpoint in the main() function of the project (which can e.g. be in the Arduino core). From there, use the regular Step Over, Step Into, Step Out of, etc. buttons for debug control.

VSCode also shows the state of all peripheral registers (such as USART1, ADC0, etc.) and decodes them. The RISC-V core's internal registers are shown in the expandable "Registers" panel.

Note all the other possible debug configuration options.

debugging

The same can be achieved from the CLI, as documented. This launches the user into a GDB session.

> pio debug -e ch32v003f4p6_evt_r0 --interface=gdb -- -x .pioinit
C:\Users\Max\.platformio\packages\toolchain-riscv\bin\riscv-none-embed-gdb.exe: warning: Couldn't determine a path for the index cache directory.
Reading symbols from C:\Users\Max\Desktop\ch32_dev\platform-ch32v\examples\blinky-none-os\.pio\build\ch32v003f4p6_evt_r0\firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = wch-link
PlatformIO: Initializing remote target...
The target architecture is assumed to be riscv:rv32
Open On-Chip Debugger 0.11.0+dev-02415-gfad123a16-dirty (2023-01-03-10:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'sdi'
Warn : Transport "sdi" was already selected
Ready for Remote Connections
Info : tcl server disabled
Info : telnet server disabled
Info : WCH-LinkE  mode:RV version 2.8
Info : wlink_init ok
Info : clock speed 6000 kHz
Info : [wch_riscv.cpu.0] datacount=2 progbufsize=8
Info : [wch_riscv.cpu.0] Examined RISC-V core; found 1 harts
Info : [wch_riscv.cpu.0]  XLEN=32, misa=0x40800014
[wch_riscv.cpu.0] Target successfully examined.
Info : starting gdb server for wch_riscv.cpu.0 on pipe
Info : accepting 'gdb' connection from pipe
Info : device id = 0xabc8abcd
Info : flash size = 16kbytes
main () at src\main.c:23
23              NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Temporary breakpoint 1 at 0x47c: file src\main.c, line 22.
Info : [wch_riscv.cpu.0] Hart unexpectedly reset!
Loading section .init, size 0xa0 lma 0x0
Loading section .text, size 0x514 lma 0xc0
Loading section .data, size 0x18 lma 0x5d4
Info : Padding image section 0 at 0x000000a0 with 32 bytes
Info : [wch_riscv.cpu.0] Hart unexpectedly reset!
Start address 0x0, load size 1484
Transfer rate: 3 KB/sec, 494 bytes/write.
PlatformIO: Initialization completed
(gdb) PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Temporary breakpoint 1, main () at src\main.c:22
22      {
(gdb) backtrace
#0  main () at src\main.c:22
(gdb)

ch32-pio-projects's People

Contributors

maxgerhardt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ch32-pio-projects's Issues

Can't install the package

PIO Core Call Error: "Platform Manager: [email protected]+sha.40b43b1 is already installed\r\nTool Manager: Installing git+https://github.com/Community-PIO-CH32V/toolchain-riscv-windows.git\r\ngit version 2.36.1.windows.1\n\n\nCloning into 'C:\Users\Attiq\.platformio\.cache\tmp\pkg-installing-aky40fqp'...\nerror: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)\nerror: 7878 bytes of body are still expected\nfetch-pack: unexpected disconnect while reading sideband packet\nfatal: early EOF\nfatal: fetch-pack: invalid index-pack output\nVCSBaseException: VCS: Could not process command ['git', 'clone', '--recursive', '--depth', '1', 'https://github.com/Community-PIO-CH32V/toolchain-riscv-windows.git', 'C:\\Users\\Attiq\\.platformio\\.cache\\tmp\\pkg-installing-aky40fqp']"

JLINK support

Could you tell - is it possible to use JLINK with CH32V2xx MCUs?
Do you have configuration script?

blinky-none-os: PA1/PA2 used for crystal on CH32V003F4P6_EVT_R0

I ordered one of the inexpensive kits from an AliExpress vendor that includes a CH32V003F4P6_EVT_R0 eval board, a programmer, and other bits and pieces. What's the first thing most people try to bring up on a new eval board? A blinky program. I grabbed the one from here, wired the board to the programmer, ran a jumper from PA1 to LED1, and loaded the code onto the board...and got nothing for my trouble.

It turns out that PA1 and PA2 on these boards are wired to the onboard 24-MHz crystal, which is used as the clock source for the microcontroller. I tweaked the source to use PC1 instead, and once flashed, it behaved as expected.

To avoid this bit of frustration for other new users, you might be interested in the PR I'm about to submit.

API reference or programing guides?

From the example, it appears that the code for the same “function” (or “goal”?) varies across different types of chips. For example, in the basic "blinky-none-os" examples, ch32 series is very different from ch5x series. Even CH56x and CH57x have their differences. Where can I get the programing instruction? I tried searching on WCH's website, but it seems that there are no results.

ch32v103c8t6 upload failed on macOS

Program is compiled successfully. when I tried to upload firmware, I got following message:
dyld[1034]: Library not loaded: /usr/local/opt/libusb/lib/libusb-1.0.0.dylib
Referenced from: /Users/chenli/.platformio/packages/tool-openocd-riscv-wch/bin/openocd
Reason: tried: '/usr/local/opt/libusb/lib/libusb-1.0.0.dylib' (code signature in <04015360-D1D9-313C-87B0-05F7AC278738> '/usr/local/Cellar/libusb/1.0.27/lib/libusb-1.0.0.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/lib/libusb-1.0.0.dylib' (no such file), '/usr/local/Cellar/libusb/1.0.27/lib/libusb-1.0.0.dylib' (code signature in <04015360-D1D9-313C-87B0-05F7AC278738> '/usr/local/Cellar/libusb/1.0.27/lib/libusb-1.0.0.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/lib/libusb-1.0.0.dylib' (no such file)

Then I installed libusb through brew, but could not resolve it.
Can anybody provide some suggestions ? Thanks!

CH582M Compile BLE project error

ERROR: users/xxx/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: cannot find -lCH58xBLE

I have used the latest EVT2.0 library and found that it cannot compile properly. It seems that the 'vessel' field in the library. json needs to be modified. I have tried 2.0, 2.0.0, 2.0.0, and 2.0.00, but they cannot compile correctly. CH58xBLE-LIB.h is written as CH58x_BLE-LIB_V2.0. Please guide me on how to make correct modifications

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.