After these exploratory efforts (a) and (b), I really wanted to be able to build larger software projects and have a testing harness I could run on the host machine.
Here is a proof-of-concept: GitHub - jmacd/supruglue: PRU test kit
the toolchain definition: https://github.com/jmacd/supruglue/tree/main/tools/toolchain
This is fully of hacks that I came up with to work around Bazel, which is built for “standard” compilers. There are a number of crosstools examples out there for other chips (here’s a nice one), however, and this is now functional enough to use with the PRU.
It’s not completely hermetic. I download the TI CGT as an installer file, run it inside Docker, and copy the bin
, lib
, and include
directories into a .tar.gz
that Bazel can work with. I had a lot of trouble wrangling the toolchain definition, so came to work around everything I couldn’t do in the wrappers/clpru
and wrappers/arpru
scripts, which (while not well documented) is the currently practiced method for making hermetic crosstools builds in Bazel.
I’m really excited by where this is headed – my goal is to build a simple SCADA system and need pulse counting and ui1203 (a.k.a. Sensus protocol) support, but it has to be industrial strength (so, well tested). When I thought about how to implement Sensus on the PRU, two examples come up:
- GitHub - michlv/sensus_protocol_lib
- GitHub - rszimm/kmeter: a water meter (sensus) reading kernel module
One of these is written using RPI kernel modules, which makes for an asynchronous code pattern, making it difficult to read and understand (supports multiple meters). The other of these uses an Arduino sketch, making it easy to read and understand (and restricted to one meter).
I want the surpruglue
library that I’ve started here to support several meters and pulse counters at once, but I like readable code too–and these are not hard real-time requirements. Currently I’m working to use the CorePartition library to implement coroutines, so that I can have both readable code and do more than one thing at a time on the processor. The build (with tests) is already complicated, and that’s why I thought Bazel would help.