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,18 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS ../../)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp-serial-flasher)
# There are issues with ESP-IDF 4.4 and -Wunused-parameter
if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.4")
idf_component_get_property(flasher esp-serial-flasher COMPONENT_LIB)
target_compile_options(${flasher}
PRIVATE
-Wunused-parameter
-Wshadow
)
endif()

View File

@@ -0,0 +1,92 @@
# Flash multiple partitions example
## Overview
This example demonstrates how to flash an Espressif SoC (target) from another MCU (host) using `esp_serial_flasher`. Two ESP32 chips are used in this case. Binaries to be flashed from the host MCU to the 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. UART1 through which the the new binary will be transferred is initialized.
2. The host puts the target device into the boot mode and tries to connect by calling `esp_loader_connect()`.
3. The binary file is opened and its size is acquired, as it has to be known before flashing.
4. Then `esp_loader_flash_start()` is called to enter the flashing mode and erase the amount of memory to be flashed.
5. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
Note: In addition to the steps mentioned above, `esp_loader_change_transmission_rate()` is called after the connection is established in order to increase the flashing speed. This does not apply for the ESP8266, as its bootloader does not support this command. However, the ESP8266 is capable of detecting the baud rate during connection phase and can be changed before calling `esp_loader_connect()`, if necessary.
## Connection configuration
In the majority of cases `ESP_LOADER_CONNECT_DEFAULT` helper macro is used in order to initialize `loader_connect_args_t` data structure passed to `esp_loader_connect()`. Helper macro sets the maximum time to wait for a response and the number of retrials. For more detailed information refer to [serial protocol](https://docs.espressif.com/projects/esptool/en/latest/esp32s3/advanced-topics/serial-protocol.html).
## Hardware Required
* Two development boards with the ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.).
* One or two USB cables for power supply and programming.
* Cables to connect host to target according to table below.
## Hardware connection
Table below shows connection between the two ESP32 devices.
| ESP32 (host) | ESP32 (target) |
|:------------:|:-------------:|
| IO26 | IO0 |
| IO25 | RESET |
| IO4 | RX0 |
| IO5 | TX0 |
Note: interconnection is the same for ESP32, ESP32-S2 and ESP8266 targets.
## Build and flash
To run the example, type the following command:
```CMake
idf.py -p PORT flash monitor
```
(To exit the serial monitor, type ``Ctrl-]``.)
See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/index.html) for full steps to configure and use ESP-IDF to build projects.
## Configuration
For details about available configuration options, please refer to the top level [README.md](../../README.md).
Compile definitions can be specified in the command line when running `idf.py`, for example:
```
idf.py build -DMD5_ENABLED=1
```
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:
```
...
Connected to target
Transmission rate changed changed
I (2484) serial_flasher: Loading bootloader...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
I (4074) serial_flasher: Loading partition table...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
I (4284) serial_flasher: Loading app...
Erasing flash (this may take a while)...
Start programming
Progress: 100 %
Finished programming
I (11934) serial_flasher: Done!
I (11273) serial_flasher: ********************************************
I (11273) serial_flasher: *** Logs below are print from slave .... ***
I (11273) serial_flasher: ********************************************
Hello world!
```

View File

@@ -0,0 +1,14 @@
set(srcs main.c ../../common/example_common.c)
set(include_dirs . ../../common)
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include_dirs})
set(target ${COMPONENT_LIB})
# Embed binaries into the app.
# In ESP-IDF this can also be done using EMBED_FILES option of idf_component_register.
# Here an external tool is used to make file embedding similar with other ports.
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(${target} PRIVATE ${CMAKE_BINARY_DIR}/binaries.c)

View File

@@ -0,0 +1,84 @@
/* Flash multiple partitions example
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.
*/
#include <sys/param.h>
#include <string.h>
#include "esp_err.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp32_port.h"
#include "esp_loader.h"
#include "example_common.h"
static const char *TAG = "serial_flasher";
#define HIGHER_BAUDRATE 230400
// Max line size
#define BUF_LEN 128
static uint8_t buf[BUF_LEN] = {0};
void slave_monitor(void *arg)
{
#if (HIGHER_BAUDRATE != 115200)
uart_flush_input(UART_NUM_1);
uart_flush(UART_NUM_1);
uart_set_baudrate(UART_NUM_1, 115200);
#endif
while (1) {
int rxBytes = uart_read_bytes(UART_NUM_1, buf, BUF_LEN, 100 / portTICK_PERIOD_MS);
buf[rxBytes] = '\0';
printf("%s", buf);
}
}
void app_main(void)
{
example_binaries_t bin;
const loader_esp32_config_t config = {
.baud_rate = 115200,
.uart_port = UART_NUM_1,
.uart_rx_pin = GPIO_NUM_5,
.uart_tx_pin = GPIO_NUM_4,
.reset_trigger_pin = GPIO_NUM_25,
.gpio0_trigger_pin = GPIO_NUM_26,
};
if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) {
ESP_LOGE(TAG, "serial initialization failed.");
return;
}
if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) {
get_example_binaries(esp_loader_get_target(), &bin);
ESP_LOGI(TAG, "Loading bootloader...");
flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
ESP_LOGI(TAG, "Loading partition table...");
flash_binary(bin.part.data, bin.part.size, bin.part.addr);
ESP_LOGI(TAG, "Loading app...");
flash_binary(bin.app.data, bin.app.size, bin.app.addr);
ESP_LOGI(TAG, "Done!");
esp_loader_reset_target();
// Delay for skipping the boot message of the targets
vTaskDelay(500 / portTICK_PERIOD_MS);
// Forward slave's serial output
ESP_LOGI(TAG, "********************************************");
ESP_LOGI(TAG, "*** Logs below are print from slave .... ***");
ESP_LOGI(TAG, "********************************************");
xTaskCreate(slave_monitor, "slave_monitor", 2048, NULL, configMAX_PRIORITIES - 1, NULL);
}
vTaskDelete(NULL);
}

View File

@@ -0,0 +1,4 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, , 0x6000,
phy_init, data, phy, , 0x1000,
factory, app, factory, , 1920K,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x6000
3 phy_init data phy 0x1000
4 factory app factory 1920K

View File

@@ -0,0 +1,9 @@
import pytest
from pytest_embedded import Dut
@pytest.mark.esp32
def test_esp32_example(dut: Dut) -> None:
for i in range(3):
dut.expect("Finished programming")
dut.expect("Hello world!")

View File

@@ -0,0 +1,2 @@
CONFIG_IDF_TARGET="esp32"
CONFIG_PARTITION_TABLE_CUSTOM=y

View File

@@ -0,0 +1,3 @@
CONFIG_IDF_TARGET="esp32"
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_SERIAL_FLASHER_MD5_ENABLED=n