Getting started with CircuitPython on Fedora

One of my little maker projects has a need for a battery powered micro controller, some DIY to clean up some old equipment and some basic HW design. Ultimately I’d like to be able to integrate it as a fun thing into home automation possibly even using Matter. More on the project for another post.

To move things forward and actually be able to play with LEDs and buttons rather than doing a board port I decided to use the standard firmware. I looked through my collection of micro controllers and found a FeatherS2, it’s based on the ESP-32-S2 MCU with WiFi in a Adafruit Feather form factor with builtin LiPo charger circuit, a USB-C interface, an onboard RGB LED and runs CircuitPython.

Next up I needed to get a development environment up and running on Fedora, batteries and other HW bits can come later. First step was to work out how to getting it running the latest CircuitPython. On the CircuitPython page for the FeatherS2 there’s two firmware, one for boot and USB and then CircuitPython itself.

Step one: Ensure you’re in the dialout group
A lot of micro contollers use serial ports to interface with so you need to be able to talk to a variety of them such as ttyACM0, ttyUSB0 or ttyS0. Simplest way to do this is to add yourself to the dialout group as follows:

sudo usermod -aG dialout ${USER}

Step two: Upgrade UF2 Bootloader
This step was probably unneeded but I upgraded to the 0.11.0 release to ensure I had all the latest fixes. For this bit you need to put the board into recovery. There’s two buttons, you plug it in, press and hold BOOT, press and release RST (reset) and then a second later release BOOT. You can then run the following commands to upgrade UF2:

sudo dnf install -y esptool unzip wget
mkdir ~/CircuitPython; cd ~/CircuitPython
wget https://github.com/adafruit/tinyuf2/releases/download/0.11.0/tinyuf2-unexpectedmaker_feathers2-0.11.0.zip
unzip tinyuf2-unexpectedmaker_feathers2-0.11.0.zip
esptool.py -p /dev/ttyACM0 write_flash 0x0 combined.bin

Once the flash completes you press the RST button and the board will got into a UF2 download mode with the RGB shining a bright green. You’ll also find you have a new USB drive appear with the name of UFTHRS2BOOT. Next step is CircuitPython!

Step three: Install CircuitPython
The latest stable release when I started playing with this was 7.3.3. To install is a simple copy of the uf2 file. While it’s copying the RGB will flash orange, once complete the board will reset and reboot into CircuitPython:

cd ~/CircuitPython
wget https://downloads.circuitpython.org/bin/unexpectedmaker_feathers2/en_GB/adafruit-circuitpython-unexpectedmaker_feathers2-en_GB-7.3.3.uf2
cp adafruit-circuitpython-unexpectedmaker_feathers2-en_GB-7.3.3.uf2 /run/media/${USER}/UFTHRS2BOOT/

Step three: Actually make it do something
The standard development environment for MicroPython and/or CircuitPython is an IDE called MU Editor. It’s nicely packaged up in Fedora and seems to just work. The code in CircuitPython appears in a /run/media/${USER}/CIRCUITPY/ drive which mu automatically detects and you can get access to the python console directly within MU (correct permissions via the dialout group in step one). By default the FeatherS2 has a little app that cycles through colours on the RGB.

sudo dnf install -y mu

Next steps
The CircuitPython firmware has lots of built in functionality that just works, there’s also a large ecosystem of libraries and drivers available for Micropython and CircuitPython. Adafruit have a lot of extremely good tutorials to get you going. Next up I plan to play with getting it on my IoT network using WiFi and communicating via MQTT.

Zephyr RTOS 2.x on Fedora: Configure the build environment

It’s been a while since I’ve had time to play with the Zephyr RTOS project and the project has evolved greatly since so I thought I’d document the process I went through while playing with Zephyr 2.1 on Fedora using the Fedora native cross toolchains rather than the various ones suggested by the Zephyr Project docs.

I’m going to do a couple of posts in this series to break it up a little. This first one will be getting a generic build environment setup. I’ll go into more detail on the specific devices I’m playing with but the ones I have handy are ARM Cortex-M based so that’s what I’ll be focusing on even though Zephyr RTOS supports numerous architectures.

As before it’s worth reading the latest Zephyr Getting Started guide. This time around I’m using a AWS aarch64 a1.medium instance running a Fedora 31 cloud instance but I’ve also tested that a DigitalOcean Droplet with 2Gb RAM works with the later ZephyrRTOS releases too.

Once you have a Fedora instance up and running install the required dependencies:

# disable modularity, mostly just slows things down.
$ sudo sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/fe*mod*

# install core utils, git and cross compilers
$ sudo dnf install git-core cmake ninja-build gperf dfu-util dtc \
xz file python3-pyelftools arm-none-eabi-gcc-cs python3-pip

# requirements for the west (Zephyr meta build tool)
$ sudo dnf install python3-colorama python3-configobj \
python3-configobj python3-docopt python3-pykwalify \
python3-dateutil python3-colorama python3-docopt \
python3-pykwalify python3-packaging

We now install west:

$ pip3 install --user --upgrade west

We now have key build dependencies installed so we can initialise west and clone key repos using west (this will take a little while to do an initial clone run):

$ west init zephyr
$ cd zephyr
$ west update

Setup the Zephyr environment for cross compiling with the distribution tools:

$ export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile
$ export CROSS_COMPILE=/usr/bin/arm-none-eabi-
$ source zephyr-env.sh
$ mkdir builds

By default the above uses the git master branch of the Zephyr git repo. If you wish to use a stable branch you can just check it out. The latest stable release is, currently, 2.1 so to use this you can check out the stable branch:

$ git checkout v2.1-branch

With this we now have a Zephyr RTOS development environment setup for building for Arm Cortex-M based devices on Fedora using the distribution’s cross toolchains.