|
| 1 | +# 🧑💻 Building TurtlPass Firmware from Source |
| 2 | + |
| 3 | +This guide explains how to compile and customize the **TurtlPass Firmware** using [**PlatformIO**](https://platformio.org/). |
| 4 | +Most users can rely on pre-built releases — building from source is ideal for developers or power users. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 📚 Table of Contents |
| 9 | + |
| 10 | +* [⚙️ Overview](#️-overview) |
| 11 | +* [🧰 Prerequisites](#-prerequisites) |
| 12 | +* [🚀 Quick Start](#-quick-start) |
| 13 | +* [⚡ Building and Uploading](#-building-and-uploading) |
| 14 | +* [🖥️ Supported Boards / Environments](#️-supported-boards--environments) |
| 15 | +* [⚙️ Optional Build Flags](#️-optional-build-flags) |
| 16 | +* [🔄 Building for Other Boards](#-building-for-other-boards) |
| 17 | +* [👆 Using a Touch Sensor (Optional)](#-using-a-touch-sensor-optional) |
| 18 | +* [🧪 Testing](#-testing) |
| 19 | +* [⚙️ Advanced PlatformIO Commands](#️-advanced-platformio-commands) |
| 20 | +* [💡 VS Code Integration](#-vs-code-integration) |
| 21 | +* [🧱 Troubleshooting](#-troubleshooting) |
| 22 | +* [🚀 Next Steps](#-next-steps) |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## ⚙️ Overview |
| 27 | + |
| 28 | +* **Core:** [Earle Philhower’s Arduino-Pico](https://github.com/earlephilhower/arduino-pico) |
| 29 | +* **Platform:** [Max Gerhardt’s RP2040 fork](https://github.com/maxgerhardt/platform-raspberrypi) |
| 30 | + |
| 31 | +TurtlPass firmware supports **RP2040** and **RP2350** microcontrollers across a wide range of boards while maintaining full Arduino compatibility. |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 🧰 Prerequisites |
| 36 | + |
| 37 | +* [PlatformIO Core or VSCode Extension](https://platformio.org/install/ide?install=vscode) |
| 38 | +* Supported RP2040 / RP2350 board |
| 39 | +* USB cable for flashing (with data support) |
| 40 | +* *(Optional)* TTP-223 capacitive touch sensor |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## 🚀 Quick Start |
| 45 | + |
| 46 | +1. **Clone the repository** |
| 47 | + |
| 48 | + ```bash |
| 49 | + git clone https://github.com/TurtlPass/turtlpass-firmware-arduino.git |
| 50 | + cd turtlpass-firmware-arduino/firmware |
| 51 | + ``` |
| 52 | + |
| 53 | +2. **Build the firmware** |
| 54 | + |
| 55 | + ```bash |
| 56 | + pio run -e pico |
| 57 | + ``` |
| 58 | + |
| 59 | +3. **(Optional) Upload to your board** |
| 60 | + |
| 61 | + ```bash |
| 62 | + pio run -e pico -t upload |
| 63 | + ``` |
| 64 | + |
| 65 | +> 💡 **Tip:** PlatformIO automatically handles toolchains, dependencies, and builds — no manual setup required. |
| 66 | +
|
| 67 | +--- |
| 68 | + |
| 69 | +## ⚡ Building and Uploading |
| 70 | + |
| 71 | +```bash |
| 72 | +# Build firmware |
| 73 | +pio run -e <env> |
| 74 | + |
| 75 | +# Upload firmware |
| 76 | +pio run -e <env> -t upload |
| 77 | +``` |
| 78 | + |
| 79 | +Replace `<env>` with one of the [supported environments](#️-supported-boards--environments). |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 🖥️ Supported Boards / Environments |
| 84 | + |
| 85 | +| Board | Environment | LED Type | |
| 86 | +| :------------------------------------ | :------------------------- | :----------- | |
| 87 | +| Raspberry Pi Pico (RP2040) | `pico` | Single-color | |
| 88 | +| Raspberry Pi Pico W (RP2040 + Wi-Fi) | `rpipicow` | Single-color | |
| 89 | +| Raspberry Pi Pico 2 (RP2350) | `rpipico2` | Single-color | |
| 90 | +| Raspberry Pi Pico 2W (RP2350 + Wi-Fi) | `rpipico2w` | Single-color | |
| 91 | +| Adafruit Feather RP2040 | `adafruit_feather` | RGB | |
| 92 | +| Adafruit QT Py RP2040 | `adafruit_qtpy` | RGB | |
| 93 | +| Adafruit Trinkey QT2040 | `adafruit_trinkeyrp2040qt` | RGB | |
| 94 | +| Seeed Xiao RP2040 | `seeed_xiao_rp2040` | RGB | |
| 95 | +| Seeed Xiao RP2350 | `seeed_xiao_rp2350` | RGB | |
| 96 | +| Waveshare RP2040-Zero | `waveshare_rp2040_zero` | RGB | |
| 97 | +| Waveshare RP2350-Zero | `waveshare_rp2350_zero` | RGB | |
| 98 | +| **Generic RP2040** | `generic` | Single/RGB | |
| 99 | +| **Generic RP2350** | `generic_rp2350` | Single/RGB | |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## ⚙️ Optional Build Flags |
| 104 | + |
| 105 | +Customize firmware parameters via `build_flags`: |
| 106 | + |
| 107 | +| Flag | Description | Default | |
| 108 | +| :-------------------------- | :------------------------------ | :------------ | |
| 109 | +| `__TURTLPASS_VERSION__` | Firmware version string | `"3.0.0"` | |
| 110 | +| `__TURTLPASS_LED_PIN__` | Onboard LED pin number | `LED_BUILTIN` | |
| 111 | +| `__TURTLPASS_LED_IS_RGB__` | Enable RGB LED (`true`/`false`) | `false` | |
| 112 | +| `__TURTLPASS_EEPROM_SIZE__` | Emulated EEPROM size (bytes) | `4096` | |
| 113 | +| `__TURTLPASS_PIN_TTP223__` | GPIO pin for touch sensor | *undefined* | |
| 114 | + |
| 115 | +### 💡 Inline Override Example |
| 116 | + |
| 117 | +```bash |
| 118 | +pio run -e pico -D__TURTLPASS_EEPROM_SIZE__=2048 |
| 119 | +``` |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +## 🔄 Building for Other Boards |
| 124 | + |
| 125 | +TurtlPass supports any board based on **RP2040** or **RP2350** — including fully custom configurations. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +### 🧩 Supported Boards Reference |
| 130 | + |
| 131 | +See the full list here: |
| 132 | +👉 [maxgerhardt/platform-raspberrypi — boards](https://github.com/maxgerhardt/platform-raspberrypi/tree/develop/boards) |
| 133 | + |
| 134 | +To build for one, create a new environment in your `platformio.ini` file. |
| 135 | + |
| 136 | +#### ⚙️ Example — Waveshare RP2040 Zero |
| 137 | + |
| 138 | +```ini |
| 139 | +[env:waveshare_rp2040_zero] |
| 140 | +extends = env:base |
| 141 | +board = waveshare_rp2040_zero |
| 142 | +build_flags = |
| 143 | + ${env:base.build_flags} |
| 144 | + -D__TURTLPASS_LED_IS_RGB__=true ; RGB LED |
| 145 | +``` |
| 146 | + |
| 147 | +Then build it: |
| 148 | + |
| 149 | +```bash |
| 150 | +pio run -e waveshare_rp2040_zero |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +### 🧠 Custom Boards |
| 156 | + |
| 157 | +> 🧭 **Tip:** |
| 158 | +> Use `generic` for RP2040 or `generic_rp2350` for RP2350, and manually define LED pin and RGB settings. |
| 159 | +
|
| 160 | +#### Example |
| 161 | + |
| 162 | +```bash |
| 163 | +pio run -e generic \ |
| 164 | + -D__TURTLPASS_LED_PIN__=16 \ |
| 165 | + -D__TURTLPASS_LED_IS_RGB__=true |
| 166 | +``` |
| 167 | + |
| 168 | +**Notes:** |
| 169 | + |
| 170 | +* `__TURTLPASS_LED_PIN__` — sets the LED pin number |
| 171 | +* `__TURTLPASS_LED_IS_RGB__` — set `true` for RGB LED |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## 👆 Using a Touch Sensor (Optional) |
| 176 | + |
| 177 | +Attach a **TTP-223 capacitive touch sensor** to replace the BOOTSEL button. |
| 178 | + |
| 179 | +```ini |
| 180 | +-D__TURTLPASS_PIN_TTP223__=2 |
| 181 | +``` |
| 182 | + |
| 183 | +This configures the firmware to use the external touch input instead of **BOOTSEL**. |
| 184 | + |
| 185 | +### 🔌 Circuit Diagram |
| 186 | + |
| 187 | +``` |
| 188 | + RP2040/RP2350 Touch Sensor |
| 189 | + +-----------+ +----------+ |
| 190 | + | GND | ---------- | GND | |
| 191 | + | GPIO 2 | ---------- | I/O | |
| 192 | + | 3.3V | ---------- | VCC | |
| 193 | + +-----------+ +----------+ |
| 194 | +``` |
| 195 | + |
| 196 | +**Connection steps:** |
| 197 | + |
| 198 | +1. Connect **GND → GND** |
| 199 | +2. Connect **GPIO 2 → I/O** |
| 200 | +3. Connect **3.3V → VCC** |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +## 🧪 Testing |
| 205 | + |
| 206 | +TurtlPass includes both **embedded** (hardware-level) and **native** (host-level) tests. |
| 207 | + |
| 208 | +### 🧭 Embedded Tests — Run on Hardware |
| 209 | + |
| 210 | +```bash |
| 211 | +pio test -e pico-tests |
| 212 | +pio test -e pico-tests --filter embedded/test_seedmanager_basic |
| 213 | +``` |
| 214 | + |
| 215 | +### 💻 Native Tests — Run on Host Machine |
| 216 | + |
| 217 | +```bash |
| 218 | +pio test -e native |
| 219 | +pio test -e native --filter native/test_key_derivation |
| 220 | +``` |
| 221 | + |
| 222 | +> ⚡ **Note:** Native tests run on your PC — fast, reproducible, and ideal for CI pipelines. |
| 223 | +
|
| 224 | +--- |
| 225 | + |
| 226 | +## ⚙️ Advanced PlatformIO Commands |
| 227 | + |
| 228 | +### 🔄 Clean and Rebuild |
| 229 | + |
| 230 | +```bash |
| 231 | +pio run -t clean |
| 232 | +pio run -e pico |
| 233 | +``` |
| 234 | + |
| 235 | +### 📦 Generate `.uf2` Firmware (Manual Flash) |
| 236 | + |
| 237 | +```bash |
| 238 | +pio run -e pico --target buildfs |
| 239 | +``` |
| 240 | + |
| 241 | +Output file: |
| 242 | + |
| 243 | +``` |
| 244 | +.pio/build/<env>/firmware.uf2 |
| 245 | +``` |
| 246 | + |
| 247 | +--- |
| 248 | + |
| 249 | +## 💡 VS Code Integration |
| 250 | + |
| 251 | +When using **PlatformIO in VS Code**: |
| 252 | + |
| 253 | +* ▶️ **Build** compiles the firmware |
| 254 | +* 🔌 **Upload** flashes it automatically |
| 255 | +* 🧩 Auto-detects connected devices and can enter **BOOTSEL mode** |
| 256 | + |
| 257 | +> 🪫 **If upload fails:** |
| 258 | +> Drag `.pio/build/pico/firmware.uf2` onto the **RPI-RP2** drive manually. |
| 259 | +
|
| 260 | +--- |
| 261 | + |
| 262 | +## 🧱 Troubleshooting |
| 263 | + |
| 264 | +### 🧭 General Checks |
| 265 | + |
| 266 | +* Run with verbose output: `pio run -v` |
| 267 | +* Hold **BOOTSEL** while connecting |
| 268 | +* Check connected devices: |
| 269 | + |
| 270 | + ```bash |
| 271 | + pio device list |
| 272 | + ``` |
| 273 | + |
| 274 | +### ❌ `Unknown board` or `Missing platform` |
| 275 | + |
| 276 | +Install the correct platform fork: |
| 277 | + |
| 278 | +```bash |
| 279 | +pio platform install https://github.com/maxgerhardt/platform-raspberrypi.git |
| 280 | +``` |
| 281 | + |
| 282 | +### ⚠️ `Upload failed` |
| 283 | + |
| 284 | +1. Hold **BOOTSEL** |
| 285 | +2. Connect USB |
| 286 | +3. Release when it mounts as a drive |
| 287 | + Then rerun: |
| 288 | + |
| 289 | +```bash |
| 290 | +pio run -e pico -t upload |
| 291 | +``` |
| 292 | + |
| 293 | +### ⚙️ Missing Arduino Core |
| 294 | + |
| 295 | +Add this line to enforce: |
| 296 | + |
| 297 | +```ini |
| 298 | +board_build.core = earlephilhower |
| 299 | +``` |
| 300 | + |
| 301 | +--- |
| 302 | + |
| 303 | +## 🚀 Next Steps |
| 304 | + |
| 305 | +Now that you’ve built the **TurtlPass Firmware**, explore the rest of the [TurtlPass Ecosystem](https://github.com/TurtlPass) to unlock its full potential. |
| 306 | + |
| 307 | +Happy hacking! ✨🐢 |
0 commit comments