Cross Compile Rust Code for Raspberry Pi
A piece of Rust code was developed on the Windows PC. Its goal is to collect and collect and visualize real-time data from the external hardware (another embedded system, such as RP2040 MCU for example) in an experiment setup.
Data from the external hardware is sent over the USB connection (or USB/serial: FTDI 232H cable) to the PC. Now it’s time to deploy the hardware in the field for “long-term” continuous data collection.
In this case, PC (due to its cost and bulkiness) will be replaced with many instances of Raspberry Pi computers. So the Rust code needs to be cross compiled to run on Pi instead, while keeping the USB interfacing with the external hardware the same.
Here is a collection of notes on how to set up the Pi, and cross compile code on Windows to run on the Pi. Things are changing both in the realms of Pi software, as well as Rust toolset. This is the learning as of December, 2023.
2. Setup Headless Raspberry Pi
Since Pi is only used as a data logger to stream serial data into a local file for storage, we don’t need to attach monitor or keyboard to it.
Over the years, a lot of things become easier to setup Pi OS software, and to run it headless. On the other hand, some other things become more restrictive due to security concerns.
To start, use Raspberry Pi Imager to burn the latest OS image. Click into the OS setting to set up the following items before hand:
- host name (if you have multiple Pi-s to setup, choose different name for each one)
- enable SSH and login password
- set WIFI information, if available
After Pi is booted from the flashed SD card, SSH into it with the “nnn.local” (host name). Hopefully no need to NMAP out its IP address. The other way to connect to Pi is through an Ethernet cable to PC directly (link).