Overview

This example demonstrates spawning multiple threads using K_THREAD_DEFINE(). It spawns up to five threads. Each thread is then defined at compile time using K_THREAD_DEFINE.

The first four threads control an LED using a custom driver named blink.

  • blink0() controls blink0_led and has a 100ms sleep cycle

  • blink1() controls blink1_led and has a 200ms sleep cycle

  • blink2() controls blink2_led and has a 300ms sleep cycle

  • blink3() controls blink3_led and has a 400ms sleep cycle

Each thread relies on the use of Zephyr Semaphores for proper thread synichronization.

Note that a multi-threaded application does not strictly require a main() function.

The last thread controls a button using a custom driver named custom_button.

  • button() controls custom_button_0

The button thread uses printk() to print a message when the button is pushed.

Button was pressed

Requirements

The IAR Zephyr application example was designed to run with the IAR STM32F429II-ACA board using a custom Device Tree specification, hence the default board is named custom_aca.

Alternatively, a overlay can be created for supported Zephyr boards under app/boards. The board must have two or more LEDs and one button connected via GPIO pins.