Closed djgood closed 2 years ago
Update thanks to Flynn from Balena on Discord: What I was trying to achieve with the automatic DT configuration is possible, but I was trying to do it locally through the Supervisor API, which isn't possible. There is another path through the Balena SDK (talking to the cloud API through the internet) where the device can request changes to the dt overlay. This is due to a design choice in Balena where the cloud wants to be the reporter of state changes.
This would give us the flexibility to modify the device tree configuration on the fly to enable the UART if we don't detect a USB device.
Summary
It would be nice feature to allow direct UART connection to a GPS device. Currently, we only support connections to GPS modules that contain a USB CDC ACM chip. Supporting a direct UART connection would increase the allowable possible hardware configurations users can use with Ribbit. In my case, the GPS module without a USB device was easier to find than one with.
I did some research and testing on the topic and have created this page to summarize my findings.
Background
It's important to start off saying that the UART isn't enabled by default on Raspberry Pis. There are a few different options for configuring the UART on a Raspberry Pi depending on your model and what you're trying to accomplish with the UART, which made it somewhat hard to wrap my head around at first. This page was super helpful for a crash course in the UART configuration on Raspberry Pis.
Also note that I didn't consider using the Mini-UART device that is available on some Raspberry Pis because it requires setting the core clock to a fixed frequency and from what I heard anecdotally has some reliability problems. It might be fine because we're using it at such a low baud but the more reliable hardware is there and is available for us to use so I figured that would be the better option.
Needed Configuration
From my research and testing, I was able to get my Raspberry Pi 3 UART connected directly to the GPS module and have the Ribbit code working with minimal changes. The required configuration for my Raspberry Pi 3 was as follows:
bt-disable
device tree overlay. This overlay disables the Bluetooth typically connected to the PL011 UART and makes it the primary UART (available on GPIO 14 & 15). Note that you should also make sure to turn off the service that attempts to talk to the Bluetooth over this UART withsudo systemctl disable hciuart
. Important: Following what I mentioned earlier, the Raspberry Pi Compute Modules series doesn't have ANY UARTs enabled by default, and must be explicitly enabled.if [ -c /dev/ttyACM0 ]; then echo "USB CDC device detected." GPS_SERIAL_DEV="/dev/ttyACM0" else echo "USB CDC device not found! Falling back to UART0." GPS_SERIAL_DEV="/dev/ttyAMA0" fi
gpsd -Nn -G $GPS_SERIAL_DEV
dt_overlay=disable-bt