|
| 1 | +# Basic Flash Guide for Castor & Pollux |
| 2 | + |
| 3 | +This guide is written for someone new to flashing firmware onto hardware, or |
| 4 | +needs guidance getting started with Python. |
| 5 | + |
| 6 | +Warning: This guide was not written by a member of the Winterbloom team, but |
| 7 | +was rather contributed by a third-party trying this for the first time. If in |
| 8 | +doubt, [CONTRIUBTING.md](./CONTRIBUTING.md) should be considered authoritative. |
| 9 | + |
| 10 | +Assumptions: |
| 11 | + * Access to a computer such that: |
| 12 | + * With Windows installed, and you can use WSL, OR |
| 13 | + * With a flavour of Linux installed, or the ability to install Linux |
| 14 | + * Access to a [black magic debug probe](https://black-magic.org/index.html) |
| 15 | + or similar hardware |
| 16 | + |
| 17 | +## Acquiring the firmware |
| 18 | + |
| 19 | +You will need a copy of the Gemini firmware. |
| 20 | + |
| 21 | +### Current Release |
| 22 | + |
| 23 | +Navigate to the [latest released |
| 24 | +firmware](https://github.com/wntrblm/Castor_and_Pollux/releases/latest), and |
| 25 | +download the file with the name containing `release` and the suffix `uf2`. |
| 26 | + |
| 27 | +### Building the firmware from head |
| 28 | + |
| 29 | +Starting from a new copy of Arch Linux (CachyOS, WSL, or archlinux.org), |
| 30 | +execute the following commands to: |
| 31 | + |
| 32 | +1. Install pre-requisite packages (list may be incomplete) |
| 33 | +2. Fetch a copy of this repository |
| 34 | +3. Move your current working directory to the repository |
| 35 | +4. Move your current working directory to the firmware source root |
| 36 | +5. Prepare a python virtual environment |
| 37 | +6. Activate the python virtual environment - this functions as an isolated |
| 38 | +environment to allow you to install additional dependencies/tooling without |
| 39 | +affecting the rest of your system. |
| 40 | +7. Install additional dependencies required for setting up the build process |
| 41 | +8. Set up the build environment - this will produce a `build.ninja` file, which |
| 42 | +you will use in the next step |
| 43 | +9. Build the firmware. You should see some graphs showing memory usage and text |
| 44 | +indicating the output location. |
| 45 | + |
| 46 | +``` |
| 47 | +sudo pacman -S arm-none-eabi-{binutils,newlib,gcc,gdb} python3 ninja git |
| 48 | +git clone https://github.com/wntrbloom/Castor_and_Pollux |
| 49 | +cd Castor_and_Pollux |
| 50 | +cd ./firmware |
| 51 | +python3 -m venv . |
| 52 | +source ./bin/activate |
| 53 | +python3 -m pip install -r requirements.txt |
| 54 | +python3 ./configure.py |
| 55 | +ninja # You should have a C&P firmware.elf and .uf2 at this point |
| 56 | +``` |
| 57 | + |
| 58 | +## Flashing the firmware |
| 59 | + |
| 60 | +### Connecting to Castor and Pollux |
| 61 | + |
| 62 | +Connect your fimrware flashing hardware of choice to the test points on the |
| 63 | +board. |
| 64 | + |
| 65 | +For a Black magic probe, double check the pins using [the debug header |
| 66 | +guide](https://black-magic.org/knowledge/pinouts.html#black-magic-debug-unified-connector-bmdu): |
| 67 | + * Pin 1 (vref) - 3v3 test point |
| 68 | + * Pin 3 (gnd) - gnd test point |
| 69 | + * Pin 4 (swdio) - swio test point |
| 70 | + * Pin 6 (swdclk) - swck test point |
| 71 | + * Pin 10 (reset) - rst test point |
| 72 | + |
| 73 | +Finally, I connected Micro-USB input power to the board's USB connector. |
| 74 | + |
| 75 | +### Simple case |
| 76 | + |
| 77 | +If you have a supported probe, flashing the fimrware should be as simple as: |
| 78 | + |
| 79 | +``` |
| 80 | +cd ./factory |
| 81 | +python3 -m venv . |
| 82 | +source ./bin/activate |
| 83 | +python3 -m pip install -r requirements.txt |
| 84 | +python3 ./alt_flash.py |
| 85 | +``` |
| 86 | + |
| 87 | +### Flashing manually |
| 88 | + |
| 89 | +For me, the `alt_flash.py` script ran into multiple problems, so I ended up |
| 90 | +reading the script and running it "manually". |
| 91 | + |
| 92 | +#### Initial firmware |
| 93 | + |
| 94 | +This flashes the board with a utility that allows you to copy-paste the UF2 |
| 95 | +files to a Castor and Pollux board. |
| 96 | + |
| 97 | +In a separate directory: |
| 98 | + |
| 99 | +``` |
| 100 | +git clone https://github.com/adafruit/uf2-samdx1 |
| 101 | +cd uf2-samdx1 |
| 102 | +make BOARD=winterbloom_gemini |
| 103 | +``` |
| 104 | + |
| 105 | +Run `arm-none-eabi-gdb` (or equivaluent for your system), and execute the |
| 106 | +following commmands. These are based on the [GDB |
| 107 | +commands](https://black-magic.org/usage/gdb-commands.html) and [Flashing |
| 108 | +automation guide](https://black-magic.org/usage/gdb-automation.html) provided |
| 109 | +by Black Magic. |
| 110 | + |
| 111 | +The commands will: |
| 112 | + |
| 113 | +1. Connect to your debug probe. |
| 114 | +2. Ensure that the probe monitors the voltage. |
| 115 | +3. Scans for any connected debug probe. |
| 116 | +4. Attaches to the first (and hopefully only) listed device. |
| 117 | +5. "This command instructs GDB to allow access to memory outside of the devices |
| 118 | + known memory map." |
| 119 | +6. Load the relevant executable and transfers it to the device's memory |
| 120 | +7. Verifies that the files match. |
| 121 | +8. Execute the program |
| 122 | +8. Execute the program |
| 123 | +9. Stop executing and restart. |
| 124 | +10. Close GDB. |
| 125 | + |
| 126 | +``` |
| 127 | +target extended-remote /dev/ttyACM0 # Or wherever your probe is mounted |
| 128 | +monitor tpwr enable |
| 129 | +monitor auto_scan # You should see your device listed here, if not, you probably need to check your connection to the board. |
| 130 | +attach 1 # There should only be one thing, unless you've done something really magical |
| 131 | +set mem inaccessible-by-default off # I can't remember if I ran this, or if it had any effect |
| 132 | +load ~/uf2-samdx1/build/winterbloom_gemini/bootloader-winterbloom_gemini-{...}.bin # I think it was the bin, or it'll be the elf |
| 133 | +compare-sections |
| 134 | +start |
| 135 | +run |
| 136 | +kill |
| 137 | +exit |
| 138 | +``` |
| 139 | + |
| 140 | +Unplug the board, and detach the black magic probe. You should automatically |
| 141 | +get a new USB device mounted, to which you can copy-paste the UF2 C&P firmware. |
| 142 | +If the device does not appear, it may be necessary to restart your system |
| 143 | +before continuing. |
| 144 | + |
| 145 | +## Calibrations |
| 146 | + |
| 147 | +In the same environment as in [#flashing-manually], iterate through the scripts |
| 148 | +in the order as listed in [`alt_scripts.md`](./factory/alt_scripts.md), |
| 149 | +following the instructions for each calibration step. |
| 150 | + |
| 151 | +At this point, you should have a working and calibrated Castor and Pollux unit. |
0 commit comments