diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9a8b48d985aaa103ae2899b6f8ae6c5ed7e263f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Environment +.venv/ +.west/ + +# West bullshit +zephyr/ +modules/ +tools/ +bootloader/ + +# Application artifacts +build/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..31d811a391ea684b51aed961d2312b308fc910da --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +BSD 2-Clause License + +Copyright (c) 2026, Mitja Felicijan + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2ae320614febf8e183395245edc6f4b9425407b7 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Zephyr RTOS ESP32 blinky + +## Hardware + +- [DFR0478 FireBeetle ESP32](https://si.farnell.com/dfrobot/dfr0478/firebeetle-esp32-iot-mcu-arduino/dp/3517881?CMP=e-email-sys-orderack-GLB) + +## System requirements + +Other distributions will require different packages. + +```sh +sudo xbps-install -S gcc ninja cmake make python3 python3-devel python3-pip +sudo xbps-install -S gcc-multilib glibc-devel-32bit libgcc-devel-32bit +``` + +## Install toolchain for real hardware + +```sh +mkdir ~/Toolchain +cd ~/Toolchain +wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v1.0.1/zephyr-sdk-1.0.1_linux-x86_64_gnu.tar.xz +tar xvf zephyr-sdk-1.0.1_linux-x86_64_gnu.tar.xz +cd zephyr-sdk-1.0.1 +./setup.sh +``` + +## Getting started with a project + +```sh +# Clone +git clone git@github.com:mitjafelicijan/zephyr-esp32-blinky.git +cd zephyr-esp32-blinky + +# Environment +python -m venv .venv +source .venv/bin/activate +pip install --upgrade pip +pip install west +west packages pip --install + +# Fetch requirements and tooling +west init +west update +west zephyr-export + +# Go to application directory +cd apps/blinky + +# Compile and run on host +make host-build +make host-run + +# Compile and flash ESP32 board +make esp-build +make esp-flash + +# Serial monitor of ESP32 +make esp-monitor +``` diff --git a/apps/blinky/CMakeLists.txt b/apps/blinky/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..64e9fd598c749a153a8555f28add27461911c8cc --- /dev/null +++ b/apps/blinky/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(blinky) + +target_sources(app PRIVATE src/main.c) diff --git a/apps/blinky/Makefile b/apps/blinky/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..da37f425b7c8f1d012bfad4e5dc47efd5bffb151 --- /dev/null +++ b/apps/blinky/Makefile @@ -0,0 +1,17 @@ +host-build: + west build -b native_sim . -p always -- -DZEPHYR_TOOLCHAIN_VARIANT=host + +host-run: + west build -t run + +esp-build: + west build -b esp32_devkitc/esp32/procpu . -p always + +esp-flash: + west flash + +esp-monitor: + west espressif monitor + +clean: + rm -rf build/ diff --git a/apps/blinky/boards/esp32_devkitc_esp32_procpu.overlay b/apps/blinky/boards/esp32_devkitc_esp32_procpu.overlay new file mode 100644 index 0000000000000000000000000000000000000000..77858e858e05ccdb5fdf33dc859b08128f0e1f18 --- /dev/null +++ b/apps/blinky/boards/esp32_devkitc_esp32_procpu.overlay @@ -0,0 +1,13 @@ +/ { + aliases { + led0 = &led0; + }; + + leds { + compatible = "gpio-leds"; + led0: led_0 { + gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>; + label = "Onboard LED"; + }; + }; +}; diff --git a/apps/blinky/prj.conf b/apps/blinky/prj.conf new file mode 100644 index 0000000000000000000000000000000000000000..b26ffcea97b11761fcee527ecd68e0cddd978a05 --- /dev/null +++ b/apps/blinky/prj.conf @@ -0,0 +1,8 @@ +CONFIG_BT=n +CONFIG_WIFI=n + +CONFIG_CONSOLE=y +CONFIG_PRINTK=y +CONFIG_GPIO=y + +CONFIG_ESP32_USE_UNSUPPORTED_REVISION=y diff --git a/apps/blinky/src/main.c b/apps/blinky/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..661edf9311afa4fc953e144f7e07dda00e450117 --- /dev/null +++ b/apps/blinky/src/main.c @@ -0,0 +1,34 @@ +#include +#include +#include + +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios); + +int main(void) { + int ret; + + printk("Blinky starting (main thread)...\n"); + + if (!gpio_is_ready_dt(&led)) { + printk("Error: LED device %s is not ready\n", led.port->name); + return 0; + } + + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE); + if (ret < 0) { + printk("Error %d: failed to configure LED pin\n", ret); + return 0; + } + + while (1) { + printk("LED ON\n"); + gpio_pin_set_dt(&led, 1); + k_msleep(500); + + printk("LED OFF\n"); + gpio_pin_set_dt(&led, 0); + k_msleep(500); + } + + return 0; +}