Skip to content

Commit 509478f

Browse files
committed
espflasher version by Willy-JL
with small changes - Extra checks added for otg power - Included firmware binaries are packed into fap, will be unpacked on first launch, second launch will be fast
1 parent 822dfe6 commit 509478f

File tree

165 files changed

+31858
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+31858
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
App(
22
appid="esp_flasher",
33
name="ESP Flasher",
4-
fap_version=(1,4),
4+
fap_version=(1, 4),
55
apptype=FlipperAppType.EXTERNAL,
66
entry_point="esp_flasher_app",
77
requires=["gui"],
88
stack_size=4 * 1024,
99
order=90,
10+
fap_file_assets="packedfws",
1011
fap_icon="wifi_10px.png",
1112
fap_category="GPIO",
1213
fap_private_libs=[
13-
Lib(
14-
name="esp-serial-flasher",
15-
fap_include_paths=["include"],
16-
sources=[
17-
"src/esp_loader.c",
18-
"src/esp_targets.c",
19-
"src/md5_hash.c",
20-
"src/protocol_common.c",
21-
"src/protocol_uart.c",
22-
"src/slip.c"
23-
],
24-
cincludes=["lib/esp-serial-flasher/private_include"],
25-
cdefines=["SERIAL_FLASHER_INTERFACE_UART=1", "MD5_ENABLED=1", "SERIAL_FLASHER_WRITE_BLOCK_RETRIES=10"],
26-
),
27-
],
14+
Lib(
15+
name="esp-serial-flasher",
16+
fap_include_paths=["include"],
17+
sources=[
18+
"src/esp_loader.c",
19+
"src/esp_targets.c",
20+
"src/md5_hash.c",
21+
"src/protocol_common.c",
22+
"src/protocol_uart.c",
23+
"src/slip.c",
24+
],
25+
cincludes=["lib/esp-serial-flasher/private_include"],
26+
cdefines=[
27+
"SERIAL_FLASHER_INTERFACE_UART=1",
28+
"MD5_ENABLED=1",
29+
"SERIAL_FLASHER_WRITE_BLOCK_RETRIES=10",
30+
],
31+
),
32+
],
2833
cdefines=["SERIAL_FLASHER_INTERFACE_UART=1"],
2934
fap_icon_assets="assets",
3035
)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

non_catalog_apps/flipperzero-esp-flasher/esp_flasher_app.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ EspFlasherApp* esp_flasher_app_alloc() {
6868

6969
app->reset = false;
7070
app->boot = false;
71+
app->quickflash = false;
7172

7273
app->turbospeed = false;
7374

@@ -118,6 +119,7 @@ int32_t esp_flasher_app(void* p) {
118119
UNUSED(p);
119120

120121
uint8_t attempts = 0;
122+
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
121123
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
122124
furi_hal_power_enable_otg();
123125
furi_delay_ms(10);
@@ -134,7 +136,7 @@ int32_t esp_flasher_app(void* p) {
134136

135137
esp_flasher_app_free(esp_flasher_app);
136138

137-
if(furi_hal_power_is_otg_enabled()) {
139+
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
138140
furi_hal_power_disable_otg();
139141
}
140142

non_catalog_apps/flipperzero-esp-flasher/esp_flasher_app_i.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <dialogs/dialogs.h>
2323
#include <notification/notification_messages.h>
2424

25+
#include <assets_icons.h>
26+
2527
#define ESP_FLASHER_TEXT_BOX_STORE_SIZE (4096)
2628

2729
#define ESP_APP_FOLDER_USER "apps_data/esp_flasher"
@@ -66,6 +68,7 @@ struct EspFlasherApp {
6668

6769
bool reset;
6870
bool boot;
71+
bool quickflash;
6972

7073
SwitchFirmware switch_fw;
7174

non_catalog_apps/flipperzero-esp-flasher/esp_flasher_uart.c

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#include "esp_flasher_app_i.h"
22
#include "esp_flasher_uart.h"
33

4-
#define UART_CH (FuriHalUartIdUSART1)
5-
#define BAUDRATE (115200)
6-
74
struct EspFlasherUart {
85
EspFlasherApp* app;
9-
FuriHalUartId channel;
106
FuriThread* rx_thread;
117
FuriStreamBuffer* rx_stream;
128
uint8_t rx_buf[RX_BUF_SIZE + 1];
139
void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context);
10+
FuriHalSerialHandle* serial_handle;
1411
};
1512

1613
typedef enum {
@@ -27,10 +24,14 @@ void esp_flasher_uart_set_handle_rx_data_cb(
2724

2825
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
2926

30-
void esp_flasher_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
27+
void esp_flasher_uart_on_irq_cb(
28+
FuriHalSerialHandle* handle,
29+
FuriHalSerialRxEvent event,
30+
void* context) {
3131
EspFlasherUart* uart = (EspFlasherUart*)context;
3232

33-
if(ev == UartIrqEventRXNE) {
33+
if(event == FuriHalSerialRxEventData) {
34+
uint8_t data = furi_hal_serial_async_rx(handle);
3435
furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
3536
furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
3637
}
@@ -57,30 +58,30 @@ static int32_t uart_worker(void* context) {
5758
return 0;
5859
}
5960

60-
void esp_flasher_uart_tx(uint8_t* data, size_t len) {
61-
furi_hal_uart_tx(UART_CH, data, len);
61+
void esp_flasher_uart_tx(EspFlasherUart* uart, uint8_t* data, size_t len) {
62+
furi_hal_serial_tx(uart->serial_handle, data, len);
63+
}
64+
65+
void esp_flasher_uart_set_br(EspFlasherUart* uart, uint32_t baud) {
66+
furi_hal_serial_set_br(uart->serial_handle, baud);
6267
}
6368

6469
EspFlasherUart*
65-
esp_flasher_uart_init(EspFlasherApp* app, FuriHalUartId channel, const char* thread_name) {
70+
esp_flasher_uart_init(EspFlasherApp* app, FuriHalSerialId channel, const char* thread_name) {
6671
EspFlasherUart* uart = malloc(sizeof(EspFlasherUart));
6772

6873
uart->app = app;
69-
uart->channel = channel;
7074
uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
7175
uart->rx_thread = furi_thread_alloc();
7276
furi_thread_set_name(uart->rx_thread, thread_name);
7377
furi_thread_set_stack_size(uart->rx_thread, 1024);
7478
furi_thread_set_context(uart->rx_thread, uart);
7579
furi_thread_set_callback(uart->rx_thread, uart_worker);
7680
furi_thread_start(uart->rx_thread);
77-
if(channel == FuriHalUartIdUSART1) {
78-
furi_hal_console_disable();
79-
} else if(channel == FuriHalUartIdLPUART1) {
80-
furi_hal_uart_init(channel, BAUDRATE);
81-
}
82-
furi_hal_uart_set_br(channel, BAUDRATE);
83-
furi_hal_uart_set_irq_cb(channel, esp_flasher_uart_on_irq_cb, uart);
81+
uart->serial_handle = furi_hal_serial_control_acquire(channel);
82+
furi_check(uart->serial_handle);
83+
furi_hal_serial_init(uart->serial_handle, BAUDRATE);
84+
furi_hal_serial_async_rx_start(uart->serial_handle, esp_flasher_uart_on_irq_cb, uart, false);
8485

8586
return uart;
8687
}
@@ -96,11 +97,8 @@ void esp_flasher_uart_free(EspFlasherUart* uart) {
9697
furi_thread_join(uart->rx_thread);
9798
furi_thread_free(uart->rx_thread);
9899

99-
furi_hal_uart_set_irq_cb(uart->channel, NULL, NULL);
100-
if(uart->channel == FuriHalUartIdLPUART1) {
101-
furi_hal_uart_deinit(uart->channel);
102-
}
103-
furi_hal_console_enable();
100+
furi_hal_serial_deinit(uart->serial_handle);
101+
furi_hal_serial_control_release(uart->serial_handle);
104102

105103
free(uart);
106104
}

non_catalog_apps/flipperzero-esp-flasher/esp_flasher_uart.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
#include "furi_hal.h"
44

5+
#define UART_CH (FuriHalSerialIdUsart)
6+
#define BAUDRATE (115200)
7+
#define FAST_BAUDRATE (921600)
8+
59
#define RX_BUF_SIZE (2048)
610

711
typedef struct EspFlasherUart EspFlasherUart;
812

913
void esp_flasher_uart_set_handle_rx_data_cb(
1014
EspFlasherUart* uart,
1115
void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
12-
void esp_flasher_uart_tx(uint8_t* data, size_t len);
16+
void esp_flasher_uart_tx(EspFlasherUart* uart, uint8_t* data, size_t len);
17+
void esp_flasher_uart_set_br(EspFlasherUart* uart, uint32_t baud);
1318
EspFlasherUart* esp_flasher_usart_init(EspFlasherApp* app);
1419
void esp_flasher_uart_free(EspFlasherUart* uart);

non_catalog_apps/flipperzero-esp-flasher/esp_flasher_worker.c

+35-11
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,33 @@ static int32_t esp_flasher_flash_bin(void* context) {
230230
// higher BR
231231
if(!err && app->turbospeed) {
232232
loader_port_debug_print("Increasing speed for faster flash\n");
233-
err = esp_loader_change_transmission_rate(921600);
234-
if (err != ESP_LOADER_SUCCESS) {
233+
err = esp_loader_change_transmission_rate(FAST_BAUDRATE);
234+
if(err != ESP_LOADER_SUCCESS) {
235235
char err_msg[256];
236236
snprintf(
237-
err_msg,
238-
sizeof(err_msg),
239-
"Cannot change transmission rate. Error: %u\n",
240-
err);
237+
err_msg, sizeof(err_msg), "Cannot change transmission rate. Error: %u\n", err);
241238
loader_port_debug_print(err_msg);
242239
}
243-
furi_hal_uart_set_br(FuriHalUartIdUSART1, 921600);
240+
esp_flasher_uart_set_br(app->uart, FAST_BAUDRATE);
244241
}
245242

246243
if(!err) {
247244
loader_port_debug_print("Connected\n");
245+
uint32_t start_time = furi_get_tick();
246+
248247
if(!_switch_fw(app)) {
249248
_flash_all_files(app);
250249
}
251250
app->switch_fw = SwitchNotSet;
252251

253-
if (app->turbospeed) {
252+
FuriString* flash_time =
253+
furi_string_alloc_printf("Flash took: %lds\n", (furi_get_tick() - start_time) / 1000);
254+
loader_port_debug_print(furi_string_get_cstr(flash_time));
255+
furi_string_free(flash_time);
256+
257+
if(app->turbospeed) {
254258
loader_port_debug_print("Restoring transmission rate\n");
255-
furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
259+
esp_flasher_uart_set_br(app->uart, BAUDRATE);
256260
}
257261

258262
loader_port_debug_print(
@@ -272,6 +276,7 @@ static int32_t esp_flasher_flash_bin(void* context) {
272276

273277
// done
274278
app->flash_worker_busy = false;
279+
app->quickflash = false;
275280

276281
// cleanup
277282
furi_stream_buffer_free(flash_rx_stream);
@@ -306,6 +311,9 @@ static int32_t esp_flasher_reset(void* context) {
306311
_setRTS(false);
307312
_initRTS();
308313

314+
furi_hal_gpio_init_simple(&gpio_swclk, GpioModeOutputPushPull);
315+
furi_hal_gpio_write(&gpio_swclk, true);
316+
309317
if(app->reset) {
310318
loader_port_debug_print("Resetting board\n");
311319
loader_port_reset_target();
@@ -319,6 +327,10 @@ static int32_t esp_flasher_reset(void* context) {
319327
app->reset = false;
320328
app->boot = false;
321329

330+
if(app->quickflash) {
331+
esp_flasher_flash_bin(app);
332+
}
333+
322334
return 0;
323335
}
324336

@@ -353,7 +365,7 @@ esp_loader_error_t loader_port_read(uint8_t* data, uint16_t size, uint32_t timeo
353365

354366
esp_loader_error_t loader_port_write(const uint8_t* data, uint16_t size, uint32_t timeout) {
355367
UNUSED(timeout);
356-
esp_flasher_uart_tx((uint8_t*)data, size);
368+
if(global_app) esp_flasher_uart_tx(global_app->uart, (uint8_t*)data, size);
357369
return ESP_LOADER_SUCCESS;
358370
}
359371

@@ -364,6 +376,18 @@ void loader_port_reset_target(void) {
364376
}
365377

366378
void loader_port_enter_bootloader(void) {
379+
// Also support for the Multi-fucc and Xeon boards
380+
furi_hal_gpio_write(&gpio_swclk, false);
381+
if(furi_hal_power_is_otg_enabled()) {
382+
furi_hal_power_disable_otg();
383+
}
384+
loader_port_delay_ms(100);
385+
if(!furi_hal_power_is_otg_enabled()) {
386+
furi_hal_power_enable_otg();
387+
}
388+
furi_hal_gpio_init_simple(&gpio_swclk, GpioModeAnalog);
389+
loader_port_delay_ms(100);
390+
367391
// adapted from custom usb-jtag-serial reset in esptool
368392
// (works on official wifi dev board)
369393
_setDTR(true);
@@ -409,4 +433,4 @@ void esp_flasher_worker_handle_rx_data_cb(uint8_t* buf, size_t len, void* contex
409433
// done flashing
410434
if(global_app) esp_flasher_console_output_handle_rx_data_cb(buf, len, global_app);
411435
}
412-
}
436+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Bug report
2+
description: Report a problem with esp-serial-flasher operation
3+
labels: ['Type: Bug']
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
* Please ensure you are using the latest version of `esp-serial-flasher`.
9+
* Try using one of the examples from the `examples` directory and following the example documentation.
10+
* If your board is a custom design, consider using our [free-of-charge schematic and PCB review service](https://www.espressif.com/en/contact-us/circuit-schematic-pcb-design-review).
11+
* If still experiencing issues, please provide as many details as possible below about your hardware and software setup.
12+
- type: input
13+
id: port
14+
attributes:
15+
label: Port
16+
description: Which port are you experiencing the issue with?
17+
placeholder: ex. ESP, STM32
18+
validations:
19+
required: true
20+
- type: input
21+
id: target
22+
attributes:
23+
label: Target chip
24+
description: Which chip are you trying to flash?
25+
placeholder: ex. ESP8266, ESP32, ESP32-C3
26+
validations:
27+
required: true
28+
- type: textarea
29+
id: other-hw
30+
attributes:
31+
label: Hardware Configuration
32+
description: What dev boards/custom PCB are you using, how are the chips connected, which baudrate are you trying to flash with?
33+
validations:
34+
required: true
35+
id: output
36+
- type: textarea
37+
attributes:
38+
label: Log output
39+
description: Enable tracing with SERIAL_FLASHER_DEBUG_TRACE and provide the full log.
40+
render: plain
41+
validations:
42+
required: true
43+
- type: textarea
44+
id: more-info
45+
attributes:
46+
label: More Information
47+
description: Provide any additional information relevant to the issue.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Feature request
2+
description: Suggest an idea for this project
3+
labels: ['Type: Feature Request']
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
* We welcome any ideas or feature requests! It's helpful if you can explain exactly why the feature would be useful.
9+
* Please check if the feature has already been suggested in [existing issues](https://github.com/espressif/esp-serial-flasher/issues) or [pull requests](https://github.com/espressif/esp-serial-flasher/pulls).
10+
* Please provide enough context so that the reasoning behind the suggestion can be understood.
11+
- type: textarea
12+
id: problem-related
13+
attributes:
14+
label: Is your feature request related to a problem?
15+
description: Please provide a clear and concise description of what the problem is.
16+
validations:
17+
required: true
18+
- type: textarea
19+
id: solution
20+
attributes:
21+
label: Describe the solution you'd like
22+
description: Please provide a clear and concise description of a solution of the described problem or usecase.
23+
validations:
24+
required: true
25+
- type: textarea
26+
id: alternatives
27+
attributes:
28+
label: Describe alternatives you've considered
29+
description: Please provide a clear and concise description of any alternative solutions or features you've considered.
30+
- type: textarea
31+
id: context
32+
attributes:
33+
label: Additional context
34+
description: Please add any other context here.

0 commit comments

Comments
 (0)