Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop support (Linux / Windows / Mac) (ESF-122) #102

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# esp-serial-flasher

`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other host microcontrollers.
`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other host that are supported through their dedicated port drivers.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's better to be upfront here. I would preffer something like:

`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other microcontrollers, SBCs and even desktop PCs.

These can be found in the `port` folder.

## Using the library

`esp-serial-flasher` supports a variety of host/target/interface combinations:

Supported **host** microcontrollers:
Expand Down
18 changes: 17 additions & 1 deletion examples/common/example_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#if !defined(WIN32)
#include <sys/param.h>
#endif
#include "esp_loader_io.h"
#include "esp_loader.h"
#include "example_common.h"

#ifndef MAX
#define MAX(a, b) ((a) > (b)) ? (a) : (b)
#endif

#ifndef MIN
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#endif

#ifndef SINGLE_TARGET_SUPPORT


Expand All @@ -31,6 +41,7 @@
#define BOOTLOADER_ADDRESS_V1 0x0
#define PARTITION_ADDRESS 0x8000
#define APPLICATION_ADDRESS 0x10000
#define MAX_BIN_HEADER_SEGMENTS 16

extern const uint8_t ESP32_bootloader_bin[];
extern const uint32_t ESP32_bootloader_bin_size;
Expand Down Expand Up @@ -336,7 +347,12 @@ esp_loader_error_t load_ram_binary(const uint8_t *bin)
printf("Start loading\n");
esp_loader_error_t err;
const esp_loader_bin_header_t *header = (const esp_loader_bin_header_t *)bin;
esp_loader_bin_segment_t segments[header->segments];
if(header->segments > MAX_BIN_HEADER_SEGMENTS) {
printf("Too many segments in binary header\n");
return ESP_LOADER_ERROR_INVALID_PARAM;
}

esp_loader_bin_segment_t segments[MAX_BIN_HEADER_SEGMENTS];

// Parse segments
uint32_t seg;
Expand Down
59 changes: 59 additions & 0 deletions examples/desktop_esp32_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

cmake_minimum_required(VERSION 3.5)
project(esp-serial-flasher)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../submodules)
find_package(WjwwoodSerial REQUIRED)

set(ESPSERIAL_PATH ${CMAKE_CURRENT_LIST_DIR}/../../)

# LIB esp_serial

include(${ESPSERIAL_PATH}examples/common/bin2array.cmake)
create_resources(${ESPSERIAL_PATH}examples/binaries/Hello-world ${CMAKE_BINARY_DIR}/binaries_1.c)
set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries_1.c PROPERTY GENERATED 1)
create_resources(${ESPSERIAL_PATH}examples/binaries/RAM_APP ${CMAKE_BINARY_DIR}/binaries_2.c)
set_property(SOURCE ${CMAKE_BINARY_DIR}/binaries_2.c PROPERTY GENERATED 1)


add_library(esp_serial
${ESPSERIAL_PATH}port/wjwwood_serial_port.cpp
${ESPSERIAL_PATH}src/esp_loader.c
${ESPSERIAL_PATH}src/esp_targets.c
${ESPSERIAL_PATH}src/md5_hash.c
${ESPSERIAL_PATH}src/slip.c
${ESPSERIAL_PATH}src/protocol_uart.c
${ESPSERIAL_PATH}src/protocol_common.c
${CMAKE_BINARY_DIR}/binaries_1.c
${CMAKE_BINARY_DIR}/binaries_2.c
${ESPSERIAL_PATH}examples/common/example_common.c
)

target_include_directories(esp_serial PUBLIC
${ESPSERIAL_PATH}include
${ESPSERIAL_PATH}port
${ESPSERIAL_PATH}examples/common
)

target_include_directories(esp_serial PRIVATE
${ESPSERIAL_PATH}private_include
)

target_compile_definitions(esp_serial PUBLIC
-DSERIAL_FLASHER_INTERFACE_USB
-DMD5_ENABLED
-DSERIAL_FLASHER_WRITE_BLOCK_RETRIES=4
-DSERIAL_FLASHER_DEBUG_TRACE
)

target_link_libraries(esp_serial PUBLIC wjwwood_serial)

# EXECUTABLE desktop_esp32_example

add_executable(desktop_esp32_example
main/main.cpp
)

target_link_libraries(desktop_esp32_example PRIVATE
esp_serial
)
65 changes: 65 additions & 0 deletions examples/desktop_esp32_example/main/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* 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 <string.h>

#include "wjwwood_serial_port.h"
#include "esp_loader.h"
#include "esp_loader_io.h"
extern "C" {
#include "example_common.h"

}

#include "serial/serial.h"

#define HIGHER_BAUDRATE 230400

int main(int argv, char **argc)
{
if(argv < 2) {
printf("Usage: %s <port>\n", argc[0]);
return 1;
}

example_binaries_t bin;

loader_wjwwood_serial_config_t config;
config.portName = argc[1];
//config.portName = "COM4";
config.baudrate = 115200;
config.timeout = 600;

if (loader_port_wjwwood_serial_init((const loader_wjwwood_serial_config_t*)&config) != ESP_LOADER_SUCCESS) {
printf("Serial initialization failed.\n");
return -1;
}

printf("Connecting...\n");
if (connect_to_target(HIGHER_BAUDRATE) == 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");
loader_port_wjwwood_serial_deinit();
} else {
printf("Connect failed\n");
loader_port_wjwwood_serial_deinit();
return -1;
}

return 0;
}
Loading