Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit edcf5a0

Browse files
author
Brandon Paiz
authored
enable development on macOS (#73)
1 parent e174494 commit edcf5a0

File tree

6 files changed

+150
-31
lines changed

6 files changed

+150
-31
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
.vscode
1+
.vscode
2+
src/build
3+
src/scripts/arduino-cli
4+
src/.arduino15

README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,3 @@ To access the web interface, connect to the `RubberNugget` AP with the password
5050
- Custom graphics
5151
- Live command preview
5252
- Reactive RGB NeoPixel
53-
54-
## Building / flashing from source
55-
Dependencies: docker, make.
56-
Docker is used to produce a replicable build environment and ensure library/tool dependensies are met.
57-
```
58-
# Clone the repo
59-
git clone https://github.com/HakCat-Tech/RubberNugget.git
60-
61-
# Navigate to src
62-
cd RubberNugget/src
63-
64-
# Build
65-
sudo make build
66-
67-
# Build and flash the ESP32-S2 (may need sudo)
68-
sudo make flash
69-
#optionally specify port: sudo make flash PORT=<port>
70-
#optionally install default scripts: sudo make flash RESET_SCRIPTS_DURING_FLASH=true
71-
72-
# Produce .img for release
73-
sudo make generate_img
74-
```
75-

src/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ COPY scripts ./scripts
3535
RUN ./scripts/build_web_ui.sh
3636
RUN ./arduino-cli compile -b esp32:esp32:esp32s2 RubberNugget \
3737
--build-property build.partitions=noota_3gffat \
38-
--build-property build.cdc_on_boot=1
38+
--build-property build.cdc_on_boot=1 \
39+
--output-dir=./build

src/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## Building / flashing from source
2+
3+
If want to flash the latest version of the USB-Nugget project, [the method
4+
documented
5+
here](https://github.com/HakCat-Tech/USB-Nugget#how-to-update-your-nugget) is
6+
easiest.
7+
8+
Docker is used to produce a replicable build environment to ensure
9+
library and tool dependencies are met. Linux is recommended when developing,
10+
building, and flashing from source.
11+
12+
### Linux
13+
14+
Dependencies: docker, make.
15+
```
16+
# Clone the repo
17+
git clone https://github.com/HakCat-Tech/USB-Nugget.git
18+
19+
# Navigate to src
20+
cd USB-Nugget/src
21+
22+
# Build
23+
sudo make build
24+
25+
# Build and flash the ESP32-S2 (may need sudo)
26+
sudo make flash
27+
#optionally specify port: sudo make flash PORT=<port>
28+
#optionally install default scripts: sudo make flash RESET_SCRIPTS_DURING_FLASH=true
29+
30+
# Produce .img for release
31+
sudo make generate_img
32+
```
33+
34+
### macOS
35+
36+
Docker on mac has issues connecting to usb devices and complicates the flashing
37+
process. A workaround is in place -- USB-Nugget will be built within docker but
38+
then flashed outside of the container. Some additional steps are also
39+
necessary to prepare your development environment:
40+
41+
1. Install docker and ensure the daemon is running. The daemon is running if the
42+
command `docker info` is successful.
43+
2. Install python3 and pip3, then `pip3 install esptool`
44+
45+
```bash
46+
# Clone the repo
47+
git clone https://github.com/HakCat-Tech/USB-Nugget.git
48+
49+
# Navigate to src
50+
cd USB-Nugget/src
51+
52+
# Verify everything is installed and configured correctly
53+
make check-mac-deps
54+
55+
# To build only, run
56+
make build
57+
58+
# Plug in your USB-Nugget dev kit in flashing mode by holding down the '0'
59+
# button while plugging it in.
60+
61+
# Find the port of your arduino. It's likely something like
62+
# "/dev/cu.usbmodem01".
63+
ls /dev/cu*
64+
65+
# To build and flash, run
66+
make flash-on-mac PORT=<port>
67+
68+
# If you want to overwrite the FAT partition to include default payloads, set
69+
# RESET_SCRIPTS_DURING_FLASH=true:
70+
make flash PORT=<port> RESET_SCRIPTS_DURING_FLASH=true
71+
```
72+
73+
### Windows
74+
75+
Not currently supported

src/arduino-cli-mac.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
board_manager:
2+
additional_urls: ["https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json"]
3+
daemon:
4+
port: "50051"
5+
directories:
6+
data: .arduino15
7+
downloads: .arduino15/staging
8+
user: /root/Arduino
9+
library:
10+
enable_unsafe_install: true
11+
logging:
12+
file: ""
13+
format: text
14+
level: info
15+
metrics:
16+
addr: :9090
17+
enabled: true
18+
output:
19+
no_color: false
20+
sketch:
21+
always_export_binaries: false
22+
updater:
23+
enable_notification: true
24+

src/makefile

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ PORT ?= /dev/ttyACM0
22
RESET_SCRIPTS_DURING_FLASH ?= false
33
IMAGE_NAME = rubber-nugget
44
CONTAINER_NAME := $(IMAGE_NAME)-$(shell date +%s)
5+
ARDUINO_CLI_VERSION = 0.22.0
56

67
submodules:
78
git submodule init
89
git submodule update
910

1011
build: submodules
11-
docker build . --file Dockerfile --tag rubber-nugget
12+
docker build . --file Dockerfile --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget
1213

13-
flash: check_port build
14+
flash: check-port build
1415
docker create --name $(CONTAINER_NAME) --device=$(PORT) -t rubber-nugget:latest
1516
docker start $(CONTAINER_NAME)
1617
docker exec $(CONTAINER_NAME) bash -c \
@@ -21,16 +22,54 @@ ifeq ($(RESET_SCRIPTS_DURING_FLASH), true)
2122
endif
2223
docker rm --force $(CONTAINER_NAME)
2324

24-
generate_img: check_port build
25+
generate_img: check-port build
2526
docker create --name $(CONTAINER_NAME) --device=$(PORT) -t rubber-nugget:latest
2627
docker start $(CONTAINER_NAME)
2728
docker exec $(CONTAINER_NAME) bash -c \
2829
'python3 -m esptool --after no_reset erase_flash && sleep 2 && \
2930
./arduino-cli upload -b esp32:esp32:esp32s2 --port $(PORT) RubberNugget/ && sleep 2 && \
3031
python3 -m esptool --after no_reset write_flash 0x110000 default.img && sleep 2 && \
3132
python3 -m esptool --after no_reset read_flash 0x0 0x400000 /rubber_nugget.bin'
32-
docker cp $(CONTAINER_NAME):/rubber_nugget.bin /tmp/meow.bin
33+
docker cp $(CONTAINER_NAME):/rubber_nugget.bin .
3334
docker rm --force $(CONTAINER_NAME)
3435

35-
check_port:
36-
@ls $(PORT) || { echo "Device not found at $(PORT). Run with 'make flash PORT=<port>'" && exit 1; }
36+
check-port:
37+
@ls $(PORT) || { echo "Device not found at $(PORT)" && exit 1; }
38+
39+
#-------------------------------------------------------------------------------
40+
# macOS development
41+
42+
MAC_PORT = /dev/cu.usbmodem01
43+
MAC_ARDUINO_CLI_TAR = arduino-cli_$(ARDUINO_CLI_VERSION)_macOS_64bit.tar.gz
44+
45+
arduino-cli: scripts/arduino-cli arduino-cli-esp32-install
46+
47+
arduino-cli-esp32-install:
48+
sudo ./scripts/arduino-cli core install esp32:esp32 --config-file arduino-cli-mac.yaml
49+
50+
scripts/arduino-cli:
51+
curl -L --output scripts/$(MAC_ARDUINO_CLI_TAR) https://github.com/arduino/arduino-cli/releases/download/$(ARDUINO_CLI_VERSION)/$(MAC_ARDUINO_CLI_TAR)
52+
tar -xf scripts/$(MAC_ARDUINO_CLI_TAR) --directory=scripts
53+
rm scripts/$(MAC_ARDUINO_CLI_TAR)
54+
rm scripts/LICENSE.txt
55+
56+
check-mac-deps:
57+
docker info
58+
which python3
59+
python3 -E -m esptool version
60+
61+
check-mac-port:
62+
@ls $(MAC_PORT) || { echo "Device not found at $(MAC_PORT)" && exit 1; }
63+
64+
mac-build: submodules
65+
sudo docker build . --file Dockerfile --build-arg ARDUINO_CLI_VERSION=$(ARDUINO_CLI_VERSION) --tag rubber-nugget
66+
67+
flash-on-mac: check-mac-port check-mac-deps arduino-cli mac-build
68+
sudo docker create --name $(CONTAINER_NAME) -t rubber-nugget:latest
69+
sudo docker cp $(CONTAINER_NAME):/app/build .
70+
sudo docker rm --force $(CONTAINER_NAME)
71+
ifeq ($(RESET_SCRIPTS_DURING_FLASH), true)
72+
python3 -m esptool --after no_reset write_flash 0x110000 fatfs/default.img
73+
endif
74+
{ sudo ./scripts/arduino-cli upload -b esp32:esp32:esp32s2 --port $(MAC_PORT) --config-file arduino-cli-mac.yaml --input-dir build; } || echo \
75+
'If you get the error: "esptool.py can not exit the download mode over USB..." this is a bug in arduino-cli and can be ignored'

0 commit comments

Comments
 (0)