Rainmaker Lights Switch

This commit is contained in:
2025-06-28 06:44:14 -04:00
parent 62bb07eb4d
commit 6132a4d429
1342 changed files with 154710 additions and 225 deletions

View File

@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(zephyr_flasher)
zephyr_compile_definitions_ifdef(CONFIG_SERIAL_FLASHER_MD5_ENABLED MD5_ENABLED)
zephyr_library_sources(
../common/example_common.c
)
zephyr_library_include_directories(
../common
../binaries
)
# Needed for example_common
add_compile_definitions(SERIAL_FLASHER_INTERFACE_UART)
# Embed binaries into the app.
include(${CMAKE_CURRENT_LIST_DIR}/../common/bin2array.cmake)
create_resources(${CMAKE_CURRENT_LIST_DIR}/../binaries/Hello-world ${CMAKE_BINARY_DIR}/binaries.c)
set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries.c PROPERTY GENERATED 1)
target_sources(app PRIVATE src/main.c ${CMAKE_BINARY_DIR}/binaries.c)

View File

@@ -0,0 +1,92 @@
# ESP32 Zephyr example
## Overview
This sample code demonstrates how to flash an Espressif SoC (target) from another MCU (host) using
`esp_serial_flasher`. In this case, the ESP32 is used as the host MCU.
Binaries to be flashed from the host MCU to another Espressif SoC can be found in [binaries](../binaries/) folder
and are converted into C-array during build process.
The following steps are performed in order to re-program targets memory:
1. Peripherals are initialized (GPIO for BOOT and EN pins and UART).
2. UART1 (can be changed) through which new binary will be transfered is initialized.
3. The host puts the target device into the boot mode and tries to connect by calling `esp_loader_connect()`.
4. The binary file is opened and its size is acquired, as it has to be known before flashing.
5. Then `esp_loader_flash_start()` is called to enter the flashing mode and erase amount of memory to be flashed.
6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
Note: In addition, to steps mentioned above, `esp_loader_change_transmission_rate()` is called after connection
is established in order to increase the flashing speed. This does not apply for ESP8266, as its bootloader
does not support this command. However, ESP8266 is capable of detecting the baud rate during connection
phase and can be changed before calling `esp_loader_connect()`, if necessary.
## Hardware Required
* Any supported Espressif SoC board for the target
* An ESP32-DevKitC board for the host
* One or two USB cables for power supply and programming.
## Hardware connection
Table below shows connection between the two devices:
| ESP32 (host) | Espressif SoC (target) |
|:------------:|:----------------------:|
| IO26 | IO0 |
| IO25 | RESET |
| IO4 | RX0 |
| IO5 | TX0 |
## Build and flash
To run the example, type the following commands:
```c
west init
west update
west build -p -b <supported board>
west flash
west espressif monitor
```
>**Note:** You can find the supported boards in the boards folder.
(To exit the serial monitor, type ``ctrl-c``.)
For more information, check [Zephyr's Getting Started](https://docs.zephyrproject.org/latest/develop/getting_started/index.html)
## Configuration
For details about available configuration option, please refer to top level [README.md](../../README.md).
Compile definitions can be specified in `prj.conf` file.
Binaries to be flashed are placed in a separate folder (binaries.c) for each possible target and converted to C-array. Without explicitly enabling MD5 check, flash integrity verification is disabled by default.
## Example output
Here is the example's console output:
``` text
Running ESP Flasher from Zephyr
Connected to target
Transmission rate changed.
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
Flash verified
********************************************
*** Logs below are print from slave .... ***
********************************************
Hello world!
```

View File

@@ -0,0 +1,4 @@
# nothing here
CONFIG_CONSOLE=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_NEWLIB_LIBC=y

View File

@@ -0,0 +1,41 @@
import pytest
from pytest_embedded import Dut
from esptool.cmds import detect_chip
FLASH_ADDRESS = 0x1000
BIN_FILE = "/zephyr/zephyr.bin"
# This fixture is used to specify the path to the Zephyr app as it is not in the examples directory.
# It is used by conftest.py to find the app path to build directory.
@pytest.fixture
def app_path() -> str:
return "zephyrproject-rtos/zephyr/"
@pytest.fixture(autouse=True)
def flash_zephyr(app_path: str, build_dir: str, port: str) -> None:
with detect_chip(port) as esp:
esp = esp.run_stub()
path = app_path + build_dir + BIN_FILE
with open(path, "rb") as binary:
binary_data = binary.read()
total_size = len(binary_data)
esp.flash_begin(total_size, FLASH_ADDRESS)
for i in range(0, total_size, esp.FLASH_WRITE_SIZE):
block = binary_data[i : i + esp.FLASH_WRITE_SIZE]
# Pad the last block
block = block + bytes([0xFF]) * (esp.FLASH_WRITE_SIZE - len(block))
esp.flash_block(block, i + FLASH_ADDRESS)
esp.flash_finish()
print("Flashed successfully")
esp.hard_reset()
@pytest.mark.zephyr
def test_zephyr_example(dut: Dut) -> None:
for i in range(3):
dut.expect("Finished programming")
dut.expect("Hello world!")

View File

@@ -0,0 +1,9 @@
sample:
description: ESP Serial Flasher sample code
name: zephyr_flasher
tests:
sample.esp_flasher.zephyr_example:
platform_allow:
- esp32_devkitc_wroom
- esp32_devkitc_wrover
tags: esp32

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
aliases {
en = &en_button;
boot = &boot_button;
uart = &uart1;
};
gpio_keys {
compatible = "gpio-keys";
en_button: en_button {
gpios = <&gpio0 25 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
};
boot_button: boot_button {
gpios = <&gpio0 26 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
};
};
};
&pinctrl {
uart1_example: uart1_example {
group1 {
pinmux = <UART1_TX_GPIO4>;
input-enable;
};
group2 {
pinmux = <UART1_RX_GPIO5>;
output-enable;
};
};
};
&uart1 {
status = "okay";
pinctrl-0 = <&uart1_example>;
pinctrl-names = "default";
};

View File

@@ -0,0 +1,96 @@
/*
* ESP Flasher Library Example for Zephyr
* Written in 2022 by KT-Elektronik, Klaucke und Partner GmbH
* This example code is in the Public Domain (or CC0 licensed, at your option.)
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*
* Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/sys/util.h>
#include <stdio.h>
#include <string.h>
#include <zephyr_port.h>
#include <esp_loader.h>
#include "example_common.h"
#define HIGHER_BAUDRATE 230400
#define DEFAULT_BAUDRATE 115200
/* Get UART DTS entry used as flash interface */
static const struct device *esp_uart_dev = DEVICE_DT_GET(DT_ALIAS(uart));
/* Get GPIO pin connected to the ESP's enable pin. */
static const struct gpio_dt_spec esp_enable_spec = GPIO_DT_SPEC_GET(DT_ALIAS(en), gpios);
/* Get GPIO pin connected to the ESP's boot pin. */
static const struct gpio_dt_spec esp_boot_spec = GPIO_DT_SPEC_GET(DT_ALIAS(boot), gpios);
int main(void)
{
example_binaries_t bin;
const loader_zephyr_config_t config = {
.uart_dev = esp_uart_dev,
.enable_spec = esp_enable_spec,
.boot_spec = esp_boot_spec
};
printk("Running ESP Flasher from Zephyr\r\n");
if (!device_is_ready(esp_uart_dev)) {
printk("ESP UART not ready");
return -ENODEV;
}
if (!device_is_ready(esp_boot_spec.port)) {
printk("ESP boot GPIO not ready");
return -ENODEV;
}
if (!device_is_ready(esp_enable_spec.port)) {
printk("ESP enable GPIO not ready");
return -ENODEV;
}
gpio_pin_configure_dt(&esp_boot_spec, GPIO_OUTPUT_ACTIVE);
gpio_pin_configure_dt(&esp_enable_spec, GPIO_OUTPUT_INACTIVE);
if (loader_port_zephyr_init(&config) != ESP_LOADER_SUCCESS) {
printk("ESP loader init failed");
return -EIO;
}
if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
get_example_binaries(esp_loader_get_target(), &bin);
flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
flash_binary(bin.part.data, bin.part.size, bin.part.addr);
flash_binary(bin.app.data, bin.app.size, bin.app.addr);
}
esp_loader_reset_target();
if (loader_port_change_transmission_rate(DEFAULT_BAUDRATE) == ESP_LOADER_SUCCESS) {
// Delay for skipping the boot message of the targets
k_msleep(500);
printk("********************************************\n");
printk("*** Logs below are print from slave .... ***\n");
printk("********************************************\n");
while (1) {
uint8_t c;
if (uart_poll_in(esp_uart_dev, &c) == 0) {
printk("%c", c);
}
}
}
return 0;
}