Skip to content

FEATURE: Added arduino CLI support #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions software/clock_setup_using_arduino_code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
PRJ_DIR = $(realpath .)

# ============================================================================= ARGS
PATH_SKETCH := $(PRJ_DIR)/clock_setup/clock_setup.ino
PATH_INSTALL := $$HOME/arduino_cli

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 " "
@ 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:
@ 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 "==================== Connected boards"; \
arduino-cli board list
@ echo "==================== Available CH32V boards"; \
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)

63 changes: 63 additions & 0 deletions software/clock_setup_using_arduino_code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# How to setup and upload code

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

- 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.
```bash
# install Arduino CLI
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# install Arduino CLI
# Install Arduino CLI


# NOTE: the CLI will be installed in the $PATH_INSTALL provided.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# NOTE: the CLI will be installed in the $PATH_INSTALL provided.
# NOTE: The CLI will be installed in the $PATH_INSTALL provided.

# Default path: ~/arduino_cli

make setup-arduino-cli PATH_INSTALL=<installation_path>
```
- 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=<installation_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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# arduino CLI installation path
# Arduino CLI installation path

which arduino-cli

# arduino CLI installed version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# arduino CLI installed version
# 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).
- 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 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
```
- To upload the sketch on the chip run:
```bash
make upload
```
3 changes: 3 additions & 0 deletions software/clock_setup_using_arduino_code/arduino-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
board_manager:
additional_urls:
- https://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.json