mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-11-27 16:02:48 +00:00
Rainmaker Lights Switch
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(FLASHER_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||
set(PORT RASPBERRY_PI)
|
||||
|
||||
project(raspberry_flasher)
|
||||
|
||||
add_compile_definitions(SERIAL_FLASHER_INTERFACE_UART)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../common/bin2array.cmake)
|
||||
create_resources(${CMAKE_CURRENT_LIST_DIR}/../binaries/Hello-world Src/binaries_flash.c)
|
||||
create_resources(${CMAKE_CURRENT_LIST_DIR}/../binaries/RAM_APP Src/binaries_ram.c)
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} ../common/example_common.c Src/main.c Src/binaries_flash.c Src/binaries_ram.c)
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ../common)
|
||||
|
||||
add_subdirectory(${FLASHER_DIR} ${CMAKE_BINARY_DIR}/flasher)
|
||||
|
||||
target_compile_options(flasher
|
||||
PRIVATE
|
||||
-Wunused-parameter
|
||||
-Wshadow
|
||||
)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE flasher)
|
||||
@@ -0,0 +1,76 @@
|
||||
# Raspberry Pi example
|
||||
|
||||
## Overview
|
||||
|
||||
This example demonstrates how to flash an Espressif SoC (target) from a Raspberry Pi 4 (Model B) using `esp_serial_flasher`. AT command firmware to be flashed from a Raspberry Pi to ESP32 can be found in [binaries](../binaries/). USART0 is dedicated for the communication with the Espressif SoC.
|
||||
|
||||
The following steps are performed in order to re-program targets memory:
|
||||
|
||||
1. Peripherals are initialized.
|
||||
2. The host puts slave device into the boot mode and tries to connect by calling `esp_loader_connect()`.
|
||||
3. Then `esp_loader_flash_start()` is called to enter the flashing mode and erase amount of the memory to be flashed.
|
||||
4. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
|
||||
5. At the end, `loader_port_reset_target()` is called to restart the target and execute the updated firmware.
|
||||
|
||||
Note: In addition to the steps mentioned above, `esp_loader_change_transmission_rate()` is called after connection is established in order to increase the flashing speed. Bootloader is also capable of detecting baud rate during connection phase and can be changed before calling `esp_loader_connect()`. However, it is recommended to start at lower speed and then use dedicated command to increase baud rate. This does not apply for ESP8266, as its bootloader does not support this command, therefore, baud rate can only be changed before connection phase in this case.
|
||||
|
||||
## Hardware Required
|
||||
|
||||
* Raspberry Pi 4 Model B.
|
||||
* A development board with the ESP32 SoC (e.g. ESP-WROVER-KIT, ESP32-DevKitC, etc.).
|
||||
* USB cable in case ESP32 board is powered from USB. ESP32 can be powered by Raspberry Pi as well.
|
||||
|
||||
## Hardware connection
|
||||
|
||||
Table below shows connection between Raspberry Pi and ESP32.
|
||||
|
||||
| Raspberry Pi (host) | ESP32 (target) |
|
||||
|:-------------------:|:-------------------:|
|
||||
| GPIO3 | IO0 |
|
||||
| GPIO2 | RST |
|
||||
| GPIO14 | RX0 |
|
||||
| GPIO15 | TX0 |
|
||||
| GND | GND |
|
||||
|
||||
Optionally, UART-to-USB bridge can be connected to PD5(RX) and PD6(TX) for debug purposes.
|
||||
|
||||
## Installation
|
||||
|
||||
### GPIO library
|
||||
Raspberry Pi makes use of [pigpio](http://abyz.me.uk/rpi/pigpio/) library in order to simplify controlling GPIO pins. Some distributions of 'Raspberry Pi OS' may come with `pigpio` already installed. Presence of the library in the system can checked by running command:
|
||||
```
|
||||
pigpiod -v
|
||||
```
|
||||
|
||||
If not present, run following commands to install the library.
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install pigpio
|
||||
```
|
||||
|
||||
### Enable UART
|
||||
On Raspberry Pi 4, primary UART (UART0) is connected to the On-board Bluetooth module by default.
|
||||
In order to enable serial communication on this UART, run following command in terminal:
|
||||
```
|
||||
sudo raspi-config
|
||||
```
|
||||
|
||||
* Navigate to **Interfacing Options -> Serial**.
|
||||
* Then it will ask for login shell to be accessible over Serial, select **No**.
|
||||
* After that, it will ask for enabling Hardware Serial port, select **Yes**.
|
||||
* Reboot the Raspberry Pi.
|
||||
|
||||
## Build and run
|
||||
|
||||
To compile the example:
|
||||
|
||||
Create and navigate to `build` directory:
|
||||
```
|
||||
mkdir build && cd build
|
||||
```
|
||||
Run cmake, build example and run example:
|
||||
```
|
||||
cmake .. && cmake --build . && ./raspberry_flasher
|
||||
```
|
||||
|
||||
For more details regarding to esp_serial_flasher configuration, please refer to top level [README.md](../../README.md).
|
||||
@@ -0,0 +1,81 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pigpio.h>
|
||||
#include <sys/param.h>
|
||||
#include "raspberry_port.h"
|
||||
#include "esp_loader.h"
|
||||
#include "example_common.h"
|
||||
|
||||
#define TARGET_RST_Pin 2
|
||||
#define TARGET_IO0_Pin 3
|
||||
|
||||
#define DEFAULT_BAUD_RATE 115200
|
||||
#define HIGHER_BAUD_RATE 460800
|
||||
#define SERIAL_DEVICE "/dev/ttyS0"
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
example_binaries_t bin;
|
||||
|
||||
const loader_raspberry_config_t config = {
|
||||
.device = SERIAL_DEVICE,
|
||||
.baudrate = DEFAULT_BAUD_RATE,
|
||||
.reset_trigger_pin = TARGET_RST_Pin,
|
||||
.gpio0_trigger_pin = TARGET_IO0_Pin,
|
||||
};
|
||||
|
||||
loader_port_raspberry_init(&config);
|
||||
|
||||
if (connect_to_target(HIGHER_BAUD_RATE) == ESP_LOADER_SUCCESS) {
|
||||
|
||||
get_example_binaries(esp_loader_get_target(), &bin);
|
||||
|
||||
printf("Loading bootloader...\n");
|
||||
flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);
|
||||
printf("Loading partition table...\n");
|
||||
flash_binary(bin.part.data, bin.part.size, bin.part.addr);
|
||||
printf("Loading app...\n");
|
||||
flash_binary(bin.app.data, bin.app.size, bin.app.addr);
|
||||
printf("Done!\n");
|
||||
esp_loader_reset_target();
|
||||
loader_port_deinit();
|
||||
|
||||
|
||||
if (gpioInitialise() < 0) {
|
||||
fprintf(stderr, "pigpio initialization failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int serial = serOpen(SERIAL_DEVICE, DEFAULT_BAUD_RATE, 0);
|
||||
if (serial < 0) {
|
||||
printf("Serial port could not be opened!\n");
|
||||
}
|
||||
|
||||
printf("********************************************\n");
|
||||
printf("*** Logs below are print from slave .... ***\n");
|
||||
printf("********************************************\n");
|
||||
|
||||
// Delay for skipping the boot message of the targets
|
||||
gpioDelay(500000);
|
||||
while (1) {
|
||||
int byte = serReadByte(serial);
|
||||
if (byte != PI_SER_READ_NO_DATA) {
|
||||
printf("%c", byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import pytest
|
||||
import pexpect
|
||||
|
||||
|
||||
@pytest.mark.raspberry
|
||||
def test_raspberry_example():
|
||||
with pexpect.spawn(
|
||||
"./examples/raspberry_example/build/raspberry_flasher",
|
||||
timeout=10,
|
||||
encoding="utf-8",
|
||||
) as p:
|
||||
p.expect("Hello world!")
|
||||
Reference in New Issue
Block a user