From 501c1b5752105ce05c89cfa5ff4c0309cc82b3d3 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Thu, 2 Jun 2022 01:58:10 +0200 Subject: [PATCH 1/3] Add RP2040 firmware with version set to 2 --- main/rp2040_updater.c | 84 +++++++++++----------------------- resources/rp2040_firmware.bin | Bin 36076 -> 36076 bytes 2 files changed, 26 insertions(+), 58 deletions(-) diff --git a/main/rp2040_updater.c b/main/rp2040_updater.c index 49821b0..78cc013 100644 --- a/main/rp2040_updater.c +++ b/main/rp2040_updater.c @@ -20,6 +20,17 @@ extern const uint8_t rp2040_firmware_bin_start[] asm("_binary_rp2040_firmware_bin_start"); extern const uint8_t rp2040_firmware_bin_end[] asm("_binary_rp2040_firmware_bin_end"); +void display_rp2040_update_state(pax_buf_t* pax_buffer, ILI9341* ili9341, const char* text) { + pax_noclip(pax_buffer); + const pax_font_t* font = pax_get_font("sky mono"); + pax_background(pax_buffer, 0xFFFFFF); + pax_vec1_t title_size = pax_text_size(font, 18, "Co-processor update"); + pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (title_size.x / 2), 120 - 30, "Co-processor update"); + pax_vec1_t size = pax_text_size(font, 18, text); + pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (size.x / 2), 120 + 10, text); + ili9341_write(ili9341, pax_buffer->buf); +} + void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { size_t firmware_size = rp2040_firmware_bin_end - rp2040_firmware_bin_start; char message[64]; @@ -35,33 +46,15 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { ili9341_write(ili9341, pax_buffer->buf); restart(); } - - /*pax_noclip(pax_buffer); - pax_background(pax_buffer, 0xCCCCCC); - memset(message, 0, sizeof(message)); - snprintf(message, sizeof(message) - 1, "RP2040 firmware: 0x%02X", fw_version); - pax_draw_text(pax_buffer, 0xFF000000, NULL, 18, 0, 20*0, message); - ili9341_write(ili9341, pax_buffer->buf); - vTaskDelay(100 / portTICK_PERIOD_MS);*/ - - if (fw_version < 0x01) { // Update required - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040..."); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - snprintf(message, sizeof(message) - 1, "Starting bootloader"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 13, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); + + if (fw_version < 0x02) { // Update required + display_rp2040_update_state(pax_buffer, ili9341, "Starting bootloader..."); rp2040_reboot_to_bootloader(rp2040); esp_restart(); } if (fw_version == 0xFF) { // RP2040 is in bootloader mode - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040..."); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Starting update..."); uint8_t bl_version; if (rp2040_get_bootloader_version(rp2040, &bl_version) != ESP_OK) { @@ -86,13 +79,7 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { rp2040_bl_install_uart(); - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040..."); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - snprintf(message, sizeof(message) - 1, "Waiting for bootloader"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 13, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Preparing..."); while (true) { vTaskDelay(1 / portTICK_PERIOD_MS); @@ -122,13 +109,7 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { } } - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040..."); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - snprintf(message, sizeof(message) - 1, "Waiting for bootloader sync"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 13, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Synchronizing..."); char rx_buffer[16]; uint8_t rx_buffer_pos = 0; @@ -153,13 +134,7 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { restart(); } - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040..."); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - snprintf(message, sizeof(message) - 1, "Erasing flash"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 13, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Erasing..."); uint32_t erase_length = firmware_size; erase_length = erase_length + erase_size - (erase_length % erase_size); // Round up to erase size @@ -201,11 +176,8 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { pax_noclip(pax_buffer); pax_background(pax_buffer, 0x325aa8); - snprintf(message, sizeof(message) - 1, "Updating RP2040... %u%%", percentage); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, message); - snprintf(message, sizeof(message) - 1, "Writing @ 0x%08X", 0x10010000 + position); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 13, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); + snprintf(message, sizeof(message) - 1, "Writing... %u%%", percentage); + display_rp2040_update_state(pax_buffer, ili9341, message); uint32_t checkCrc = 0; memset(txBuffer, 0, write_size); @@ -217,6 +189,7 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { if (writeSuccess && (blockCrc == checkCrc)) { position += txSize; } else { + display_rp2040_update_state(pax_buffer, ili9341, "CRC mismatch"); while (!rp2040_bl_sync()) { vTaskDelay(20 / portTICK_PERIOD_MS); } @@ -225,16 +198,11 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { free(txBuffer); - pax_noclip(pax_buffer); - pax_background(pax_buffer, 0xCCCCCC); - memset(message, 0, sizeof(message)); - snprintf(message, sizeof(message) - 1, "Sealing..."); - pax_draw_text(pax_buffer, 0xFF000000, NULL, 18, 0, 20*0, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Finalizing..."); bool sealRes = rp2040_bl_seal(0x10010000, 0x10010000, totalLength, totalCrc); - snprintf(message, sizeof(message) - 1, "Result: %s", sealRes ? "OK" : "FAIL"); + snprintf(message, sizeof(message) - 1, "%s", sealRes ? "OK" : "FAIL"); pax_draw_text(pax_buffer, 0xFF000000, NULL, 18, 0, 20*1, message); ili9341_write(ili9341, pax_buffer->buf); @@ -243,11 +211,11 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { pax_noclip(pax_buffer); pax_background(pax_buffer, 0xCCCCCC); memset(message, 0, sizeof(message)); - snprintf(message, sizeof(message) - 1, "Waiting for reset..."); - pax_draw_text(pax_buffer, 0xFF000000, NULL, 18, 0, 20*0, message); - ili9341_write(ili9341, pax_buffer->buf); + display_rp2040_update_state(pax_buffer, ili9341, "Update completed"); rp2040_bl_go(0x10010000); } + + display_rp2040_update_state(pax_buffer, ili9341, "Update failed"); while (true) { vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/resources/rp2040_firmware.bin b/resources/rp2040_firmware.bin index 89d7459314583a46ed8744d17b18b15c30827bf8..285205d7fd59d9629728f79b478bd14ceb19332c 100755 GIT binary patch delta 16 YcmaDelj+S&rVV_2j7*#P`R>*M068B92><{9 delta 16 YcmaDelj+S&rVV_2jEtN4`R>*M067^32mk;8 From 587b1d9a490a5703bc48c575a75acc754e4ee7d9 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Thu, 2 Jun 2022 02:02:55 +0200 Subject: [PATCH 2/3] Small fixes --- main/rp2040_updater.c | 10 ++++------ main/wifi_ota.c | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/main/rp2040_updater.c b/main/rp2040_updater.c index 78cc013..0b2687a 100644 --- a/main/rp2040_updater.c +++ b/main/rp2040_updater.c @@ -202,10 +202,6 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { bool sealRes = rp2040_bl_seal(0x10010000, 0x10010000, totalLength, totalCrc); - snprintf(message, sizeof(message) - 1, "%s", sealRes ? "OK" : "FAIL"); - pax_draw_text(pax_buffer, 0xFF000000, NULL, 18, 0, 20*1, message); - ili9341_write(ili9341, pax_buffer->buf); - if (sealRes) { vTaskDelay(2000 / portTICK_PERIOD_MS); pax_noclip(pax_buffer); @@ -213,9 +209,11 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { memset(message, 0, sizeof(message)); display_rp2040_update_state(pax_buffer, ili9341, "Update completed"); rp2040_bl_go(0x10010000); + } else { + display_rp2040_update_state(pax_buffer, ili9341, "Update failed"); + vTaskDelay(1000 / portTICK_PERIOD_MS); + restart(); } - - display_rp2040_update_state(pax_buffer, ili9341, "Update failed"); while (true) { vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/main/wifi_ota.c b/main/wifi_ota.c index 144dfe7..c125b34 100644 --- a/main/wifi_ota.c +++ b/main/wifi_ota.c @@ -108,8 +108,10 @@ void display_ota_state(pax_buf_t* pax_buffer, ILI9341* ili9341, const char* text pax_noclip(pax_buffer); const pax_font_t* font = pax_get_font("sky mono"); pax_background(pax_buffer, 0xFFFFFF); - pax_vec1_t size = pax_text_size(font, 20, text); - pax_draw_text(pax_buffer, 0xFF000000, font, 20, (320 / 2) - (size.x / 2), (240 - 20) / 2, text); + pax_vec1_t title_size = pax_text_size(font, 18, "Firmware update"); + pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (title_size.x / 2), 120 - 30, "Co-processor update"); + pax_vec1_t size = pax_text_size(font, 18, text); + pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (size.x / 2), 120 + 10, text); ili9341_write(ili9341, pax_buffer->buf); } @@ -200,7 +202,7 @@ void ota_update(pax_buf_t* pax_buffer, ILI9341* ili9341) { ota_finish_err = esp_https_ota_finish(https_ota_handle); if ((err == ESP_OK) && (ota_finish_err == ESP_OK)) { ESP_LOGI(TAG, "ESP_HTTPS_OTA upgrade successful. Rebooting ..."); - display_ota_state(pax_buffer, ili9341, "Update completed"); + display_ota_state(pax_buffer, ili9341, "Update installed"); vTaskDelay(1000 / portTICK_PERIOD_MS); esp_restart(); } else { From a0181292a016087f43721885f53e38430e50ddfd Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Thu, 2 Jun 2022 02:06:05 +0200 Subject: [PATCH 3/3] Small fixes --- main/rp2040_updater.c | 7 ++----- main/wifi_ota.c | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/main/rp2040_updater.c b/main/rp2040_updater.c index 0b2687a..e05663b 100644 --- a/main/rp2040_updater.c +++ b/main/rp2040_updater.c @@ -110,13 +110,10 @@ void rp2040_updater(RP2040* rp2040, pax_buf_t* pax_buffer, ILI9341* ili9341) { } display_rp2040_update_state(pax_buffer, ili9341, "Synchronizing..."); - - char rx_buffer[16]; - uint8_t rx_buffer_pos = 0; - memset(rx_buffer, 0, sizeof(rx_buffer)); + while (true) { if (rp2040_bl_sync()) break; - vTaskDelay(500 / portTICK_PERIOD_MS); + vTaskDelay(100 / portTICK_PERIOD_MS); } uint32_t flash_start = 0, flash_size = 0, erase_size = 0, write_size = 0, max_data_len = 0; diff --git a/main/wifi_ota.c b/main/wifi_ota.c index c125b34..e31383a 100644 --- a/main/wifi_ota.c +++ b/main/wifi_ota.c @@ -109,7 +109,7 @@ void display_ota_state(pax_buf_t* pax_buffer, ILI9341* ili9341, const char* text const pax_font_t* font = pax_get_font("sky mono"); pax_background(pax_buffer, 0xFFFFFF); pax_vec1_t title_size = pax_text_size(font, 18, "Firmware update"); - pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (title_size.x / 2), 120 - 30, "Co-processor update"); + pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (title_size.x / 2), 120 - 30, "Firmware update"); pax_vec1_t size = pax_text_size(font, 18, text); pax_draw_text(pax_buffer, 0xFF000000, font, 18, (320 / 2) - (size.x / 2), 120 + 10, text); ili9341_write(ili9341, pax_buffer->buf);