One-Minute LED Blinker

This is a video demonstration using the Satellite System to create a simple LED Blinker for the Chocolate board from scratch, build and flash it to the Chocolate board, and have it running on the board in under one minute.

Please forgive the poor video quality- I am filming using an old camera that is balanced on top of a box.

The board begins in a default pre-flashed but essentially empty state. The microcontroller (MCU) contains an empty image, and the CPLD has been pre-flashed with the Rascal CPLD image (the default for both).

The ls command confirms that we are genuinely starting from scratch. There are initially no files in our working directory.

The satdev new blinky command creates a new project. To determine the hardware to build for, it scans for connected Satellite boards. In this case it has detected the board that we just plugged in: A Chocolate board with hardware revision 0.2. The tool then asks some follow-up questions, with [enter] selecting a sensible default. It then creates a simple initial project for you. The project is created in a directory of the specified name (blinky in this case) and contains two files: a configuration file, and an source file.

We confirm this new directory has been created with ls. Next, we enter the directory (cd blinky), and confirm the two files are there (ls).

We then edit the source file (custom.cpp), which in our current configuration contains two functions: Init(), which is called once during initialisation; and Update(), which is called once per update of the main loop on the MCU.

In this case we add two statements to the Update() function. The first statement is:


For the Chocolate board, a number of GPIO definitions are added by default to the sat::resource namespace (this can be changed in the configuration file), and one of these is the GPIO object for the PC0 pin. The toggle() method ensures that the pin is set to output and sets the output high if it was low, or low if it was high.

The second statement we add is:


In this case we take the System object sys (an object that contains system-specific information, in this case representing the specific MCU we are using) and wait for 250ms (about 1/4 of a second). Technically we shouldn't perform a delay like this in the Update() function, instead calling something like sat::sys->ticks() to get the current elapsed time in milliseconds, and setting the LED accordingly. However, for the sake of simplicity in this example, it should suffice.

In this case we do not need to edit the sat.cfg file, but it if we did, it looks like this:

  board chocolate 0.2 rascal
  has_custom_hooks y
  build_files custom.cpp

This file specifies that we are using the Satellite board Chocolate with hardware revision 0.2, and using the Rascal CPLD image. This determines a large number of sensible defaults automatically for us. Under the device section (!device) we indicate that we have custom hooks included (Init() and (Update()), and that we should include the file custom.cpp in the build. These defaults are exactly what we want for the LED blinker, so we do not have to make any changes here.

We next issue the command:

  satdev flash

This indicates that we (ultimately) want to flash the built image to the MCU on the board. Before we can flash the built image we need to build it, and before we can build it we need to configure the project and create a Makefile. The single command satdev flash takes care of all of this for us.

While the project is building, we connect a 2x5 IDC cable to the programming header. The other end of the cable (not shown) is connected to a series of jumper wires that are connected to the GPIO headers on a Raspberry Pi. If you don't have a 2x5 IDC cable, you can get by with a set of four female-to-female jumper wires connecting the corresponding Pi pins to the board. An IDC cable makes it easier though.

In short order the build finishes, and the result is flashed to the MCU. The MCU is reset, and our LED blinker runs.

You may be wondering why the five LEDs are flashing at the same time. By default, the Rascal CPLD image routes the MCU outputs from PC0-2 to the five LEDs. PC0 controls the red on all five LEDs, PC1 the green, and PC2 the blue. This allows you to control all five LEDs together using just three lines. This is not the only way to control the LEDs. With a simple configuration change you can allow the five LEDs to be controlled individually- more on that later on in the next post.

< Overview
USB Control >
^ Overview ^

Garth is generally available for part-time, casual, and full-time appointments, ad-hoc, short-term or long-term. Click here for further information, or here for Garth's contact details.