Skip to content
Draft
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
80 changes: 37 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,25 @@ jobs:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio-${{ hashFiles('platformio.ini') }}
restore-keys: |
${{ runner.os }}-platformio-

- name: Ensure changelog is updated
uses: dangoslen/[email protected]
- name: Set up python
uses: actions/setup-python@v6
with:
python-version: '3.11'
architecture: 'x64'
- name: Upgrade pip tooling
run: |
python -m pip install --upgrade pip setuptools wheel

- name: Get current date
id: date
run: echo "date=$(date +'%y.%-m.%-d')" >> $GITHUB_OUTPUT

- name: Test with environment variables
run: echo $TAG_NAME - $RELEASE_NAME
env:
TAG_NAME: ${{ steps.date.outputs.date }}
RELEASE_NAME: ${{ steps.date.outputs.date }}-

- uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.date.outputs.date }}
message: "Automatic release ${{ steps.date.outputs.date }}"

- uses: dorny/paths-filter@v3
id: changes
with:
Expand All @@ -49,39 +39,43 @@ jobs:
- '!(Hardware/**)'
hardware:
- 'Hardware/**'
- name: Show python version
run: python --version
- name: Install PlatformIO
run: python -m pip install platformio
- name: Pre-install PlatformIO packages (release env)
run: platformio pkg install -e release
- name: Ensure ESP-IDF component manager is available
shell: bash

- name: Install ESP-IDF
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4
target: esp32

- name: Setup external dependencies
run: |
set -euo pipefail
PIO_HOME="$HOME/.platformio"
# Try to locate PlatformIO-managed ESP-IDF virtualenv
ESPIDF_VENV=$(ls -d "$PIO_HOME/penv/.espidf-"* 2>/dev/null | head -n 1 || true)
if [ -z "$ESPIDF_VENV" ]; then
# Trigger framework fetch which usually creates the venv
platformio platform show espressif32 || true
ESPIDF_VENV=$(ls -d "$PIO_HOME/penv/.espidf-"* 2>/dev/null | head -n 1 || true)
fi
if [ -n "$ESPIDF_VENV" ] && [ -x "$ESPIDF_VENV/bin/python" ]; then
"$ESPIDF_VENV/bin/python" -m pip install --upgrade pip setuptools wheel
"$ESPIDF_VENV/bin/python" -m pip install --upgrade idf-component-manager
else
echo "ESP-IDF venv not found yet; proceeding. PlatformIO should install deps during build."
fi
chmod +x setup_dependencies.sh
./setup_dependencies.sh

- name: Check pre-commit hooks
uses: pre-commit/[email protected]

- name: Build firmware
run: platformio run -e release
- name: Build filesystem
run: platformio run -e release --target buildfs
run: |
. $IDF_PATH/export.sh
idf.py set-target esp32
idf.py build

- name: Build filesystem (LittleFS)
run: |
. $IDF_PATH/export.sh
idf.py littlefs-create-partition-image littlefs data

- name: Create artifacts
run: |
7z a SmartSpin2kFirmware-${{ steps.date.outputs.date }}.bin.zip ./.pio/build/release/*.bin
mkdir -p artifacts
cp build/SmartSpin2k.bin artifacts/
cp build/bootloader/bootloader.bin artifacts/
cp build/partition_table/partition-table.bin artifacts/
cp build/littlefs.bin artifacts/ || echo "LittleFS image not found, skipping"
cd artifacts
7z a ../SmartSpin2kFirmware-${{ steps.date.outputs.date }}.bin.zip *.bin
cd ..

- name: Archive
uses: actions/upload-artifact@v4
with:
Expand All @@ -107,7 +101,7 @@ jobs:
body: ${{ github.event.head_commit.message }}
files: |
SmartSpin2kFirmware-${{ steps.date.outputs.date }}.bin.zip
update-changelog:

- name: Update changelog
uses: thomaseizinger/keep-a-changelog-new-release@v3
with:
Expand Down
29 changes: 21 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
# PlatformIO (legacy - can be removed after full migration)
.pio/

# VSCode
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode/extensions.json
.vscode/settings.json

# IDEs
.idea/

# ESP-IDF Build artifacts
/build/
/managed_components/
/dependencies.lock
sdkconfig
sdkconfig.old

# Test artifacts
test/tmp_pio_test_transport.cpp
test/output/

# User config and logs
data/config.txt
include/telegram_token.h
Errors
SmartSpin_logfile.txt
*.err
.DS_Store
build/CMakeCache.txt
*.log
*.map

# System files
.DS_Store
.aider*
.env
C/Users/
/build
/managed_components
dependencies.lock
.vscode/settings.json
*.map
C/Users/
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude: (\.pio|lib/NimBLE-Arduino|lib/ArduinoCompat)/.*
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
Expand Down
206 changes: 206 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Building SmartSpin2k with ESP-IDF

This project uses ESP-IDF (Espressif IoT Development Framework) with Arduino as a component for building the SmartSpin2k firmware.

## Prerequisites

1. **ESP-IDF v5.4 or later**
- Install ESP-IDF following the [official installation guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html)
- Make sure to install the ESP32 toolchain: `./install.sh esp32`
- Source the export script: `. $HOME/esp/esp-idf/export.sh` (or wherever you installed ESP-IDF)

2. **Python 3.8+**
- Required for ESP-IDF build system

3. **CMake 3.16+**
- Required for ESP-IDF build system

4. **Ninja build system** (recommended)
- Install via package manager: `sudo apt-get install ninja-build` (Linux) or `brew install ninja` (macOS)

## Setting Up External Dependencies

The project uses several external Arduino libraries that need to be added to the `components/` directory:

### Option 1: Manual Clone (Recommended for Development)

```bash
cd components

# Clone esp-nimble-cpp (Custom NimBLE C++ wrapper)
git clone https://github.com/doudar/esp-nimble-cpp.git

# Clone TMCStepper (v0.7.3 - Trinamic stepper motor driver)
git clone --branch v0.7.3 https://github.com/teemuatlut/TMCStepper.git

# Clone ArduinoJson (v7.3.1 - JSON library)
git clone --branch v7.3.1 https://github.com/bblanchon/ArduinoJson.git

# Clone FastAccelStepper (High-performance stepper motor library)
git clone https://github.com/doudar/FastAccelStepper.git

# Clone ArduinoWebsockets (WebSocket library)
git clone https://github.com/doudar/ArduinoWebsockets.git
```

### Option 2: Using Git Submodules (Recommended for Production)

```bash
# Add as submodules
git submodule add https://github.com/doudar/esp-nimble-cpp.git components/esp-nimble-cpp
git submodule add -b v0.7.3 https://github.com/teemuatlut/TMCStepper.git components/TMCStepper
git submodule add -b v7.3.1 https://github.com/bblanchon/ArduinoJson.git components/ArduinoJson
git submodule add https://github.com/doudar/FastAccelStepper.git components/FastAccelStepper
git submodule add https://github.com/doudar/ArduinoWebsockets.git components/ArduinoWebsockets

# Initialize and update submodules
git submodule update --init --recursive
```

## Configuring the Build

### 1. Set Target (ESP32)

```bash
idf.py set-target esp32
```

### 2. Configure Project (Optional)

```bash
idf.py menuconfig
```

Key configuration options (already set in `sdkconfig.defaults`):
- Arduino components are selectively enabled to manage IRAM constraints
- Partition table: `partitions.csv` (2MB flash with OTA support)
- Compiler optimization: Size (`-Os`)
- FreeRTOS tick rate: 1000 Hz

## Building

### Full Build

```bash
idf.py build
```

### Build Firmware Only

```bash
idf.py app
```

### Build Filesystem (LittleFS)

```bash
idf.py littlefs-create-partition-image
```

## Flashing

### Flash Everything (bootloader, partitions, app)

```bash
idf.py flash
```

### Flash App Only

```bash
idf.py app-flash
```

### Monitor Serial Output

```bash
idf.py monitor
```

### Flash and Monitor

```bash
idf.py flash monitor
```

## Build Artifacts

After a successful build, the following files will be created in the `build/` directory:

- `SmartSpin2k.bin` - Main application binary
- `bootloader/bootloader.bin` - Bootloader binary
- `partition_table/partition-table.bin` - Partition table
- `littlefs.bin` - LittleFS filesystem image (if built)

## Cleaning

### Clean Build Artifacts

```bash
idf.py fullclean
```

## Troubleshooting

### Component Not Found

If you get errors about missing components, ensure all external dependencies are cloned into the `components/` directory.

### IRAM Overflow

The ESP32 has limited IRAM. The project uses selective Arduino component compilation to manage this. If you encounter IRAM overflow errors:

1. Check `sdkconfig.defaults` for Arduino component selection
2. Disable unnecessary Arduino components via `idf.py menuconfig` → Component config → Arduino Configuration

### Flash Size Issues

This project requires 2MB flash minimum. If you have a 4MB module, you can update the partition table in `partitions.csv` to utilize the additional space.

## VSCode Integration

### Install ESP-IDF Extension

1. Install the [ESP-IDF extension](https://marketplace.visualstudio.com/items?itemName=espressif.esp-idf-extension) for VSCode
2. Configure the extension to point to your ESP-IDF installation
3. Use the extension's build, flash, and monitor commands

### Configuration

The extension should automatically detect the `CMakeLists.txt` and configure the project.

## Advanced Build Options

### Custom Build Flags

Edit `main/CMakeLists.txt` to add custom compile flags:

```cmake
target_compile_options(${COMPONENT_LIB} PRIVATE
-std=gnu++17
-DCUSTOM_FLAG=1
)
```

### Build Version Information

The build system automatically generates version information from git tags:
- `git_tag_macro.py` - Generates firmware version from git tags
- `build_date_macro.py` - Generates build timestamp

These scripts are called automatically during the build process.

## Migrating from PlatformIO

If you were previously using PlatformIO:

1. **Configuration**: Most settings from `platformio.ini` have been migrated to `sdkconfig.defaults`
2. **Libraries**: External dependencies that were managed by PlatformIO are now in `components/`
3. **Source Files**: `src/` → `main/`, `lib/` → `components/`
4. **Build Commands**: `pio run` → `idf.py build`, `pio run -t upload` → `idf.py flash`

## Further Reading

- [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/index.html)
- [ESP-IDF Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html)
- [Arduino-ESP32 as ESP-IDF Component](https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html)
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Hardware


## [25.11.4]

### Added

### Changed

### Hardware


## [25.11.3]

### Added
Expand Down
Loading
Loading