See write-up on sagarpatil.me
- MCU: RP2040
- RTOS: FreeRTOS
- HAL: pico-sdk
Information as of Aug 28, 2023, bother Sagar if you want it updated
main
: development branch, contains latest (mostly) tested code, broken code is not allowed, POC is Sagar Patilcmdnet-secure
: encrypted version of CommandNet, POC is Sagar Patil, information on Confluenceads13x
: driver development for ADS13xMXX ADCs, POC is Mihir Patillte-modem
: LTE modem driver, POC is Jay Jaganistuff_on_pi
: random stuff from Taylor's Pi, should probably merge it, POC is Sagar Patilfreertos
: exploratory branch for FreeRTOS, POC is Sagar Patil and Charlie Schoettlevn200
: driver for the VN200 IMU, POC is Charlie Schoettletests
: working test framework, but dead branch, POC is Sagar Patilhost-compilation
: dead branch, host compilation for testing purposes, POC is Jay Jagani (?)camerons-stuff
: Dead branch, old code written for the ATMega328p, archival, POC is Cameron Williams
PSPL_CMS_Avionics_Code/
├── README.md <- This file
│
│
├── src/ <- contains main programs for each board
│ └── someprogram/ <- Main program folder, i.e., for a board
│ ├── someprogram.h <- All header stuff for this program
│ ├── main.c <- Contains the entrypoint
│ └── other.c <- Other source files
├── lib/ <- common libraries shared by all boards
│ └── example/ <- example library
│ ├── example.c
│ └── include/ <- header files, added to include path
│ ├── example.h <- top level header, included with `#include <example.h>`
│ └── example/ <- secondary headers
│ └── whatever.h <- included with `#include <example/whatever.h>`
├── device/ <- Same structure as lib, but for device drivers
│
│
├── external/ <- Gitignored, for automatically downloaded libraries(in Makefile), contains pico-sdk
├── build/ <- not uploaded to the repo, contains compilation outputs
│ └── bin/ <- contains the files to be uploaded to the boards
│
│
├── .clang-format <- file containing autoformatter rules
├── .gitignore <- file containing things to not be uploaded to GitHub(e.g., exe's, build folder)
├── Doxyfile <- Doxygen Documentation Generator Configs, mostly autogenerated
├── CMakeLists.txt <- Main build script
└── Makefile <- User-friendly build script, calls CMake
This folder contains abstractions for interacting with external hardware
(drivers), and also contains low level RP2040 specific stuff, such as a custom
implementation of spi
under myspi/
.
All of the subfolders explained
myspi/
- This exists solely due to FreeRTOS. It uses FreeRTOS mutexes so that multiple tasks can communicate with devices over SPI. For a brief summary of how it works:- Start a DMA transfer when myspi_transfer is called
- Yield the current process and wait for a task notification
- When the DMA transfer completes, it raises an interrupt
- Interrupt sends a notification to the task owning the transfer
- Task continues execution
mydma/
- Contains amemcpy
implementation which uses RP2040's DMA to copy memory without using the CPU. Operation is similar tomyspi
, but instead of data being copied to a peripheral, it's copied across memory on the RP2040.myuart/
- FreeRTOS supporting UART driver
All subsequent drivers use the above three drivers. Most of them use myspi
ads13x/
- Driver for the ADS13xMXX ADCsmax31856/
- Thermocouple amplifier and ADC driverw25n01/
- Flash driverw5500/
- Ethernet driver
git
(to clone this repo)make
(for running CMake)ninja
(CMake backend)cmake
(build system)compdb
(compile database for headers, optional)gcc-arm-none-eabi
(compiler)ccache
(compiler cache, optional)newlib-arm-none-eabi
(C standard library)
Just clone it like you normally would
All Setup and Development Operations information is on Confluence.
Run make
or make build
for a debug build, or make release
for a release build.
make clean
will delete the build folder.
Output binaries for each board will be present in build/bin/
. ELF binaries can
be found in build/bin/elf/
- Raspberry Pi 4, running Raspberry Pi OS
- 0-2 Pi Picos connected at any time, ask in #avionics for which boards are
connected
- Connected over USB
- BOOTSEL (puts the Pico into a flashable state) and RUN (reset) connected to Pi's GPIO
There's Pico A and Pico B, each with a set of bootsel and reset pins.
You can see how many Pico's are connected by running lsusb
- Zerotier VPN
- SSH
- VSCode (optional)
- Install Zerotier, ask Sagar for the network ID
- Join the network
- SSH into the Pi
VSCode Setup
- Install the Remote SSH extension
- Use the extension to connect to the Pi
Flight software is located in ~/Documents/FlightSoftware_CMS
There are scripts under scripts/
that can be used to flash code to the Pi.
They are:
flash.sh
: Copy the UF2 file to the Pico (this flashes the Pico)pico.py
: See later, this can be used to bootsel and reset the Picorouter.sh
: (Legacy, do not execute) Used to setup the Pi as a router
- Decide which Pico you want to use (A or B)
- Run
./scripts/pico.py <A/B> bootsel
- Example:
./scripts/pico.py A bootsel
- This will put the Pico into a flashable state
- You can verify this by running
lsusb
, you'll see that one of the Pico's is listed as "Raspberry Pi Pico Boot" or something similar
- Example:
- Run
./scripts/flash.sh <board-name>
- Example:
./scripts/flash.sh ntp-test
- This will flash the Pico
- Example:
- To see the output, run
cat /dev/ttyACM0
- If multiple Picos are connected, use
ls /dev/ttyACM*
to list all the output ports. - Your Pico can be either
/dev/ttyACM0
or/dev/ttyACM1
, try both
- If multiple Picos are connected, use
If at any point you want to reset the Pico, run ./scripts/pico.py <A/B> reset
Q: I'm getting a Permission Denied
error when running ./scripts/pico.py
or
./scripts/flash.sh
A: Wait a bit longer, the Pico is still booting up. If it's been more than 30 seconds, ask Sagar.
Q: Sagar isn't responding, what do I do?
A: If waiting doesn't fix the permission problem, try this
- Reset both Picos (doesn't matter if they exist or not)
./scripts/pico.py A reset
./scripts/pico.py B reset
- Run
sudo rm /media/pspl/RPI-RP2*
- This deletes any stray mount points left behind, which is probably what's causing the script to fail
Q: There aren't any Pico's listed when I run lsusb
A: Reboot the Raspberry Pi by running sudo reboot
. Exit your terminal, and
wait a bit for the Pi to reboot. Then SSH back in and try again.
Q: That didn't work, what do I do?
A: Contact Sagar and Taylor on the #avionics channel on Slack.