Linux GPIO documentation, PWM control, Device trees

Something I ‘made’, electronics related, part of one of my projects, but software in nature.

Last year I bought a MangoPI MQ-Pro, a risc-v single board computer in the Raspberry Pi Zero form-factor.

It has ‘one’ of everything; One Core, One Gigaherz, One Gigabyte. Also a SD card slot, onboard wifi/bt, usbC for power and a GPIO connector. It runs Linux quite well, so long as you dont ask too much of it.

I want to use this board as a LoRa basestation on my balcony, talking to my boat. But… first I needed to get a proper, updated and updatable linux distribution on it, then I need to control the GPIO pins.

The LoRa module is on a pi-zero HAT, it needs serial and three digital lines for use. Serial can be jumpered to either standard pi pins, or elsewhere, but the three pins are ‘fixed’ on the connector.

Also… I want to run a I2C based environment sensor (bme280), have a local I2C lcd display and control the backlight to that.

A lot of work later and I have:

A full on guide to getting the MQ-Pro up and running with Ubuntu server 24.04.1.

  • This is a LTS+ release, should be good for 5+ years
  • I’m normally a Fedora/RH guy, but Canonical are embarassingly far ahead of RH with regards to risc-v support.
  • WiFi is working (and is very stable even with the onboard antenna)
  • The board is running with the correct Device Tree

The last point is the hard one… And what my documentation is all about.

There is no official Ubuntu release for this board, but they do support a couple of other boards based on the same Allwinner D1 soc. The SD images for these can be booted and mostly work, even WiFi is detected.

But the device tree is not correct for the board and some things are not properly configured; Bluetooth is not detected and the GPIO pin header assignments are wrong.

  • Device Trees inform the boot process and then the kernel about the hardware it is running on.
  • Each Chipset has a set of device tree headers and drivers (provided by manufacturers), and then each board needs a device tree built on that.
  • And I do mean ‘built’; device trees are source. You have to compile them against the headers for your kernel and the manufacturers drivers.

The guide starts by getting a ‘vanilla’ board running; showing how to reconfigure for the correct device tree (the correct tree is already present in the linux-firmware package, it just needs to be configured as the default)

Then I show how to go further; enabling hardware interfaces (I2C, SPI, PWM, etc) in the device tree and mapping them to GPIO pins. There is tooling to build and install custom modified device trees and some examples.

And my prototype rig has life: Sensors, displays, pwm LED and a button. Linux based GPIO can be tricky, but things have been getting better lately.

I need to make the two ‘end nodes’ next; the sailing season is over so this is a new years plan.

3 Likes

Nice work…

Congratulations on getting that to work!

I did something similar maybe 8 years ago but I used an Arduino Pro Mini LoRa node I made and posted to DirtyPCB and an ESP8266(NodeMCU) gateway node(http://hallard.me) which provided local MQTT messages to a Linux LoRaWAN server(can’t find source at the moment).


1 Like

I’ve just lost a day bringing myself up to speed with a pair of meshtastic LoRa nodes; I’ve had them for years (ttgo v1 units with a OLED display and ‘do not use’ battery charg^H^H^H^H^Hcooker)

I mixed up a modular case for them back in the day; then lost interest when I couldnt find a use for them. But MeshTastic caught my eye and I now have a pair of nodes ready for the apocalypse. Or just to keep in touch with Anja…

The LoRa hat in my Boat sensor project is different, It uses Ebyte LoRa modules; these are preconfigured to talk to each other and not really compatible with generic modules. But are super-duper easy to use and I have 2x loose modules plus the HAT that will form a small private network. If I were buying parts for this again I’d choose differently :wink:

One nice thing; I have a NanoVNA; so I’ll have all the fun of tuning my antennas.

1 Like