Chart Plotter Hat Software
Microprocessor Firmware
microprocessor source code on github
The microprocessor on the Chart Plotter Hat is responsible for
monitoring the push button and turning the power to the Raspberry Pi
on and off. When starting out, and a button push detected, it turns on
the 5V power supply and then waits for the pin mcu_running
to go
high as commanded by the Pi. This tells the microprocessor that the Pi
is booted up and running. When another button push is detected, it
drives the shutdown
pin high, which tells the Pi to shut itself down
cleanly. The utility on the Pi that monitors these pins is the
shutdown_monitor which is described in the section below.
The microprocessor also acts as a SPI secondary for some additional functions that the Raspberry Pi can access.
- Version information
- Turn on/off and get values from ADC pins
- Allow the eeprom memory to be written, or locked (default)
- Jump to bootloader on the microprocessor (at present, no bootloader is flashed)
- Signal whether hardware has CAN controller
The firmware runs as a state machine. The following diagram (authored in Gaphor) shows the state machine
Rust version of firmware
I attempted to rewrite this firmware using Rust. It turns out that the rust compiler/libraries for 8-bit microprocessors has too many bugs. Various parts wouldn't work even after fixing and contributing a number of bugs. Perhaps if the gcc compiler ever gets a rust front end, then we can try again. rust firmware github
Linux Utilities to work with Hat
To work with the microprocessor on the Hat, some software is required. There is 2 separate binaries one for watching the power pins, the other for communicating with the SPI secondary on the microprocessor.
There is also the data needed to flash the eeprom on the hat in this project. The other piece needed is the device tree overlay that will setup the hardware for use with the hat. Unlike PC's, there is no BIOS, or UEFI software on the device to do this function, so ARM computers use device trees that are loaded on boot to tell the Linux kernel which hardware is present and how it is connected. In our case we need to activate UART1, I2C1, SPI1, and load the CAN device driver. We also need to alter the configuration of SPI0 so it doesn't use one of it's CS pins as we are using it for something else.
The first binary is shutdown_monitor. This runs as a daemon under systemd and watches the GPIO pins. This is written in Rust.
The second binary is spitool. This is a command line utility that will interact with the SPI secondary on the microprocessor. This is written in Rust.
Sensor software
The Hat includes a Qwiic connector. For my boat computer project I have 2 devices attached to this bus. One is a real time clock. The Raspberry Pi for some reason doesn't have one. Since the boat computer is mostly not connected to the internet, it needs some other method of setting the time. I am using this clock, and also NTP software which extracts the time from the GPS. This is all setup in the provisioning software.
Another device connected is an environment sensor. This is the BME680 device that includes Temperature, Pressure, Relative Humidity, and Organic VOC in the air.
The BME680 has a linux kernel device driver, so this project then includes a python program that acts as a daemon under systemd. It reads the data from the sysfs files the driver creates. It saves the acquired data in a sqlite3 database, and also sends them out as nmea0183 sentence packets on UDP.
Provisioning the Raspberry Pi with Ansible
provisioning software on github
There is a long list of changes and additions required to the base Raspberry Pi software to get all of this running. Instead of doing it manually, I use Ansible to provision the Raspberry Pi. I forked a similar project I found on github and added/revised some roles to get everything setup.