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 3 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
64 changes: 64 additions & 0 deletions software/clock_setup_using_arduino_code/Makefile
Original file line number Diff line number Diff line change
@@ -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; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably add a prompt for changing the installation directory?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also see nothing that implements this. Any thoughts?

cd ~/arduino_cli; \
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh; \
echo "========== Verifying installation..."; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this layout a standard from somewhere?

If not, what about something like this (also for all others and also the comments):

Suggested change
echo "========== Verifying installation..."; \
echo "===== Verifying installation... ====="; \

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about this formatting? This is also used on multiple occasions

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)

45 changes: 45 additions & 0 deletions software/clock_setup_using_arduino_code/README.md
Original file line number Diff line number Diff line change
@@ -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.
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
- Move to directory `./software/clock_setup_using_arduino_code` which contains
the Makefile required for setup, compilation and uploading the sketch.

These files are already in this directory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still in the latest commits

- 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
```
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