Bare-metal Programming from the Ground Up

I’ve never come across a class with such polar opposite reviews. When I mentioned taking CS107 at Stanford, the reactions were nearly all the same. “Oh, good luck,” “Get ready to not have any time this quarter,” “That class is a doozy.” People hated it, and people loved it. It’s a class that anyone involved with the computer science (CS) department needs to take at some point during their academic career; a major milestone both for technical knowledge and for overcoming challenges.

There’s currently two versions of the course being offered at Stanford, the original CS107, and CS107E, which takes a more hands-on approach to the same material. CS107E requires an application to get in, and I happened to be one of the lucky few. The teaching staff was fantastic, headed by Chris Gregg and Phil Levis from the CS department.

The next 10 weeks of spring quarter would be my toughest academic quarter yet, and it’s unclear whether being gone almost every weekend of the quarter (for ultimate frisbee and other fun trips), or it being the famous ‘spring quarter’ had anything to do with it. Although I haven’t cried over anything academic, this course brought me close to it, and I’ve never felt so elated when a few lines of code finally worked after working on it throughout the night.

When you think of programming and computer systems, it usually comes with a variety of tools. Python, Java, countless languages, libraries, and plugins that give you the nuts and bolts you need to run your code. Bare-metal programming involves not working with an operating system. It works directly with the hardware, and that’s where the class started.

The first week involved getting used to the environment. Learning Terminal, Git, ARM Assembly Language, Bit shifting… (don’t worry if this is gibberish, it was to me too). It was a ton of new material to take on at once, especially with someone with very little background in anything systems-related. But the course was well-taught and the materials were straight-forward. By the end of week two, I had a flashing LED.

In this course we worked with a Raspberry Pi, basically a small computer. It’s that green plate with a bunch of wires sticking out of it in the photo above. Nerds on the internet have built incredible projects just using that little square, and at the end of the course, I would be too. There’s a big community surrounding the Raspberry Pi, you can check out a branch of it here: https://www.raspberrypi.org/

Most of course material was taught in an initial lecture session, then applied through the weekly assignments. Homework included implementing a clock, taking apart a keyboard, and building a graphics library, among others. The workload was quite heavy, and some weeks I put in over 30 hours of work, struggling to fix bugs and complete the assignment requirements before the deadline. I passed due to two things: a solid teaching staff and excellent classmates.

THE FINAL PROJECT

 

The course concludes with a two-week final group project which incorporates the knowledge we acquired throughout the quarter. After bouncing around multiple ideas, our group agreed upon a loop-pedal-style music project. We had seen sound produced by the Raspberry Pi before, and thought that this would be a great extension of what we had already seen.

By the end of the first week, we had reached our goal of producing sound through the Raspberry Pi by sending instructions to the MP3 chip that held multiple sound effects. However, it was in this time that we discovered the difficulty of playing multiple sounds through the Raspberry Pi at the same time. Realizing the limited time we had to complete the project, we decided to pivot the project to a topic that would incorporate more aspects of what we learned in the course.

Raspbaraoke was born; a fully interactive karaoke machine run on the Raspberry Pi. A user could list the songs available on the machine, and choose a song. The lyrics would play on the screen in time with the music. We had a few limitations on this project – such as the MP3 only having enough data to store a single song (“Eye of the Tiger”).

The breakdown of the project along with the code can be found here: https://github.com/maikaisogawa/Raspbaraoke  

To see a video of the project in action, check out the project page here!

For those interested, here’s a list of links and resources related to the concepts we covered throughout the course: