
The K32 is another Cortex M0+ processor, similar to the ones that I've used in the past, like the KL25 and the K43. I'm using the K32 because it is supported, out of the box by the TinyUSB framework, which I want to leverage for MIDI music control.
Typically, though, before we get started with anything as complicated as a USB framework or MIDI control, we need to get some basics down, including:
- Setting up LEDs
- Setting up and validating timers
Here I'm going to set up the LEDs and then use the MCUXpresso IDE to single-step through the code. The code uses the blinky_light example from the SDK and then I modified it to conform to the SDK calls used by TinyUSB in order to be consistent with that usage.

#include "pin_mux.h"
#include "board.h"
#include "fsl_gpio.h" // Not typically added in template.
#include "fsl_port.h" // Not typically added in template.
/*******************************************************************************
* Definitions
******************************************************************************/
#define BOARD_LED_GPIO BOARD_LED_RED_GPIO
#define BOARD_LED_GPIO_PIN BOARD_LED_RED_GPIO_PIN
// LED1 (Green) PTD5 - D13/SCK/LED/int
#define LED_PIN_CLOCK kCLOCK_PortD
#define LED_GPIO GPIOD
#define LED_PORT PORTD
#define LED_PIN 5
#define LED_STATE_ON 0
// LED2 (Red) PTE31/TPM0_CH4
#define LED2_PIN_CLOCK kCLOCK_PortE
#define LED2_GPIO GPIOE
#define LED2_PORT PORTE
#define LED2_PIN 31
#define LED2_STATE_ON 0
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
volatile uint32_t g_systickCounter;
/*******************************************************************************
* Code
******************************************************************************/
// helper function to turn an LED on or off. (Green LED)
// This is how TinyUSB does it.
void board_led_write(bool state)
{
GPIO_PinWrite(LED_GPIO, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
}
// New helper function to turn an LED on or off. (Red LED)
// This is how TinyUSB does it (but doesn't include this particular version)
void board_led2_write(bool state)
{
GPIO_PinWrite(LED2_GPIO, LED2_PIN, state ? LED2_STATE_ON : (1-LED2_STATE_ON));
}
/*!
* @brief Main function
*/
int main(void)
{
/* Board pin init */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Set up the RED and GREEN GPIO
* LED1 is GREEN. On Arduino pin D13. On the K32 it's pin PTD5 - D13/SCK/LED/int
* LED2 is RED. No specific Arduino pin. On the it's K32 PTE31/TPM0_CH4 */
CLOCK_EnableClock(LED_PIN_CLOCK); // FSL Library:Turn on GPIO port for first LED
CLOCK_EnableClock(LED2_PIN_CLOCK); // FSL library:Turn on GPIO port for the 2nd LED
// Configure LED1 (GREEN) as output and turn off.
gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0 }; // kGPIO_DigitalOutput means 1U. 1 is output.
GPIO_PinInit(LED_GPIO, LED_PIN, &led_config); // Init LED1
PORT_SetPinMux(LED_PORT, LED_PIN, kPORT_MuxAsGpio); // Set up pin MUX for LED1
// Configure LED2 (RED) as output and turn off.
gpio_pin_config_t led2_config = { kGPIO_DigitalOutput, 0 }; // ?????
GPIO_PinInit(LED2_GPIO, LED2_PIN, &led2_config); // Init LED2
PORT_SetPinMux(LED2_PORT, LED2_PIN, kPORT_MuxAsGpio); // Set up pin MUX for LED2
while (1){
// Turnj the two LEDs on then off.
board_led_write(1); // Green on
board_led_write(0); // Green off.
board_led2_write(1); // Red on
board_led2_write(0); // Red off
__asm volatile ("nop");
}
}
The origin of Blinkenlights
Where does Blinkenlights come from? I remember seeing a post in the CEMIS high school computer lab run by Bev Weber and Gord Pierce, probably around 1990 or 1991. The Wikipedia page says that it dates back even longer.


James Andrew Smith is a Professional Engineer and Associate Professor in the Electrical Engineering and Computer Science Department of York University’s Lassonde School, with degrees in Electrical and Mechanical Engineering from the University of Alberta and McGill University. Previously a program director in biomedical engineering, his research background spans robotics, locomotion, human birth, music and engineering education. While on sabbatical in 2018-19 with his wife and kids he lived in Strasbourg, France and he taught at the INSA Strasbourg and Hochschule Karlsruhe and wrote about his personal and professional perspectives. James is a proponent of using social media to advocate for justice, equity, diversity and inclusion as well as evidence-based applications of research in the public sphere. You can find him on Twitter. You can find him on BlueSky. Originally from Québec City, he now lives in Toronto, Canada.
