# Adafruit Ultimate GPS HAT on a Raspberry Pi 3b and FreeBSD 12?



## m87carlson (Apr 4, 2020)

I've been trying to get my Adafruit GPS hat to work on my RPI3 and FreeBSD 12.0-RELEASE

The issue is when I plug the GPS hat in the GPIO, and turn it on, it never updates the video console (because plugging the GPIO hat in triggered the serial console to become active?), and it never boots (because it never comes back online). From my understanding, I need to do two things:

Rebuild u-boot from ports, and set the stdin, stdout to null or vidconsole
Rebuild the rpi.dts, and set pps-gpio to pins 0 and 4
There is some existing information out there, this mailing list thread for example:


			Adding a GPS Module (hat/shield) on a Raspberry Pi
		


But it is all based on FreeBSD 11, and it appears some things have changed.

Building u-boot from ports and copying it into /boot/msdos/ just causes the device to fail booting and it attempts a pxeboot.
Also, FreeBSD 12 doesn't seem to have /usr/src/sys/boot/fdt/dts/arm/rpi.dts, but it does have /usr/src/sys/dts/arm

Also, with a Raspberry Pi 3, is rpi.dts the correct file to change, or rpi2.dts?

Is there updated docs or guidelines to accomplish this?


----------



## ralphbsz (Apr 4, 2020)

I hate to suggest it on the FreeBSD forum, but did you try it with Raspbian? Just to check that the hardware is OK?


----------



## m87carlson (Apr 4, 2020)

I haven't yet, I can give that a shot as well. I do have a spare SD card to use.


----------



## George (Apr 4, 2020)

Discussing topics on an outdated version of FreeBSD is not ideal, especially since there is still a lot of development going into the raspberry pi 3. Why not use 12.1, or even 13?


----------



## m87carlson (Apr 4, 2020)

Alright,

I have re-image the rpi3b with FreeBSD 12.1-RELEASE.

I've also built an device tree overlay file:


```
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";
        fragment@0 {
                target-path = "/";
                __overlay__ {
                        pps@0 {
                                compatible = "pps-gpio";
                                gpios = <&gpio 4 0>;
                                status = "okay";
                        };
                };
        };
};
```

Compiled it:

```
dtc -@ -o ~/pps.dtbo ~/pps.dts
```

Copied it to /boot/msdos/overlays, and added 'overlay=pps' to /boot/msdos/config.txt


Now, back to the original problem.

The device will not auto-boot once the GPS hat is plugged in.

In the u-boot prompt, I have to set stdout, stdin, and stderr manually:

```
U-Boot> setenv stdout vidconsole
U-Boot> setenv stderr vidconsole
U-Boot> setenv stdin usbkbd
U-Boot> boot
```

From the mailing list post I originally linked too, the solution seemed to be a messy patch to the sysutils/u-boot-rpi port, by changing include/configs/rpi.h

The issue with that, is u-boot's source has also changed enough that the patch files mentioned here:








						freebsd-gpio-pps/patches at master · BobBallance/freebsd-gpio-pps
					

PPS timing signals, FreeBSD 11.0, Raspberry Pi-2, GPIO - freebsd-gpio-pps/patches at master · BobBallance/freebsd-gpio-pps




					github.com
				




are not compatible with the latest u-boot.

I'm just curious if those few folks who seemed to have gotten all of this working on FreeBSD 11 have been successful on 12


----------



## m87carlson (Apr 7, 2020)

For what its worth, I did try Rasbian, and the GPS works on that


----------



## Phishfry (Apr 7, 2020)

I don't think you want to use config.txt and your overlay directory is not correct.
We load overlays via /boot/loader.conf
See the _fdt___overlays_ section for guidance.
loader.conf(5)


----------



## m87carlson (Apr 8, 2020)

Hey Phishfry , thanks a bunch for pointing that out! The wiki seemed to indicate differently. It is a tad confusing.

I moved the pps.dtbo in /boot/dtb/overlays and added:

```
fdt_overlays="pps"
```

And upon boot, I did notice a quick boot loader message about loading PPS.

Here is the gpiopps device in the kernel messages:

```
gpiopps0: <GPIO PPS> on ofwbus0
gpiopps0: PPS input on gpio0 pin 4
```

As well as pps0 in a dump for the fdt:

```
sysctl -b hw.fdt.dtb | dtc -I dtb -O dts | grep -2 pps
    #address-cells = <0x1>;
    #size-cells = <0x1>;
    pps@0 {

        status = "okay";
        gpios = <0x10 0x4 0x0>;
        compatible = "pps-gpio";
    };
    framebuffer@3e513000 {
```

So thats cool!

However, I can't seem to talk to the gps device on cuau0. An old blog post mentions completely re-compiling the dtb file for rpi with this modification:

```
aliases {
        uart0 = &uart0;
    };

    chosen {
        bootargs = "";            /* Set by VideoCore */
/*         stdin = "uart0";
        stdout = "uart0"; */
    };
```

This I think allows a tool like gpsd to use the serial line to the gps device for data.

Is it possible to add this as an overlay as well?


----------



## m87carlson (Apr 9, 2020)

I might as well continue documenting this adventure for anyone else that comes along

After changing /boot/loader.conf to

```
# Configure USB OTG; see usb_template(4).
hw.usb.template=3
umodem_load="YES"
# Disable the beastie menu and color
beastie_disable="YES"
loader_color="NO"
gpiopps_load="YES"
fdt_overlays="pps"
boot_multicons="NO"
boot_serial="NO"
```

which added the gpiospps, fdt and changes the boot_ lines both to NO

And, changing /boot/msdos/config.txt

```
arm_control=0x200
dtparam=audio=on,i2c_arm=on,spi=on
dtoverlay=mmc
dtoverlay=pwm
#dtoverlay=pi3-disable-bt
device_tree_address=0x4000
kernel=u-boot.bin
enable_uart=1
```

which commented out the pi3-disable-bt, and added enable_uart=1

I now have /dev/cuau1 device, which if I cat it:

```
# cat /dev/cuau1
$GPGGA,1.000,453223.39119,106.5,000,0000,A,3,16,,08,27,30.99,0.8C,165557.2330,N,W,0.18,5,,,D*43
05,T,,M,,K,D*03
$GPGGA,165558.00,N,122239,0.86,1.1,M,000$GPGSA,A07,04,05,,1.18,0

$GPRMC,A,4536.23.3912,3,090420PVTG,21.5,N,0.29,$GPGGA,165559331,N,122,09,0.819.1,M,0

$GPGSA09,07,040,,,,1.1*01

$GP07,77,34151,37,3,08,36,0GPGSV,3,159,38,2,05,26,2,215,34*3,3,10,0,16,07,0GPRMC,164536.233912,W,0.420,,,D*3.05,T,,15,K,D*3$GPGGA,165600.02,N,122209,0.87,.1,M,000$GPGSA,A,07,04,0,,,1.62,1

$GPRM0,A,453623.3913,25,09042GPVTG,34.10,N,0.$GPGGA,1601.000,,12223.30.86,106M,0000,0GSA,A,3,,04,05,01.18,0.8$GPRMC,1,4536.233914,W,0090420,,TG,328.5,N,0.15,$GPGGA,100,4536.3.3915,W106.1,M,0,0000*5,3,16,285,08,27,0.86,0.8C,165602.2331,N,W,0.03,10,,,D*731.45,T,,05,K,D*3$GPGGA,165603.01,N,122209,0.86,.1,M,000
$GPGSA,9,07,04,0,,,1.18,1

$GPRM0,A,4536223.3917.62,0904$GPVTG,20.09,N,0$GPGGA,104.000,412223.39.86,106.,0000,00SA,A,3,104,05,08.18,0.86GPGSV,3,341,21,0,30,49,2,096,21*3,2,10,5,27,27,0,297,14,2*7E

$G,04,20,1,044,23*165604.0332,N,120.09,231,,D*7C

41,T,,M,,K,D*33
$GPGGA,165605.00,N,122239,0.86,11,M,0000GPGSA,A,07,04,05,,1.18,0

$GPRMC,A,4536.3.3921,W6,090420PVTG,25808,N,0.1$GPGGA,165606.34,N,122,09,0.869.1,M,00

$GPGSA09,07,04,,,,,1.1801

^C
```

This is now *closer* to what I need. I suspect the tty settings for cuau1 are not correct, because each like should start with a $
like:

```
$GPRMC,194509.000,A,4042.6142,N,07400.4168,W,2.03,221.11,160412,,,A*77
```

It looks like I'm getting extra new lines (or none where there should be) so gpsd is complaining about invalid commands. Seems like it should be a simple stty fix, and the adafruit guide says to use:

```
stty -F /dev/serial0 raw 9600 cs8 clocal -cstopb
```

On my system, I would assume it would then be:

```
# stty -f /dev/cuau1.init raw 9600 cs8 clocal -cstopb

# stty -f /dev/cuau1
speed 9600 baud;
lflags: -icanon -isig -iexten -echo echoke echoctl
iflags: -icrnl -ixon -imaxbel ignbrk -brkint
oflags: -opost tab0
cflags: cs8 -parenb clocal
```

but again, cat'ing /dev/cuau1 doesn't look right and gpsd complains about the commands it is getting:

```
gpsd:WARN: bad checksum in NMEA packet; expected 52.
gpsd:WARN: unknown sentence: "$GPVT,M,0.01,39\x0d\x0a"
gpsd:WARN: device read of /dev/gpiopps0 returned error or packet sniffer failed sync (flags {ERROR})
gpsd:WARN: merge_hhmmss(14542.000N), malformed time
gpsd:WARN: bad checksum in NMEA packet; expected 4D.
gpsd:WARN: bad checksum in NMEA packet; expected 73.
gpsd:WARN: unknown sentence: "$GPVT,M,0.02,39\x0d\x0a"
gpsd:WARN: bad checksum in NMEA packet; expected 5F.
gpsd:WARN: device read of /dev/gpiopps0 returned error or packet sniffer failed sync (flags {ERROR})
```

I've given up on u-boot for now. I might try rebuilding it from ports with the patch to set stdout, stdin, and stderr but for now I just make sure I unplug the hat when it reboots and set the std settings to vidconsole and usbkbd


----------

