deckle studioOpen in the editor

ESP32-C3 (RISC-V) with Zephyr firmware

RISC-V with Zephyr: a button switches an LED.

  • ESP32-C3
Open in the simulatorNo account needed: press Simulate and it runs.

How it works

ESP32-C3 as on the SuperMini board: RISC-V core (RV32IMC, 160 MHz) with real Zephyr firmware. Button SW1 on GPIO9 (BOOT) switches the blue LED on GPIO8 through the GPIO interrupt. Swap the firmware in the inspector: blinky, fade_led (LEDC PWM), hello_world (UART on GPIO21). Your own firmware: load zephyr.elf or zephyr.bin for esp32c3_devkitm.

Wiring

Each line is one connection (net) and the pins it joins.

NetPins
GNDC1 2D1 KSW1 2U1 GNDV1 −
3V3C1 1U1 3V3V1 +
BOOTSW1 1U1 GPIO9
LEDR1 1U1 GPIO8
LED_AD1 AR1 2
D1
LED

Parts

Firmware

src/main.c · 45 lines

/*
 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

#include <inttypes.h>
#include <zephyr/drivers/led.h>
#include <zephyr/input/input.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

#define LED0_NODE DT_ALIAS(led0)

#if DT_NODE_HAS_STATUS_OKAY(DT_PARENT(LED0_NODE))
static const struct led_dt_spec led0 = LED_DT_SPEC_GET(LED0_NODE);
#else
static const struct led_dt_spec led0;
#endif

static void button_input_cb(struct input_event *evt, void *user_data)
{
	if (evt->sync == 0) {
		return;
	}

	printk("Button %d %s at %" PRIu32 "\n",
	       evt->code,
	       evt->value ? "pressed" : "released",
	       k_cycle_get_32());

	if (led0.dev != NULL) {
		led_set_brightness_dt(&led0, evt->value ? 100 : 0);
	}
}

INPUT_CALLBACK_DEFINE(NULL, button_input_cb, NULL);

int main(void)
{
	printk("Press the button\n");

	k_sleep(K_FOREVER);

	return 0;
}
Open in the simulator

More examples: Microcontrollers