Making a RISC-V operating system using Rust

As RISC-V progressively challenges the existing ARM processor ecosystem it’s interesting to see more and more software projects popping up that aim that RISC-V architecture.

Here’s one project that aims to develop (and explain along the way) how to create an operating system from scratch. On top of the RISC-V specifics this tutorial also aims to teach how this all can be done in a programming language called Rust.

Keep in mind that all of this is done on a baremetal system. No other software is running.

RISC-V (“risk five”) and the Rust programming language both start with an R, so naturally they fit together. In this blog, we will write an operating system targeting the RISC-V architecture in Rust (mostly). If you have a sane development environment for RISC-V, you can skip the setup parts right to bootloading. Otherwise, it’ll be fairly difficult to get started.

This tutorial will progressively build an operating system from start to something that you can show your friends or parents — if they’re significantly young enough. Since I’m rather new at this I decided to make it a “feature” that each blog post will mature as time goes on. More details will be added and some will be clarified. I look forward to hearing from you!

The Adventures of OS

a 1980s style computer built today for fun

Can you display VGA and play audio on a Cortex-M4 in pure Rust? The short answer is yes, yes you can! Minus the hand-unrolled assembler loop for fixing the phase error in the RGB output. But we don’t talk about that in polite company.

Monotron project page

What currently is in place:

  • The Atari Joystick interface works, but two Joysticks would be more fun
  • The PS/2 Keyboard via the Atmega works, but the pinout was mirrored so you have to put the connector under the PCB :/
  • The RTC works
  • VGA Output works
  • The MIDI Out seems to work when looped to MIDI In, as does the MIDI Though.
  • The MIDI In seems to receive data when connected to my electronic drum kit
  • The Audio output seems to work quite nicely
  • The SD card works, but the power supply can’t handle hot-insertion of the SD card and it makes the TM4C reboot. More capacitors / some current limiting probably required.

I can load games and programs from the SD card into the 24 KiB of free Application RAM. You can interact with these games via the PS/2 Keyboard and Joystick. I can play simple games (like Snake) and play three channels of 8-bit wavetable audio simultaneously. I’ve even got a 6502 Emulator running a copy of 6502 Enhanced BASIC, if you want to go old school!

Localino – Indoor Location

As you might know I am regularly looking into indoor-location systems and opportunities to optimize my own system (based on Bluetooth…)

Now I cam across a concept by a german company called Localino. They’ve built their own hard- and software.

Localino has its own “satellites”, also called “anchors”. The mobile receivers are called “tags” and can locate their position based on the available anchors inside a building. Anchors and tags precisely measure signal propagation delays in the order of sub-nanoseconds, resulting in centimeter-accurate location. Any person or object wearing a tag can be located.

Localino website

There’s also a hack-a-day article on the system which states that all hard- and software would be open source. So far I did not find any source code though…

As far as I could dig into this so far it’s based upon decawave DW1000 hardware and an older base-library of this is available as source code here.

There are some other mentions which are back from 2017 when there seemingly was a big open source portion. Some python code is mentioned but nothing available right away today sadly.

REST-API testing: Reqres

I am back again and developing some smaller APIs for my own use.

As I am learning a new programming language and framework (SwiftUI) and for my little learning project I need to also implement a server backend. Implementing a RESTful service is quite straight-forward but for testing and UI prototyping I actually want to do some testing before really setting up the server side.

To easily test RESTful calls without actually implementing anything I found that Reqres is a quite useful tool to have in the toolbelt:

Apart from some pre-set-up API endpoints with dummy data (like users, …) it also features a request mirror service.

With that you can simply throw a JSON document into the general direction of Reqres and it will put a timestamp on it and return it right away.

Like so:

Writing Network Drivers in C#

Somebody had to do it. Maximilian Stadlmeier did:

User space network drivers on Linux are often used in production environments to improve the performance of network-heavy applications. However, their inner workings are not clear to most
programmers who use them. ixy aims to change this by providing a small educational user space network driver, which is gives a good overview of how these drivers work, using only 1000 lines of C code.
While the language C is a good common denominator, which many developers are familiar with, its syntax is often much more dicult to read than that of more modern languages and makes the driver seem more complex than it actually is.

For this thesis I created a C# version of ixy, named ixy.cs, which utilizes the more modern syntax and additional safety of the C# programming language in order to make user space network driver development even more accessible. The viability of C# for driver programming will be analyzed and its advantages and disadvantages will be discussed.

The actual implementation (with other programming languages as well) can be found here.

Apparently it’s not as slow as you might think:

Odometer for the HUD

Since I am back at developing the Head-Up-Display app I was writing about in February (yeah, mornings got darker again!) I want to leave this nice looking Odometer Javascript library here:

Odometer is a Javascript and CSS library for smoothly transitioning numbers. See the demo page for some examples.

Odometer’s animations are handled entirely in CSS using transforms making them extremely performant, with automatic fallback on older browsers.


Bulletin Board Systems in the wild

While recording a podcast episode we briefly touched on the topic of bulletin board systems and how we both had operated our own FidoNet BBS in the 90s.

To create a bigger reflux of thoughts:

Synchronet Bulletin Board System Software is a free software package that can turn your personal computer into your own custom online service supporting multiple simultaneous users with hierarchical message and file areas, multi-user chat, and the ever-popular BBS door games.

Everything there to set-up a BBS. Maybe I really need to get out a backup of my old BBS and bring it back online?!

TIL: iPhone Visual Voicemal is IMAP

Today I learned that the Apple iPhone re-purposes the IMAP protocol to implement the voice mail feature.

By sniffing the network traffic it was possible to examine the IMAP protocol revealing username and the corresponding hashed password (which allows to repeat a successful login) and of course all voicemail files. We want to highlight, that all the voicemail files have been transferred unencrypted.

Assessment of Visual Voicemail from 2012

replacing MyFitnessPal

Well, it’s about time to do something about MyFitnessPal. In our family we’re using their service by the daily. But just for logging. No reports, no further features used.

But still, we were using it for quite a time now:

almost 5 years logged every-single-day.

The service has started to roll out ads for some time now in their apps. There are only iOS / Android apps available. And a mediocre website.

Just recently they started to announce that their free service will restrict how many years back are going to be stored. From those 5 years we will loose 3.

In addition the whole integration has never gotten to a point where I would have decided to upgrade to the paid premium version. No functionality ever got added. No interfacing with scales, no optimizations for UI/UX, …

But they now reduce the functionalities and service and want me to cough up a bit of money:

I am not generally against subscriptions. But I am not getting 9,99 Euro of value out of the service. A shared google sheet would almost achieve parity. And the price itself is just not value based. For 2 Euro I probably would not feel the urge to move on. For 9,99 (times 2 for 2 accounts) make me move.

So I’ve sat down with my wife and we scribbled up some things we want to have in a replacement. The content and feature-set is agreed. Now I’ll throw up a prototype app.

It’ll be integrated with the MQTT scales. And with the flow we came up with we hopefully will reduce the interactions dramatically over MyFitnessPal. And it’ll never stop saving history. And I’ll learn something new.

ASCII browser games

A lot is going on in browsers these days. They are becoming increasingly powerful and resource-demanding.

So it just feels natural to combine high resource usage infrastructure with low resource using graphics to get the worst of both worlds.

Not quite, but you get the idea.

There’s a guy on the internet (haha) who dedicates time to write ASCII / character based graphics engines and games with it.

Meet MrGumix:

Of course, what’s that games and graphics?

Exhibit #1:

And the more advanced Exhibit #2:

using AI to generate human faces from emojis and thumbnails

Back in March 2019 we’d already seen artificial people. Yawn.

Back then a Generative adversarial network (GAN) was used to produce random human faces from scratch. It synthesized human faces out of randomness.

Now take it a step further and input actual small images. Like thumbnails or emojis or else.

And what do you get?

Quite impressive, eh? There’s more after the jump.

Oh and they wrote a paper about it: Progressive Face Super-Resolution via Attention to Facial Landmark

global QR code scavenger hunt

I like location based stuff. I like QR codes. There is something that combines both.

Meet Munzee:

Munzee is the next generation in global scavenger hunt games.

Track down QR Codes hidden in the real world and capture them for points. Whether you are a casual player, an avid explorer, or a hardcore competition enthusiast, Munzee helps you rediscover the world around you.

Magnificent app which corrects your previous console command

We all know this. You typed a loooong line of commands in your shell and you made one typo.

That’s the worst.

Now. There’s a command that aims to help:

It is rather simple. But extremely effective.

The Fuck attempts to match the previous command with a rule. If a match is found, a new command is created using the matched rule and executed.

Grab it on github. Install it right away. It went into my toolbelt in an instant.

Hertzian Landscapes

I played with SDR – Software Defined Radio – back in 2013. I’ve still got the equipment around.

Now that I am thinking about it – there is a practical use-case that I will look into in the coming months for sure for it. And just to mention this use case here: With SDR I could create a more versatile 443/886 Mhz receiver.

Anyhow. SDR hardware allows you to access a whole spectrum of radiosignals at once. And a common way to visualize the spectrum is to draw the amplitudes in a line add each new measurement as a new line – color/brightness coded.

What you get is some sort of waterfall diagram that looks like this:

Hertzian Landscapes (2019) is a live visualization of the radio spectrum. Unlike visible light, waves in the radio spectrum cannot be perceived by us directly yet this space is teeming with human activity. Hertzian Landscapes employs a digital receiver to scan large swaths of radio spectrum in near real-time and visualizes thousands of signals into a panoramic electromagnetic landscape. Users can zoom in to specific frequencies by positioning themselves in front of the panorama as if controlling a radio tuner with their body, giving them a sense of walking through the spectrum.
From radio broadcasts to weather satellites and from medical implants to aeronautical navigation, the radio spectrum is divided into hundreds of designated slices each tied to a specific application. Based on a localized frequency database that describes these slices, signals are annotated to provide information about their theoretical type and application.

C# PlayStation emulation

After looking into the NES emulation written entirely in C# I came across a similar approach using C# to emulate a full and much more complex PlayStation 1.

Scott Hanselman wrote:

I then stumbled on this very early version of a PSX Emulator in C#.

Now, if you were to theoretically have a Playtation SCPH1001.BIN BIOS and then physically owned a Playstation (as I do) and then created a BIN file from your physical copy of Crash Bandicoot, you could happily run it as you can see in the screenshot below.

Why the MS-DOS floppy disk cache was valid 2 seconds…

If you’re old enough to have used MS-DOS you know the benefits a read cache introduced back at the time for floppy disks. Without such a cache everything data intensive was magnitudes slower.

Now after all these years more and more stories emerge about how certain thresholds and timeings where set back in the days.

This is such a story:

Mark Zbikowski led the MS-DOS 2.0 project, and he sat down with a stopwatch while Aaron Reynolds and Chris Peters tried to swap floppy disks on an IBM PC as fast as they could.

They couldn’t do it under two seconds.

So the MS-DOS cache validity was set to two seconds. If two disk accesses occurred within two seconds of each other, the second one would assume that the cached values were still good.

Raymond Chen blog

There are more links in the original article – so go there and down that rabbit hole!

Experimental Audio Tool: SuperCollider

SuperCollider is a platform for audio synthesis and algorithmic composition, used by musicians, artists, and researchers working with sound. It is free and open source software available for Windows, macOS, and Linux.

SuperCollider features three major components:

scsynth, a real-time audio server, forms the core of the platform. It features 400+ unit generators (“UGens”) for analysis, synthesis, and processing.

sclang, an interpreted programming language. It is focused on sound, but not limited to any specific domain. sclang controls scsynth via Open Sound Control.

scide is an editor for sclang with an integrated help system.

Fonts for Coders: Cascadia

Microsoft recently is releasing a lot of tools and assets for developers and terminal monkeys.

This is good. Very nice of them.

The recent release of a font specifically for terminal and code editing use seems worth a mention here:

Cascadia Code was announced this past May at Microsoft’s Build event. It is the latest monospaced font shipped from Microsoft and provides a fresh experience for command line experiences and code editors. Cascadia Code was developed hand-in-hand with the new Windows Terminal application. This font is most recommended to be used with terminal applications and text editors such as Visual Studio and Visual Studio Code.

Cascadia Code announcement

What’s most interesting about this: It’s got code ligatures. Just recently a lot of development focussed fonts showed up and they started to incorporate special characters for development specific character combinations:

Cascadia Code supports programming ligatures! Programming ligatures are most useful when writing code, as they create new glyphs by combining characters. This helps make code more readable and user-friendly for some people.


good wireguard tutorial

If you, like me, are looking into new emerging tools and technologies you might also look at Wireguard.

WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. Initially released for the Linux kernel, it is now cross-platform (Windows, macOS, BSD, iOS, Android) and widely deployable. It is currently under heavy development, but already it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry.

bold wireguard website statement

To apply and get started with WireGuard on Linux and iOS I’ve used the very nice tutorial of Graham Stevens: WireGuard Setup Guide for iOS.

This guide will walk you through how to setup WireGuard in a way that all your client outgoing traffic will be routed via another machine (server). This is ideal for situations where you don’t trust the local network (public or coffee shop wifi) and wish to encrypt all your traffic to a server you trust, before routing it to the Internet.

WireGuard Setup Guide for iOS.

Simple Windows Text Expander

If you, like me, once every while need to type the same again and again it might also get tired for you as it got for me.

A specific example: I very frequently need to have the current date available to be entered.

May it be because I need to name a file correctly, prepending it with the current date, or because I need it to refer to a specific date in a text I am currently typing.

The common scheme for dates I am using is YYYY-MM-DD. The 24th of September 2019 becomes 2019-09-24.

click to download

For when I am on Windows I am using a small utility called “TyperTask” to have a system wide shortcut available to me that will enter the current date with the press of a button.

As you can see in the screenshot above. By simply adding / editing the TXT file you will be able to specify new shortcuts. In the above case ALT+D or STRG+SHIFT+D will generated my desired date text pattern.

It’s freeware. It’s from a company that ceased to exist. It’s 60kbyte. Download while supply lasts.

Multi-Sensor board progress

Still working on these

Still lots of errors and challenges to positioning and casing. It works electrically and in software. Does not yet fit into a case.

It’s supposed to get you these sensors accomodated:

  • barometric pressure
  • temperature
  • humidity
  • PIR motion
  • light intensity
  • bluetooth scan/BLE connectivity
  • Wifi scan / Wifi connectivity

And a RGB LED as output. All powered by USB and an ESP32.

2001-era docomo flip phone emoji font

NTT DoCoMo might not have been the first ones to release feature phones with actual emoji characters to be used in text messaging. But their set of original emojis is just oh-so-beautiful to look at.

With the help of Monica Dinculescu we now can enjoy these emojis on our modern era computing machines.


You can either get the font downloaded for free directly from Monicas page or you could use her SVG code to further make use of the great emojis.

the font download will get you this

If you go for the SVG link you will get some overview alike the one at the start of this post. If you wanted to further work with the raw vector data (SVG) in there you could use this simple trick:

Step 1: locate the emoji you want in the code of the page. Maybe by utilizing the developer tools of your browser.

Step 2: Copy that specific element that you want to your clipboard / into a new text document.

Step 3: add the proper header tag before the element you’ve copied.

<?xml version="1.0" encoding="utf-8"?>

Step 4: Save the contents now as a file with the .svg ending. You can now open it up in any SVG compatible editor, like Inkscape.

smart arduino fish pond feeder: TurtleFeeder

We’ve got several quite big fish tanks in our house. Mainly used by freshwater turtles.

say Hi! to Wilma.

These turtles need to be fed every once in a while. And while this is not an issue normally it’s an issue if you leave the house for travel for an extended period of time.

Of course there are humans checking on everything in the house regularly but as much as can be automated should and will be automated in our household. So the requirement wa to have the turtle feeding automated.

To achieve this is would be necessary to have a fixed amount of turtle food be dispensed into the tanks on a plan and with some checks in the background (like water quality and such).

It’s been quite a hassle to come up with a plan how the hardware should look like and work. And ultimately i’ve settled on retrofitting an off-the-shelf fish pond feeder to become controllable through MQTT.

The pond feeder I’ve found and used is this one:

It’s not really worth linking to a specific product detail page as this sort of feeder is available under hundreds of different names. It always looks the same and is priced right around the same.

If you want to build this yourself, you want one that looks like the above. I’ve bought 3 of them and they all seem to come out of the same factory somewhere in China.

Anyway. If you got one you can easily open it up and start modifying it.


the wheel is turned by a DC motor and the switch is triggered by the wheels fins
I’ve added a connector to the switch and the motor cables for quick connect

The functional principle of the feeder is rather simple:

  1. turn the feeder wheel
  2. take the micro-switch status in account – when it’s pressed down the wheel must be pushing against it
  3. turn it until the micro-switch is not pressed anymore
  4. turn some more until it’s pressed again

Simple. Since the switch-status is not known on power loss / reboot a calibration run is necessary (even with the factory electronics) every time it boots up.

After opening the feeder I’ve cut the two cables going to the motor as well as the micro-switch cables. I’ve added a 4-Pin JST-XH connector to both ends. So I can reconnect it to original state if desired.

These are all the parts needed:

I am using a Wemos D1 Mini and a couple of additional components apart from the prototype board:

A PN2222 NPN transistor, a rectifier diode 1N4007 and a 220 Ohm resistor.

I’ve connected everything according to this schematic I’ve drawn with Fritzing:

I’ve then prototyped away and put everything on the PCB. Of course with very limited solderig skill:

As you can see the JST-XH connector on Motor+Switch can now be connected easily to the PCB with all the parts.

Make sure you check polarity and that you did correctly hook up the motor and switch.

When done correctly the PCB (I’ve used 40mm x 60mm prototype pcb) and all cables will fit into the case. There’s plenty of room and I’ve put it to the side of it. I’ve also directly connected an USB cable to the USB port of the Wemos D1 Mini. As long as you put at least 1A into it it will all work.


Since the Wemos D1 Mini sports an ESP8266 and is well supported by Arduino it was clear to me to use Arduino IDE for the software portion of this project.

Of course everything, from schematics to the sourcecode is available as open source.

To get everything running you need to modify the .ino file in the src folder like so:


What you need to configure:

  • the output pins you have chosen – D1+D2 are pre-configured
  • WiFi SSID + PASS
  • MQTT Server (IP(+Username+PW))
  • MQTT Topic prefix

Commands that can be sent through mqtt to the /feed topic.

MQTT topics and control

There are overall two MQTT topics:

  • $prefix/feeder-$chipid/state
    This topic will hold the current state of the feeder. It will show a number starting from 0 up. When the feeder is ready it will be 0. When it’s currently feeding it will be 1 and up – counting down for every successfull turn done. There is an safety cut-off for the motor. If the motor is longer active than configured in the MaximumMotorRuntime variable it will shut-off by itself and set the state to -1.
  • $prefix/feeder-$chipid/feed
    This topic acts as the command topic to start / control the feeding process. If you want to start the process you would send the number of turns you want to happen. So 1 to 5 seems reasonable. The feeder will show the progress in the /state topic. You can update the amount any time to shorten / lengthen the process. On the very first feed request after initial power-up / reboot the feeder will do a calibration run. This is to make sure that all the wheels are in the right position to work flawlessly.

So if you want to make it start feeding 3 times:

mosquitto_pub -t house/stappenbach/feeder/feeder-00F3B839/feed -m 3

And if you want to see the state of the feeder:

mosquitto_sub -v -t house/stappenbach/feeder/feeder-00F3B839/state

All in all there are 3 of these going to be running in our household and the feeding is going to be controlled either by Alexa voice commands or through Node-Red automation.

Homebrew AR: HoloKit

Augmented Reality – AR – is getting some buzz here and there throughout the last 20 years almost. With hardware becoming more powerful and optics+light hardware becoming cheaper and more efficient it’s still all but close to become widely used and available.

Many refer to some one-trick pony feature in location-based games like “Pokemon Go” to being “AR”. But actual useful cases of AR are there but not feasible with current hardware generations.

Nevertheless a team in california has taken our the scissors and keyboards and made HoloKit:

HoloKit features super sharp optics quality and a 76-degree diagonal field of view. Pairing with a smartphone, HoloKit can perform an inside out tracking function, which uses the changing perspective on the outside world to note changes in its own position. HoloKit merges the real and the virtual in a smart way. While you see through the real world, virtual objects are blended into it. Powered by the accurate gyro and camera on smart phones, HoloKit solidly places virtual objects onto your table or floor, as if they were physically there without physical makers. These virtual objects will stay in the same place even if you walk away, just like real physical objects.

HoloKit is different from screen-based AR experience like Tango. You can directly see through the headset and view the real world as is, and in the meantime the virtual objects are projected on top of the real world, as opposed to viewing both the real and the virtual through a smartphone camera.

An Introduction to D3.js

Browsers can do many things. It’s probably your main window into the vast internet. Lots of things need visualization. And if you want to know how it’s done, maybe do one yourself, then…

D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.


And to further learn what it’s all about, go to Amelia Wattenbergers blog and take a stroll:

So, you want to create amazing data visualizations on the web and you keep hearing about D3.js. But what is D3.js, and how can you learn it? Let’s start with the question: What is D3?

While it might seem like D3.js is an all-encompassing framework, it’s really just a collection of small modules. Here are all of the modules: each is visualized as a circle – larger circles are modules with larger file sizes.

An Introduction to D3.js

create 3D environments with your phone – early access

Augmented Reality needs proper 3D geometry and the ability to sense the environment to interact with it. At some point I would expect tools to show up that allow us to do some of this ourselves.

Seems like we’re one step closer. Ubiquity6 is reaching out to get early access to interested users:

We’re giving early access to our 3D mapping tools for creators and artists! If you’re interested in trying it out sign up for early access here:

Ubiquity6 on Twitter

Of course. I applied. And I’ve just started testing.

text replacements for Tokyo ward and kens on iOS and macOS

I am having a hard time learning japanese and reading/writing the kanji especially.

Having to write japanese city names frequently (for example when doing searches) I still do remember the spoken out version of the name but I do not quite yet remember the kanji version. Also I do not want to switch back and forth in keyboard languages.

For this, especially in macOS and iOS there is a nice way around this. With the built-in “Text Replacement” feature of your Mac or iPhone/iPad you can easily mass-import a mapping between the romanized version of a word and the japanese written out kanji version of that word.

While you are typing then you will be presented with recommendation text replacements, effectively the kanjis of what you’ve just tried to write.

see the text recommendations above the keyboard

Unfortunately I do not know a way how to mass-import these text-replacements on iOS.

But if you own a macOS computer and you have it synced over iCloud with your mobile phone or tablet you will likely be able to open the text replacement pane in your system settings and import this plist file into it. Simply drag the file (after unzipping the ZIP file) into the text replacement window.

Download the file. Extract it (double clicking). And drag the .plist file into the Text Replacement Window.

For you to derive your own files you can find the raw data, a list of all designated Ken and Ward names in Tokyo here:

nodes – a new way to create with code

In Nodes you write programs by connecting “blocks” of code. Each node – as we refer to them – is a self contained piece of functionality like loading a file, rendering a 3D geometry or tracking the position of the mouse. The source code can be as big or as tiny as you like. We’ve seen some of ours ranging from 5 lines of code to the thousands. Conceptual/functional separation is usually more important.

Nodes* is a JavaScript-based 2D canvas for computational thinking. It’s powered by the npm ecosystem and lives on the web. We take inspiration from popular node-based tools but strive to bring the visual interface and textual code closer together while also encouraging patterns that aid the programmer in the prototype and exploratory stage of their process.
*(not to be confused with node.js)