From d1268983dd5cc825e1692d371d45806625cfc6a4 Mon Sep 17 00:00:00 2001 From: usman1515 Date: Wed, 29 Jan 2025 14:46:31 +0100 Subject: [PATCH 1/6] created a README that explains how to setup, compile and upload the sketch using arduino CLI --- .../clock_setup_using_arduino_code/README.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 software/clock_setup_using_arduino_code/README.md diff --git a/software/clock_setup_using_arduino_code/README.md b/software/clock_setup_using_arduino_code/README.md new file mode 100644 index 0000000..780b6d4 --- /dev/null +++ b/software/clock_setup_using_arduino_code/README.md @@ -0,0 +1,45 @@ +# How to setup and upload code + +To flash the firmware for configuring the PLL chip to compatible MCUs we will be using [Arduino-CLI](https://github.com/arduino/arduino-cli). + +## Procedure + +### Prerequisite + +- Add the following line in your `.bashrc` or `.zshrc`. +```bash +export PATH=$HOME/arduino_cli/bin:$PATH +``` +- Make sure to source your `.bashrc` or `.zshrc` after updating `$PATH`. + +- Install `libhidapi-hidraw0` library for USB serial communication. +```bash +# Ubuntu/Debian +sudo apt update +sudo apt install libhidapi-hidraw0 +``` + +### Install Arduino CLI +- Move to directory `./software/clock_setup_using_arduino_code` which contains +the Makefile required for setup, compilation and uploading the sketch. +- Run `make setup-arduino-cli` which will install `arduino-cli`. + +### Install Board Files +- Now we need to setup and add the board support files for our CH32 EVT chips which can be found [here](https://github.com/openwch/arduino_core_ch32). +- Run `make setup-board-files` which will download, search and install all board files necessary. + +### Compile and Upload +- Now connect the chip using the WCH-Debugger Link and run the following command: + ```bash + # show all connected boards/chips via USB + make list-boards + ``` +- Make sure to check if Port value e.g. `/dev/ttyACM0` is the same as in the `Makefile`. If not, update it accordingly. +- To compile the sketch run: + ```bash + make compile + ``` +- To upload the sketch on the chip run: + ```bash + make upload + ``` From 3adfa7e26a50d4fcd3c8ecb6834e9b3fa17d9f81 Mon Sep 17 00:00:00 2001 From: usman1515 Date: Wed, 29 Jan 2025 14:47:30 +0100 Subject: [PATCH 2/6] created a Makefile wiht multiple targets used to setup, compile and upload the sketch using arduino CLI --- .../clock_setup_using_arduino_code/Makefile | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 software/clock_setup_using_arduino_code/Makefile diff --git a/software/clock_setup_using_arduino_code/Makefile b/software/clock_setup_using_arduino_code/Makefile new file mode 100644 index 0000000..bf21a63 --- /dev/null +++ b/software/clock_setup_using_arduino_code/Makefile @@ -0,0 +1,64 @@ +PRJ_DIR = $(realpath .) + +# ============================================================================= ARGS +PATH_SKETCH := $(PRJ_DIR)/clock_setup/clock_setup.ino + +PORT := /dev/ttyACM0 + +FILE_CONFIG := arduino-cli.yaml +BOARD_CORE := WCH:ch32v +BOARD_LIST := WCH +FQBN := WCH:ch32v:CH32V00x_EVT + +# ============================================================================= TARGETS + +# setup and install arduino CLI +setup-arduino-cli: + @ echo " " + [ -d ~/arduino_cli ] || mkdir -p ~/arduino_cli; \ + cd ~/arduino_cli; \ + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh; \ + echo "========== Verifying installation..."; \ + source $(HOME)/.bashrc; \ + which arduino-cli; \ + arduino-cli version + +# setup board files for CH32V003 on arudino +setup-board-files: + @ echo " " + @ echo "==================== Creating board config file" + arduino-cli config init && \ + @ echo "==================== Copy file to config folder"; \ + [ -d $(HOME)/.arduino15 ] || mkdir -p $(HOME)/.arduino15; \ + cp -rv ./$(FILE_CONFIG) $(HOME)/.arduino15/$(FILE_CONFIG) && \ + @ echo "==================== Update the core index"; \ + arduino-cli core update-index && \ + @ echo "==================== Search for WCH boards"; \ + arduino-cli core search wch && \ + @ echo "==================== Install the core"; \ + arduino-cli core install $(BOARD_CORE) && \ + @ echo "==================== Verify installation"; \ + arduino-cli core list && \ + @ echo "==================== List all WCH boards"; \ + arduino-cli board listall $(BOARD_LIST) + +# show all connected boards/chips via USB +list-boards: + @ echo " " + @ echo "==================== List connected boards"; \ + arduino-cli board list && \ + @ echo "==================== List Ch32V boards available"; \ + arduino-cli board listall | grep CH32 + +# compile the arduino sketch for the chip +compile: + @ echo " " + @ echo "==================== Compiling sketch" + arduino-cli compile --fqbn $(FQBN) $(PATH_SKETCH) + +# upload the sketch to the board +upload: + @ echo " " + @ echo "==================== Uploading sketch" + arduino-cli upload $(PATH_SKETCH) -p $(PORT) --fqbn $(FQBN) + From b2b31d8ee9a61f1150c7764d89da92219a7d58f6 Mon Sep 17 00:00:00 2001 From: usman1515 Date: Wed, 29 Jan 2025 14:48:45 +0100 Subject: [PATCH 3/6] created YAML config file for adding arduino core support for CH32 EVT Boards --- software/clock_setup_using_arduino_code/arduino-cli.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 software/clock_setup_using_arduino_code/arduino-cli.yaml diff --git a/software/clock_setup_using_arduino_code/arduino-cli.yaml b/software/clock_setup_using_arduino_code/arduino-cli.yaml new file mode 100644 index 0000000..bb5b202 --- /dev/null +++ b/software/clock_setup_using_arduino_code/arduino-cli.yaml @@ -0,0 +1,3 @@ +board_manager: + additional_urls: + - https://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.json From 0cd073695e42c4b9276371ed1beac25db8e25e61 Mon Sep 17 00:00:00 2001 From: usman1515 Date: Thu, 30 Jan 2025 15:22:50 +0100 Subject: [PATCH 4/6] docs: made minor spelling and grammar chanes as requested. --- .../clock_setup_using_arduino_code/README.md | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/software/clock_setup_using_arduino_code/README.md b/software/clock_setup_using_arduino_code/README.md index 780b6d4..de78b99 100644 --- a/software/clock_setup_using_arduino_code/README.md +++ b/software/clock_setup_using_arduino_code/README.md @@ -1,17 +1,11 @@ # How to setup and upload code -To flash the firmware for configuring the PLL chip to compatible MCUs we will be using [Arduino-CLI](https://github.com/arduino/arduino-cli). +To flash the firmware for configuring the PLL chip to compatible MCUs we will be using the [Arduino-CLI](https://github.com/arduino/arduino-cli). ## Procedure ### Prerequisite -- Add the following line in your `.bashrc` or `.zshrc`. -```bash -export PATH=$HOME/arduino_cli/bin:$PATH -``` -- Make sure to source your `.bashrc` or `.zshrc` after updating `$PATH`. - - Install `libhidapi-hidraw0` library for USB serial communication. ```bash # Ubuntu/Debian @@ -20,9 +14,33 @@ sudo apt install libhidapi-hidraw0 ``` ### Install Arduino CLI -- Move to directory `./software/clock_setup_using_arduino_code` which contains -the Makefile required for setup, compilation and uploading the sketch. -- Run `make setup-arduino-cli` which will install `arduino-cli`. +- Move to directory `./software/clock_setup_using_arduino_code` which contains the Makefile required for setup, compilation and uploading the sketch. +```bash +# install Arduino CLI + +# NOTE: the CLI will be installed in the $PATH_INSTALL provided. +# Default path: ~/arduino_cli + +make setup-arduino-cli PATH_INSTALL= +``` +- Once installation is complete add the following line in your `.bashrc` or `.zshrc` to update the `$PATH` variable. +```bash +# When using custom install path +export PATH=/bin:$PATH + +# When using default install path +export PATH=$HOME/arduino_cli/bin:$PATH +``` +- Source your `.bashrc` or `.zshrc` after updating `$PATH`. +- Verify your installation. + +```bash +# arduino CLI installation path +which arduino-cli + +# arduino CLI installed version +arduino-cli version +``` ### Install Board Files - Now we need to setup and add the board support files for our CH32 EVT chips which can be found [here](https://github.com/openwch/arduino_core_ch32). @@ -34,7 +52,7 @@ the Makefile required for setup, compilation and uploading the sketch. # show all connected boards/chips via USB make list-boards ``` -- Make sure to check if Port value e.g. `/dev/ttyACM0` is the same as in the `Makefile`. If not, update it accordingly. +- Make sure to check if the port e.g. `/dev/ttyACM0` is the same as in the `Makefile`. If not, update it accordingly. - To compile the sketch run: ```bash make compile From 0f8b7aa5bd2a4b8e1fda2f3dcd297bc6294c5b83 Mon Sep 17 00:00:00 2001 From: usman1515 Date: Thu, 30 Jan 2025 15:27:08 +0100 Subject: [PATCH 5/6] fix: target setup-arduino-cli updated with arg install_path --- .../clock_setup_using_arduino_code/Makefile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/software/clock_setup_using_arduino_code/Makefile b/software/clock_setup_using_arduino_code/Makefile index bf21a63..c73bb46 100644 --- a/software/clock_setup_using_arduino_code/Makefile +++ b/software/clock_setup_using_arduino_code/Makefile @@ -1,7 +1,8 @@ PRJ_DIR = $(realpath .) # ============================================================================= ARGS -PATH_SKETCH := $(PRJ_DIR)/clock_setup/clock_setup.ino +PATH_SKETCH := $(PRJ_DIR)/clock_setup/clock_setup.ino +PATH_INSTALL := $$HOME/arduino_cli PORT := /dev/ttyACM0 @@ -15,13 +16,10 @@ FQBN := WCH:ch32v:CH32V00x_EVT # setup and install arduino CLI setup-arduino-cli: @ echo " " - [ -d ~/arduino_cli ] || mkdir -p ~/arduino_cli; \ - cd ~/arduino_cli; \ - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh; \ - echo "========== Verifying installation..."; \ - source $(HOME)/.bashrc; \ - which arduino-cli; \ - arduino-cli version + @ echo "Installation dir: $(PATH_INSTALL)" + [ -d $(PATH_INSTALL)/arduino_cli ] || mkdir -p $(PATH_INSTALL)/arduino_cli; \ + cd $(PATH_INSTALL)/arduino_cli; \ + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh # setup board files for CH32V003 on arudino setup-board-files: @@ -45,9 +43,9 @@ setup-board-files: # show all connected boards/chips via USB list-boards: @ echo " " - @ echo "==================== List connected boards"; \ + @ echo "==================== Connected boards"; \ arduino-cli board list && \ - @ echo "==================== List Ch32V boards available"; \ + @ echo "==================== Available CH32V boards"; \ arduino-cli board listall | grep CH32 # compile the arduino sketch for the chip From 6936b1cc7c074612c59cd49975026e2f7ade447e Mon Sep 17 00:00:00 2001 From: usman1515 Date: Wed, 5 Feb 2025 14:27:11 +0100 Subject: [PATCH 6/6] fixed small typo in target list-boards --- software/clock_setup_using_arduino_code/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/software/clock_setup_using_arduino_code/Makefile b/software/clock_setup_using_arduino_code/Makefile index c73bb46..5f6caed 100644 --- a/software/clock_setup_using_arduino_code/Makefile +++ b/software/clock_setup_using_arduino_code/Makefile @@ -44,7 +44,7 @@ setup-board-files: list-boards: @ echo " " @ echo "==================== Connected boards"; \ - arduino-cli board list && \ + arduino-cli board list @ echo "==================== Available CH32V boards"; \ arduino-cli board listall | grep CH32