Golang to the rescue on embedded with TinyGo

Background

First I spent many hours to try get Zephyr RTOS up and running on some Nordic Semi boards.

I finally had some success on OpenBSD, but I never got a simple LED blink app to function correctly on the boards.

So in desperation I looked for alternatives. I went back to basics and installed Nordic Semi old nRF SDK which does not have any RTOS. Its hard to understand that these two options is available as Nordic seem to push users to their new nRF Connect SDK instead which is based on Zephyr. By using Segger Embedded Studio I was able to build and flash a working sample app.

But I had come across another interesting project for embedded development TinyGo which seemed very attractive. So I had to try that as well.

Install TinyGo

So I installed TinyGo on my old macOS. It turned out to be trivial. See Quick Install.

brew tap tinygo-org/tools
brew install tinygo

Compared with Zephyr install this is magnitudes less complicated.

The tinygo tool is written in golang so it is assumed that go is installed as well. To install go also happen to be trivial.

From previous installation of Nordic Semi SDKs I already had some basic tools installed.

These tools are also used by TinyGo to interact with Nordic Semi boards.

LED blink with TinyGo

So I tried to make a simple example app a Blinking LED.

Setup this project in a separate folder.

mkdir blinky
cd blinky

Setup a separate go module for the project.

go mod init blinky

Create the program main file named main.go.


package main

import (
    "machine"
    "time"
)

func main() {
    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})
    for {
        led.Low()
        time.Sleep(time.Millisecond * 500)

        led.High()
        time.Sleep(time.Millisecond * 500)
    }
}

Connect your board via USB connector.

Build and flash the project.

For nRF53840 development board.

tinygo flash -target=pca10056 main.go 

For nRF53840 dongle.

tinygo flash -target=pca10059 main.go

The same code and it just works!

Reflections

If this project gets some momemtum this seems to be a very attractive way to develop embedded solutions.

But of course it is a matter if enough boards and devices will be supported. And if you get the flexibility needed to develop embedded solutions.

But so far currently many boards and devices are already supported. Even a go based Bluetooth stack is in the works.