Compare commits

..

No commits in common. "master" and "test-s3" have entirely different histories.

74 changed files with 746 additions and 47064 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
.idea
.pio

View file

@ -1,7 +1,7 @@
// Testing basic peripherals on Brain // Testing basic peripherals on Brain
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -26,14 +26,16 @@
#define ESP_BINARIES_H_ #define ESP_BINARIES_H_
// Configuration: select which bins to flash // Configuration: select which bins to flash
#define BIN_FILES BIN_C6_BLINK_IO8 #define BIN_FILES BIN_DEVKIT_S3
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LIST OF BINARIES // LIST OF BINARIES
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define BIN_ESP32_NINA_1_7_4 0 // nina 1.7.4 #define BIN_ESP32_NINA_1_7_4 0 // nina 1.7.4
#define BIN_ESP32_WIFI_AP_SKETCH 1 // esp32 AP with ssdi "YourAP" #define BIN_ESP32_WIFI_AP_SKETCH \
1 // esp32 wifi accesspoint sketch with ssdi "YourAP"
#define BIN_FEATHER_ESP32_V2_BLINKY 2 // Feather esp32 v2 blinky sketch
#define BIN_FEATHER_S2 10 // Feather esp32s2 factory firmware #define BIN_FEATHER_S2 10 // Feather esp32s2 factory firmware
#define BIN_FEATHER_S3 11 // Feather esp32s3 factory firmware #define BIN_FEATHER_S3 11 // Feather esp32s3 factory firmware
@ -42,10 +44,6 @@
#define BIN_DEVKIT_S2 20 // Espressif s2 devkit #define BIN_DEVKIT_S2 20 // Espressif s2 devkit
#define BIN_DEVKIT_S3 21 // Espressif s3 devkit #define BIN_DEVKIT_S3 21 // Espressif s3 devkit
#define BIN_ESP8266 30 // Espressif esp8266
#define BIN_C6_BLINK_IO8 40 // Blink sketch for C6 with LED on IO8
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Binaries include // Binaries include
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -53,6 +51,9 @@
#if BIN_FILES == BIN_ESP32_WIFI_AP_SKETCH #if BIN_FILES == BIN_ESP32_WIFI_AP_SKETCH
#include "esp_binaries/wifi_ap_binaries.h" #include "esp_binaries/wifi_ap_binaries.h"
#elif BIN_FILES == BIN_FEATHER_ESP32_V2_BLINKY
#include "esp_binaries/feather_esp32_v2_blinky_binaries.h"
#elif BIN_FILES == BIN_NINA_1_7_4 #elif BIN_FILES == BIN_NINA_1_7_4
#include "esp_binaries/nina_1_7_4_binaries.h" #include "esp_binaries/nina_1_7_4_binaries.h"
@ -71,15 +72,6 @@
#elif BIN_FILES == BIN_DEVKIT_S3 #elif BIN_FILES == BIN_DEVKIT_S3
#include "esp_binaries/esp32s3_devkit_binaries.h" #include "esp_binaries/esp32s3_devkit_binaries.h"
#elif BIN_FILES == BIN_ESP8266
#include "esp_binaries/esp8266_binaries.h"
#elif BIN_FILES == BIN_C6_BLINK_IO8
#include "esp_binaries/c6_blink_io8.h"
#else
#error "Please select BIN_FILES in esp_binaries.h"
#endif #endif
struct { struct {
@ -89,6 +81,12 @@ struct {
#if BIN_FILES == BIN_NINA_1_7_4 #if BIN_FILES == BIN_NINA_1_7_4
{0x00000, &NINA_W102_1_7_4}, {0x00000, &NINA_W102_1_7_4},
#elif BIN_FILES == BIN_FEATHER_ESP32_V2_BLINKY
{0x1000, &feather_esp32v2_blinky_bootloader},
{0x8000, &feather_esp32v2_blinky_partitions},
{0xe000, &boot_app0},
{0x10000, &feather_esp32v2_blinky},
#elif BIN_FILES == BIN_FEATHER_S2 #elif BIN_FILES == BIN_FEATHER_S2
{0x1000, &esp32s2_feather_test_ino_bootloader}, {0x1000, &esp32s2_feather_test_ino_bootloader},
{0x8000, &esp32s2_feather_test_ino_partitions}, {0x8000, &esp32s2_feather_test_ino_partitions},
@ -121,20 +119,7 @@ struct {
{0x8000, &Blink_ino_partitions}, {0x8000, &Blink_ino_partitions},
{0xe000, &boot_app0}, {0xe000, &boot_app0},
{0x10000, &Blink_ino}, {0x10000, &Blink_ino},
#elif BIN_FILES == BIN_ESP8266
{0x00000, &esp8266_blink_io0},
#elif BIN_FILES == BIN_C6_BLINK_IO8
{0x00000, &c6_blink_io8_bootloader},
{0x8000, &c6_blink_io8_partitions},
{0xe000, &boot_app0},
{0x10000, &c6_blink_io8},
#else
#error "Please select BIN_FILES in esp_binaries.h"
#endif #endif
}; };
enum { BIN_FILES_COUNT = sizeof(bin_files) / sizeof(bin_files[0]) }; enum { BIN_FILES_COUNT = sizeof(bin_files) / sizeof(bin_files[0]) };

View file

@ -9,7 +9,7 @@
// - There is no need to connect IO0/Reset since we will use DTR/RTS to reset ESP32 // - There is no need to connect IO0/Reset since we will use DTR/RTS to reset ESP32
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"
@ -30,25 +30,31 @@
// Note: baudrate does not matter if programming S2/S3 native USB // Note: baudrate does not matter if programming S2/S3 native USB
// But does matter if programming ESP32/8266 via USB-to-UART chip // But does matter if programming ESP32/8266 via USB-to-UART chip
#define ESP32_BAUDRATE (115200*8) #define ESP32_BAUDRATE 921600
// CDC Host object // CDC Host object
Adafruit_USBH_CDC SerialHost; Adafruit_USBH_CDC SerialHost;
#if ESP32_NATIVE_USB #if ESP32_NATIVE_USB
// Declare BootROM with IO0 and Reset will use GPIO for bootloader reset
// This is typically for programming ESP32-S2/S3 via native USB // Declare BootROM with IO0 and Reset will use GPIO for bootloader reset
ESP32BootROMClass ESP32BootROM(SerialHost, ESP32_IO0, ESP32_RESET); // This is typically for programming ESP32-S2/S3 via native USB
ESP32BootROMClass ESP32BootROM(SerialHost, ESP32_IO0, ESP32_RESET);
#else #else
// Defined an boot rom object that use SerialHost
// Declare BootROM without IO0 and Reset will use SerialHost.setDtrRts() for bootloader reset // Defined an boot rom object that use SerialHost
// This is for programming ESP32/8266 via USB-to-UART chip such as FTDI/CP210x/CH9102f // Declare BootROM without IO0 and Reset will use SerialHost.setDtrRts() for bootloader reset
ESP32BootROMClass ESP32BootROM(SerialHost); // This is for programming ESP32/8266 via USB-to-UART chip such as FTDI/CP210x/CH9102f
ESP32BootROMClass ESP32BootROM(SerialHost);
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Setup and Loop on Core0 // Setup and Loop on Core0
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) { void print_speed(size_t count, uint32_t ms) {
float count_k = count / 1000.0F; float count_k = count / 1000.0F;
float sec = ms / 1000.0F; float sec = ms / 1000.0F;
@ -72,14 +78,14 @@ void setup() {
// sync: wait for Brain.begin() called in core1 before accessing SD or other peripherals // sync: wait for Brain.begin() called in core1 before accessing SD or other peripherals
while (!Brain.inited()) delay(10); while (!Brain.inited()) delay(10);
while (!Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE)) { while ( !Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE) ) {
delay(100); delay(100);
} }
// Writing bin files // Writing bin files
size_t total_bytes = 0; size_t total_bytes = 0;
uint32_t ms = millis(); uint32_t ms = millis();
for (size_t i = 0; i < BIN_FILES_COUNT; i++) { for(size_t i=0; i<BIN_FILES_COUNT; i++) {
Brain.LCD_printf("Flashing file %u", i); Brain.LCD_printf("Flashing file %u", i);
Serial.printf("File %s\r\n", bin_files[i].zfile->name); Serial.printf("File %s\r\n", bin_files[i].zfile->name);
size_t wr_count = Brain.esp32_programFlashDefl(bin_files[i].zfile, bin_files[i].addr); size_t wr_count = Brain.esp32_programFlashDefl(bin_files[i].zfile, bin_files[i].addr);
@ -122,7 +128,7 @@ void setup1() {
// core1's loop: process usb host task on core1 // core1's loop: process usb host task on core1
void loop1() { void loop1() {
if (Brain.esp32_s3_inReset()) { if ( Brain.esp32_s3_inReset() ){
// Note: S3 has an USB-OTG errata // Note: S3 has an USB-OTG errata
// https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf // https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf
// which is walkarounded by idf/arduino-esp32 to always mux JTAG to USB for // which is walkarounded by idf/arduino-esp32 to always mux JTAG to USB for
@ -138,7 +144,7 @@ void loop1() {
Brain.USBHost.task(); Brain.USBHost.task();
// periodically flush SerialHost if connected // periodically flush SerialHost if connected
if (SerialHost && SerialHost.connected()) { if ( SerialHost && SerialHost.connected() ) {
SerialHost.flush(); SerialHost.flush();
} }
@ -152,7 +158,8 @@ void loop1() {
extern "C" { extern "C" {
// Invoked when device is mounted (configured) // Invoked when device is mounted (configured)
void tuh_mount_cb(uint8_t daddr) { void tuh_mount_cb (uint8_t daddr)
{
uint16_t vid, pid; uint16_t vid, pid;
tuh_vid_pid_get(daddr, &vid, &pid); tuh_vid_pid_get(daddr, &vid, &pid);
@ -161,7 +168,8 @@ void tuh_mount_cb(uint8_t daddr) {
} }
/// Invoked when device is unmounted (bus reset/unplugged) /// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t dev_addr) { void tuh_umount_cb(uint8_t dev_addr)
{
(void) dev_addr; (void) dev_addr;
Brain.LCD_printf(1, "No USB Device"); Brain.LCD_printf(1, "No USB Device");
} }

View file

@ -26,15 +26,13 @@
#define ESP_BINARIES_H_ #define ESP_BINARIES_H_
// Configuration: select which bins to flash // Configuration: select which bins to flash
#define BIN_FILES BIN_C6_BLINK_IO8 #define BIN_FILES BIN_METRO_S2
//--------------------------------------------------------------------+ //------------- Binaries Define -------------//
// LIST OF BINARIES
//--------------------------------------------------------------------+
#define BIN_ESP32_NINA_1_7_4 0 // nina 1.7.4 #define BIN_ESP32_NINA_1_7_4 0 // nina 1.7.4
#define BIN_ESP32_WIFI_AP_SKETCH 1 // esp32 AP with ssdi "YourAP" #define BIN_ESP32_WIFI_AP_SKETCH \
#define BIN_FEATHER_ESP32_V2_BLINKY 2 // Feather esp32 v2 blinky sketch 1 // esp32 wifi accesspoint sketch with ssdi "YourAP"
#define BIN_FEATHER_S2 10 // Feather esp32s2 factory firmware #define BIN_FEATHER_S2 10 // Feather esp32s2 factory firmware
#define BIN_FEATHER_S3 11 // Feather esp32s3 factory firmware #define BIN_FEATHER_S3 11 // Feather esp32s3 factory firmware
@ -43,20 +41,13 @@
#define BIN_DEVKIT_S2 20 // Espressif s2 devkit #define BIN_DEVKIT_S2 20 // Espressif s2 devkit
#define BIN_DEVKIT_S3 21 // Espressif s3 devkit #define BIN_DEVKIT_S3 21 // Espressif s3 devkit
#define BIN_FEATHER_8266_BLINKY 30 // Feather esp8266 blinky sketch #define BIN_ESP8266 30 // Espressif esp8266
#define BIN_C6_BLINK_IO8 40 // Blink sketch for C6 with LED on IO8 //------------- Binaries include -------------//
//--------------------------------------------------------------------+
// Binaries include
//--------------------------------------------------------------------+
#if BIN_FILES == BIN_ESP32_WIFI_AP_SKETCH #if BIN_FILES == BIN_ESP32_WIFI_AP_SKETCH
#include "esp_binaries/wifi_ap_binaries.h" #include "esp_binaries/wifi_ap_binaries.h"
#elif BIN_FILES == BIN_FEATHER_ESP32_V2_BLINKY
#include "esp_binaries/feather_esp32_v2_blinky_binaries.h"
#elif BIN_FILES == BIN_NINA_1_7_4 #elif BIN_FILES == BIN_NINA_1_7_4
#include "esp_binaries/nina_1_7_4_binaries.h" #include "esp_binaries/nina_1_7_4_binaries.h"
@ -75,11 +66,8 @@
#elif BIN_FILES == BIN_DEVKIT_S3 #elif BIN_FILES == BIN_DEVKIT_S3
#include "esp_binaries/esp32s3_devkit_binaries.h" #include "esp_binaries/esp32s3_devkit_binaries.h"
#elif BIN_FILES == BIN_FEATHER_8266_BLINKY #elif BIN_FILES == BIN_ESP8266
#include "esp_binaries/feather_esp8266_blinky.h" #include "esp_binaries/esp8266_binaries.h"
#elif BIN_FILES == BIN_C6_BLINK_IO8
#include "esp_binaries/c6_blink_io8.h"
#else #else
#error "Please select BIN_FILES in esp_binaries.h" #error "Please select BIN_FILES in esp_binaries.h"
@ -93,12 +81,6 @@ struct {
#if BIN_FILES == BIN_NINA_1_7_4 #if BIN_FILES == BIN_NINA_1_7_4
{0x00000, &NINA_W102_1_7_4}, {0x00000, &NINA_W102_1_7_4},
#elif BIN_FILES == BIN_FEATHER_ESP32_V2_BLINKY
{0x1000, &feather_esp32v2_blinky_bootloader},
{0x8000, &feather_esp32v2_blinky_partitions},
{0xe000, &boot_app0},
{0x10000, &feather_esp32v2_blinky},
#elif BIN_FILES == BIN_FEATHER_S2 #elif BIN_FILES == BIN_FEATHER_S2
{0x1000, &esp32s2_feather_test_ino_bootloader}, {0x1000, &esp32s2_feather_test_ino_bootloader},
{0x8000, &esp32s2_feather_test_ino_partitions}, {0x8000, &esp32s2_feather_test_ino_partitions},
@ -132,18 +114,12 @@ struct {
{0xe000, &boot_app0}, {0xe000, &boot_app0},
{0x10000, &Blink_ino}, {0x10000, &Blink_ino},
#elif BIN_FILES == BIN_FEATHER_8266_BLINKY #elif BIN_FILES == BIN_ESP8266
{0x0000, &Blink_ino}, {0x00000, &esp8266_blink_io0},
#elif BIN_FILES == BIN_C6_BLINK_IO8
{0x00000, &c6_blink_io8_bootloader},
{0x8000, &c6_blink_io8_partitions},
{0xe000, &boot_app0},
{0x10000, &c6_blink_io8},
#else #else
#error "Please select BIN_FILES in esp_binaries.h" #error "Please select BIN_FILES in esp_binaries.h"
#endif #endif
}; };
enum { BIN_FILES_COUNT = sizeof(bin_files) / sizeof(bin_files[0]) }; enum { BIN_FILES_COUNT = sizeof(bin_files) / sizeof(bin_files[0]) };

View file

@ -0,0 +1,79 @@
// This sketch program ESP32 by flashing bin file from on-flash (with .h header)
// Supported/tested ESP MCU are: ESP32, ESP32-S2, ESP32-S3, ESP8266
// Hardware wiring:
// - Brain GPIO28 <-> ESP32 IO0
// - Brain Reset <-> ESP32 Enable
// - Brain TX/RX <-> ESP32 RX/TX
// required for Host MSC block device
#include "SdFat.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
#include "Adafruit_TestBed_Brains.h"
// Change BIN_FILES in esp_binaries.h header to select which binaries to flash
// bin_files[] is defined accordingly
#include "esp_binaries.h"
#define ESP32_RESET 27
#define ESP32_IO0 28
#define ESP32_BAUDRATE 2000000
//#define ESP32_BAUDRATE 1500000
//#define ESP32_BAUDRATE 921600
//#define ESP32_BAUDRATE 115200
// Defined an boot rom object that use UART Serial1
ESP32BootROMClass ESP32BootROM(Serial1, ESP32_IO0, ESP32_RESET);
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
float count_k = count / 1000.0F;
float sec = ms / 1000.0F;
float speed = count_k / sec;
Brain.LCD_printf(0, "%.01fKB %.01fs", count_k, sec);
Brain.LCD_printf(1, "Spd: %.01f KB/s", speed);
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Tester Brains: Programming ESP with UART!");
Brain.begin();
Brain.usbh_setVBus(true); // enable VBUS for power
while ( !Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE) ) {
// retry syncing
delay(100);
}
// Writing bin files
size_t total_bytes = 0;
uint32_t ms = millis();
for(size_t i=0; i<BIN_FILES_COUNT; i++) {
Brain.LCD_printf(0, "Flashing file %u", i);
Serial.printf("File: %s\r\n", bin_files[i].zfile->name);
size_t wr_count = Brain.esp32_programFlashDefl(bin_files[i].zfile, bin_files[i].addr);
total_bytes += wr_count;
if (!wr_count) {
Brain.LCD_printf_error("Failed to flash");
}
}
print_speed(total_bytes, millis() - ms);
Brain.esp32_end();
// reset ESP32 to run new firmware
Brain.targetReset();
}
void loop() {
}

View file

@ -0,0 +1,128 @@
// This sketch program ESP32 by flashing bin file from SD Card
// Hardware wiring:
// - Brain GPIO28 <-> ESP32 IO0
// - Brain Reset <-> ESP32 Enable
// - Brain TX/RX <-> ESP32 RX/TX
// required for Host MSC block device
#include "SdFat.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
#include "Adafruit_TestBed_Brains.h"
#define ESP32_RESET 27
#define ESP32_IO0 28
#define ESP32_BAUDRATE 2000000
//#define ESP32_BAUDRATE 921600
//#define ESP32_BAUDRATE 115200
// Bin files on SDCard to program
// These files can be generated by any of Arduino sketches
// The example use WiFiAccessPoint sketch, which we can verify its running image
// by simply scan for existence of ssid "YourAP"
struct {
uint32_t addr;
const char* fpath;
} bin_list [] = {
{ 0x1000 , "esp32/WiFiAccessPoint/WiFiAccessPoint.ino.bootloader.bin" },
{ 0x8000 , "esp32/WiFiAccessPoint/WiFiAccessPoint.ino.partitions.bin" },
{ 0xe000 , "esp32/WiFiAccessPoint/boot_app0.bin" },
{ 0x10000 , "esp32/WiFiAccessPoint/WiFiAccessPoint.ino.bin" },
};
enum {
BIN_LIST_COUNT = sizeof(bin_list)/sizeof(bin_list[0])
};
// Defined an boot rom object that use UART Serial1
ESP32BootROMClass ESP32BootROM(Serial1, ESP32_IO0, ESP32_RESET);
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void prepare_sd(void) {
if (!Brain.SD_detected()) {
Brain.LCD_printf(0, "No SD Card");
while ( !Brain.SD_detected() ) delay(10);
}
if ( !Brain.SD_begin(SD_SCK_MHZ(16)) ) {
Brain.LCD_printf(0, "SD init failed");
while(1) delay(10);
}
Brain.LCD_printf(0, "SD mounted");
// Print out file on SD if Serial is connected
if (Serial) {
Serial.println();
Serial.println("SD Contents:");
Serial.printf("Card size = %0.1f GB\n", 0.000000512 * Brain.SD.card()->sectorCount());
Brain.SD.ls(LS_R | LS_DATE | LS_SIZE);
}
}
void print_speed(size_t count, uint32_t ms) {
Brain.LCD_printf(0, "%.01fKB %.01fs", count/1000.0F, ms / 1000.0F);
Serial.printf("Completed %u bytes in %.02f seconds.\r\n", count, ms / 1000.0F);
Serial.printf("Speed : %.02f KB/s\r\n", (count / 1000.0F) / (ms / 1000.0F));
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Tester Brains: Programming ESP32 with UART!");
Brain.begin();
// prepare SD Card
prepare_sd();
while ( !Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE) ) {
// retry syncing
delay(100);
}
// Writing bin files
size_t total_bytes = 0;
uint32_t ms = millis();
for(size_t i=0; i<BIN_LIST_COUNT; i++) {
Brain.LCD_printf("Flashing file %u", i);
size_t wr_count = Brain.esp32_programFlash(bin_list[i].fpath, bin_list[i].addr);
total_bytes += wr_count;
if (!wr_count) {
Brain.LCD_printf_error("Failed to flash");
}
}
print_speed(total_bytes, millis() - ms);
Brain.esp32_end(false);
// reset ESP32 to run new firmware
Brain.targetReset();
}
void loop() {
}
//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+
// call usbh_begin() here to make pio usb background task run on core1
// NOTE: Brain.begin() should be called here as well to prevent race condition
void setup1() {
}
// core1's loop: process usb host task on core1
void loop1() {
yield();
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,134 +0,0 @@
// This sketch program ESP32 by flashing bin file from on-flash (with .h header)
// Supported/tested ESP MCU are: ESP32, ESP32-S2, ESP32-S3, ESP8266
// Hardware wiring:
// - Brain GPIO28 <-> ESP32 IO0
// - Brain Reset <-> ESP32 Enable
// - Brain TX/RX <-> ESP32 RX/TX
// required for Host MSC block device
#include "SdFat_Adafruit_Fork.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
#include "Adafruit_TestBed_Brains.h"
// Change BIN_FILES in esp_binaries.h header to select which binaries to flash
// bin_files[] is defined accordingly
#include "esp_binaries.h"
#define ESP32_RESET 27
#define ESP32_IO0 28
#define ESP32_BAUDRATE 2000000
//#define ESP32_BAUDRATE 1500000
//#define ESP32_BAUDRATE 921600
//#define ESP32_BAUDRATE 115200
// Defined an boot rom object that use UART Serial1
ESP32BootROMClass ESP32BootROM(Serial1, ESP32_IO0, ESP32_RESET);
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
float count_k = count / 1000.0F;
float sec = ms / 1000.0F;
float speed = count_k / sec;
Brain.LCD_printf(0, "%.01fKB %.01fs", count_k, sec);
Brain.LCD_printf(1, "Spd: %.01f KB/s", speed);
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Tester Brains: Programming ESP with UART!");
// sync: wait for Brain.begin() called in core1 before accessing SD or other peripherals
while (!Brain.inited()) delay(10);
while (!Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE)) {
// retry syncing
delay(100);
}
// Writing bin files
size_t total_bytes = 0;
uint32_t ms = millis();
for (size_t i = 0; i < BIN_FILES_COUNT; i++) {
Brain.LCD_printf(0, "Flashing file %u", i);
Serial.printf("File: %s\r\n", bin_files[i].zfile->name);
size_t wr_count = Brain.esp32_programFlashDefl(bin_files[i].zfile, bin_files[i].addr);
total_bytes += wr_count;
if (!wr_count) {
Brain.LCD_printf_error("Failed to flash");
}
}
print_speed(total_bytes, millis() - ms);
Brain.esp32_end();
// reset ESP32 to run new firmware
Brain.targetReset();
}
void loop() {
}
//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+
// call usbh_begin() here to make pio usb background task run on core1
// NOTE: Brain.begin() should be called here as well to prevent race condition
void setup1() {
Brain.begin();
Brain.usbh_begin();
Brain.LCD_printf(0, "No USB attached");
Brain.LCD_printf(1, "Plug your device");
}
// core1's loop: process usb host task on core1
void loop1() {
if (Brain.esp32_s3_inReset()) {
// Note: S3 has an USB-OTG errata
// https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf
// which is walkarounded by idf/arduino-esp32 to always mux JTAG to USB for
// uploading and/or power on. Afterwards USB-OTG will be set up if selected
// so. However rp2040 USBH is running too fast and can actually retrieve
// device/configuration descriptor of JTAG before the OTG is fully setup.
// We delay a bit here
delay(500);
Brain.esp32_s3_clearReset();
}
Brain.USBHost.task();
yield();
}
//--------------------------------------------------------------------+
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
extern "C" {
// Invoked when device is mounted (configured)
void tuh_mount_cb(uint8_t daddr) {
uint16_t vid, pid;
tuh_vid_pid_get(daddr, &vid, &pid);
Serial.printf("Device attached, address = %d\r\n", daddr);
Brain.LCD_printf("USBID %04x:%04x", vid, pid);
}
/// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t dev_addr) {
(void) dev_addr;
Brain.LCD_printf(1, "No USB Device");
}
}

View file

@ -6,7 +6,7 @@
// - Brain's USB host to Target USB // - Brain's USB host to Target USB
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"
@ -17,7 +17,11 @@
#include "Adafruit_TestBed_Brains.h" #include "Adafruit_TestBed_Brains.h"
// file path on SDCard to program // RP2040 Boot VID/PID
#define BOOT_VID 0x2e8a
#define BOOT_PID 0x0003
// file path on SDCard to prograom
#define TEST_FILE_PATH "nrf/feather_nrf52840/bleblink.bin" #define TEST_FILE_PATH "nrf/feather_nrf52840/bleblink.bin"
// DAP interface for nRF5x // DAP interface for nRF5x
@ -62,10 +66,8 @@ void setup() {
// erase chip before programming // erase chip before programming
Brain.dap_eraseChip(); Brain.dap_eraseChip();
// for nrf52840 don't use crc32 as it is not supported.
// Note: verify is with reading back increase programming time by 2x
uint32_t ms = millis(); uint32_t ms = millis();
size_t copied_bytes = Brain.dap_programFlash(TEST_FILE_PATH, 0, true, false); size_t copied_bytes = Brain.dap_programFlash(TEST_FILE_PATH, 0);
ms = millis() - ms; ms = millis() - ms;
print_speed(copied_bytes, ms); print_speed(copied_bytes, ms);
@ -108,7 +110,9 @@ void tuh_mount_cb (uint8_t dev_addr)
uint16_t vid, pid; uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid); tuh_vid_pid_get(dev_addr, &vid, &pid);
Brain.LCD_printf("USBID %04x:%04x", vid, pid); if ( !(vid == BOOT_VID && pid == BOOT_PID) ) {
Brain.LCD_printf(1, "UnkDev %04x:%04x", vid, pid);
}
} }
/// Invoked when device is unmounted (bus reset/unplugged) /// Invoked when device is unmounted (bus reset/unplugged)

View file

@ -1,121 +0,0 @@
// This sketch program SAMD with bin file from SDCard using Adafruit_DAP
// Hardware wiring:
// - Brain's header Reset <-> Target Reset
// - Brain's header SWDIO <-> Target SWDIO
// - Brain's header SWCLK <-> Target SWCLK
// - Brain's USB host to Target USB
// required for Host MSC block device
#include "SdFat_Adafruit_Fork.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
// required for DAP programming
#include "Adafruit_DAP.h"
#include "Adafruit_TestBed_Brains.h"
// file path on SDCard to program
#define TEST_FILE_PATH "nrf/feather_nrf52840/bleblink.bin"
// DAP interface for nRF5x
Adafruit_DAP_nRF5x dap;
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
Brain.LCD_printf(0, "%.01fKB in %.01fs", count/1000.0F, ms / 1000.0F);
Serial.printf("Completed %u bytes in %.02f seconds.\r\n", count, ms / 1000.0F);
Serial.printf("Speed : %.02f KB/s\r\n", (count / 1000.0F) / (ms / 1000.0F));
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Tester Brains: nRF52840 programming !");
// sync: wait for Brain.usbh_begin() called in core1 before accessing SD or other peripherals
while (!Brain.usbh_inited()) delay(10);
Brain.SD_begin(SD_SCK_MHZ(16));
// Print out file on SD if Serial is connected
if (Serial) {
Serial.println();
Serial.println("SD Contents:");
Serial.printf("Card size = %0.1f GB\n", 0.000000512 * Brain.SD.card()->sectorCount());
Brain.SD.ls(LS_R | LS_SIZE);
}
Brain.targetReset();
Brain.dap_begin(&dap);
Brain.dap_connect();
Brain.dap_unprotectBoot();
// erase chip before programming
Brain.dap_eraseChip();
// for nrf52840 don't use crc32 as it is not supported.
// Note: verify is with reading back increase programming time by 2x
uint32_t ms = millis();
size_t copied_bytes = Brain.dap_programFlash(TEST_FILE_PATH, 0, true, false);
ms = millis() - ms;
print_speed(copied_bytes, ms);
Brain.dap_protectBoot();
Brain.dap_disconnect();
Brain.targetReset();
}
void loop() {
}
//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+
// call usbh_begin() here to make pio usb background task run on core1
// NOTE: Brain.begin() should be called here as well to prevent race condition
void setup1() {
Brain.begin();
Brain.usbh_begin();
Brain.LCD_printf(1, "No USB Device");
}
// core1's loop: process usb host task on core1
void loop1() {
Brain.USBHost.task();
}
//--------------------------------------------------------------------+
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
extern "C" {
// Invoked when device is mounted (configured)
void tuh_mount_cb (uint8_t dev_addr)
{
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
Brain.LCD_printf("USBID %04x:%04x", vid, pid);
}
/// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t dev_addr)
{
(void) dev_addr;
Brain.LCD_printf(1, "No USB Device");
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,135 +0,0 @@
// This sketch program rp2040 by copying UF2 file from SDCard to
// rp2040 bootrom
// Hardware wiring:
// - Brain's Target GPIO28 to RP2 bootsel
// - Brain's Target Reset to RP2 Reset
// - Brain's USB host to RP2040 USB interface
// required for Host MSC block device
#include "SdFat_Adafruit_Fork.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
#include "Adafruit_TestBed_Brains.h"
// firmware.h is converted using tools/file2carray.py e.g
// python tools/file2carray.py cdc_msc.uf2
// above command will generate cdc_msc.uf2.h with bindata, bindata_len
#include "metro_rp2350_cdc_msc.uf2.h"
// RP2040 Boot VID/PID
#define BOOT_VID 0x2e8a
#define BOOT_PID_RP2040 0x0003
#define BOOT_PID_RP2350 0x000f
// If USB filesystem is mounted
volatile bool is_usbfs_mounted = false;
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
Brain.LCD_printf(0, "%.01fKB %.01fs", count/1000.0F, ms / 1000.0F);
Serial.printf("Completed %u bytes in %.02f seconds.\r\n", count, ms / 1000.0F);
Serial.printf("Speed : %.02f KB/s\r\n", (count / 1000.0F) / (ms / 1000.0F));
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Program RP2 by copy UF2 from Internal Flash to Bootloader!");
// sync: wait for Brain.begin() called in core1 before accessing SD or other peripherals
while (!Brain.inited()) delay(10);
// wait for USB filesystem is mounted. USB host bit-banging and task is
// processed on core1
while (!is_usbfs_mounted) delay(10);
// Copy UF2 file
Brain.LCD_printf(0, "Copying firmware");
Serial.println("Copying UF2 from Flash to USBHFS");
uint32_t ms = millis();
size_t copied_bytes = Brain.rp2_programUF2(bindata, bindata_len);
print_speed(copied_bytes, millis() - ms);
// wait for rp2040 boot rom to reset
// while (is_usbfs_mounted) delay(10);
}
void loop() {
Serial.flush();
}
//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+
// call usbh_begin() here to make pio usb background task run on core1
// NOTE: Brain.begin() should be called here as well to prevent race condition
void setup1() {
Brain.begin();
Brain.usbh_begin();
Brain.LCD_printf(1, "No USB Device");
// reset rp2040 target into Boot Rom, default bootsel = 28, reset duration = 10 ms
Brain.rp2_targetResetBootRom();
}
// core1's loop: process usb host task on core1
void loop1() {
Brain.USBHost.task();
}
//--------------------------------------------------------------------+
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
bool is_rp2_bootloader(uint16_t vid, uint16_t pid) {
return (vid == BOOT_VID && (pid == BOOT_PID_RP2040 || pid == BOOT_PID_RP2350));
}
extern "C" {
// Invoked when device is mounted (configured)
void tuh_mount_cb(uint8_t dev_addr) {
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
if (!is_rp2_bootloader(vid, pid)) {
Brain.LCD_printf(1, "UnkDev %04x:%04x", vid, pid);
}
}
/// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t dev_addr) {
(void)dev_addr;
Brain.LCD_printf(1, "No USB Device");
}
// Invoked when a device with MassStorage interface is mounted
void tuh_msc_mount_cb(uint8_t dev_addr) {
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
if (is_rp2_bootloader(vid, pid)) {
is_usbfs_mounted = Brain.usbh_mountFS(dev_addr);
if (is_usbfs_mounted) {
uint16_t rp2variant = (pid == BOOT_PID_RP2040 ? 2040 : 2350);
Brain.LCD_printf(1, "RP%u Bootldr", rp2variant);
}
}
}
// Invoked when a device with MassStorage interface is unmounted
void tuh_msc_umount_cb(uint8_t dev_addr) {
is_usbfs_mounted = false;
Brain.usbh_umountFS(dev_addr);
}
}

View file

@ -6,7 +6,7 @@
// - Brain's USB host to RP2040 USB interface // - Brain's USB host to RP2040 USB interface
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"
@ -79,7 +79,7 @@ void setup() {
Serial.println("Copying from SD to USBHFS: " UF2_FILE_PATH); Serial.println("Copying from SD to USBHFS: " UF2_FILE_PATH);
uint32_t ms = millis(); uint32_t ms = millis();
size_t copied_bytes = Brain.rp2_programUF2(UF2_FILE_PATH); size_t copied_bytes = Brain.rp2040_programUF2(UF2_FILE_PATH);
print_speed(copied_bytes, millis() - ms); print_speed(copied_bytes, millis() - ms);
@ -104,7 +104,7 @@ void setup1() {
Brain.LCD_printf(1, "No USB Device"); Brain.LCD_printf(1, "No USB Device");
// reset rp2040 target into Boot Rom, default bootsel = 28, reset duration = 10 ms // reset rp2040 target into Boot Rom, default bootsel = 28, reset duration = 10 ms
Brain.rp2_targetResetBootRom(); Brain.rp2040_targetResetBootRom();
} }
// core1's loop: process usb host task on core1 // core1's loop: process usb host task on core1

View file

@ -6,7 +6,7 @@
// - Brain's USB host to Target USB // - Brain's USB host to Target USB
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -6,7 +6,7 @@
// - Brain's USB host to Target USB // - Brain's USB host to Target USB
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -6,7 +6,7 @@
// - Brain's USB host to Target USB // - Brain's USB host to Target USB
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -1,112 +0,0 @@
// This sketch program SAMD with bin file from SDCard using Adafruit_DAP
// Hardware wiring:
// - Brain's header Reset <-> Target Reset
// - Brain's header SWDIO <-> Target SWDIO
// - Brain's header SWCLK <-> Target SWCLK
// - Brain's USB host to Target USB
// required for Host MSC block device
#include "SdFat_Adafruit_Fork.h"
// required for USB host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"
// required for DAP programming
#include "Adafruit_DAP.h"
#include "Adafruit_TestBed_Brains.h"
// file path on SDCard to hold nrf52840 binary
#define READ_FILE_PATH "nrf/readback.bin"
#define READ_SIZE (1024u*1024u) // 1 MB
// DAP interface for nRF5x
Adafruit_DAP_nRF5x dap;
//--------------------------------------------------------------------+
// Setup and Loop on Core0
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
Brain.LCD_printf(0, "%.01fKB in %.01fs", count/1000.0F, ms / 1000.0F);
Serial.printf("Completed %u bytes in %.02f seconds.\r\n", count, ms / 1000.0F);
Serial.printf("Speed : %.02f KB/s\r\n", (count / 1000.0F) / (ms / 1000.0F));
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Tester Brains: Reading nRF52840 to SD Card!");
// sync: wait for Brain.usbh_begin() called in core1 before accessing SD or other peripherals
while (!Brain.usbh_inited()) delay(10);
Brain.SD_begin(SD_SCK_MHZ(16));
// Print out file on SD if Serial is connected
if (Serial) {
Serial.println();
Serial.println("SD Contents:");
Serial.printf("Card size = %0.1f GB\n", 0.000000512 * Brain.SD.card()->sectorCount());
Brain.SD.ls(LS_R | LS_SIZE);
}
Brain.targetReset();
Brain.dap_begin(&dap);
Brain.dap_connect();
uint32_t ms = millis();
size_t nbytes = Brain.dap_readFlash(READ_FILE_PATH, 0, READ_SIZE);
ms = millis() - ms;
print_speed(nbytes, ms);
Brain.dap_disconnect();
Brain.targetReset();
}
void loop() {
}
//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+
// call usbh_begin() here to make pio usb background task run on core1
// NOTE: Brain.begin() should be called here as well to prevent race condition
void setup1() {
Brain.begin();
Brain.usbh_begin();
Brain.LCD_printf(1, "No USB Device");
}
// core1's loop: process usb host task on core1
void loop1() {
Brain.USBHost.task();
}
//--------------------------------------------------------------------+
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
extern "C" {
// Invoked when device is mounted (configured)
void tuh_mount_cb (uint8_t dev_addr)
{
uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
Brain.LCD_printf("USBID %04x:%04x", vid, pid);
}
/// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t dev_addr)
{
(void) dev_addr;
Brain.LCD_printf(1, "No USB Device");
}
}

View file

@ -2,7 +2,7 @@
// to LCD. Also determine if device support MSC or HID // to LCD. Also determine if device support MSC or HID
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -2,7 +2,7 @@
// to LCD. Also determine if device support MSC or HID // to LCD. Also determine if device support MSC or HID
// required for Host MSC block device // required for Host MSC block device
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
// required for USB host // required for USB host
#include "pio_usb.h" #include "pio_usb.h"

View file

@ -7,7 +7,7 @@ extern Adafruit_TestBed TB;
#if defined(ARDUINO_ARCH_RP2040) \ #if defined(ARDUINO_ARCH_RP2040) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) \ || defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) \ || defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2) \ || defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3) \
|| defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) \ || defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) \
|| defined(ARDUINO_SAM_DUE) \ || defined(ARDUINO_SAM_DUE) \
|| defined(ARDUINO_ARCH_RENESAS_UNO) || defined(ARDUINO_ARCH_RENESAS_UNO)
@ -26,7 +26,7 @@ void setup() {
#if defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) || \ #if defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) || \ defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2) || \ defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
// ESP32 is kinda odd in that secondary ports must be manually // ESP32 is kinda odd in that secondary ports must be manually
// assigned their pins with setPins()! // assigned their pins with setPins()!

View file

@ -1,30 +0,0 @@
// Generated by tools/esp_compress.py
#define ESP_BINARIES_COUNT (1)
// const esp32_zipfile_t NINA_W102_1_7_5
const esp32_zipfile_t NINA_W102_1_7_5 = {
.name = "NINA_W102-1.7.5.bin.gz",
.data = NULL,
.compressed_len = 634996,
.uncompressed_len = 1160192,
.md5 =
{
0x07,
0x7c,
0xec,
0x6d,
0xaa,
0x68,
0x13,
0xc5,
0xa4,
0x68,
0x0f,
0x45,
0xc9,
0xd8,
0x77,
0x6b,
},
};

View file

@ -1,146 +0,0 @@
/* This sketch run on SAMD21/SAMD51 to program ESP32 by flashing bin file from SD Card
* Supported/tested ESP MCU are: ESP32, ESP32-S2, ESP32-S3, ESP8266
* Hardware wiring:
* - TB D2 <-> ESP32 IO0
* - TB D3 <-> ESP32 Enable
* - TB TX/RX <-> ESP32 RX/TX
*
* How to run this example:
* 0. Define ESP32_RESET, ESP32_IO0, SD_CS, SD_DETECT in this sketch according to your hardware setup
* 1. Generate compressed binary and its metadata (len, md5 etc..) by running:
* python3 tools/esp_compress.py --sd <directory_of_bin_files>
* For example: python tools/esp_compress.py --sd .
* 2. .bin.gz (e.g NINA_W102-1.7.5.bin.gz) and esp_binaries.h will be generated in the same directory
* 3. Copy esp_binaries.h to this example directory
* 4. Copy .bin.gz files to SD Card within BIN_DIR (defined in this sketch)
* 5. Insert SD Card to board
* 6. Upload this sketch to board
*
* Note: for convenience, this example included generated 'NINA_W102-1.7.5.bin.gz' and 'esp_binaries.h'
* from https://github.com/adafruit/nina-fw/releases/tag/1.7.5 in this example directory.
*/
#include "SdFat_Adafruit_Fork.h"
// #include "Adafruit_TinyUSB.h"
#include "Adafruit_TestBed.h"
//--------------------------------------------------------------------+
// Hardware Configuration
//--------------------------------------------------------------------+
// These are defined in airlift-capable board such PyPortal, PyBadge, etc.
#if defined(ESP32_GPIO0) && defined(ESP32_RESETN)
#define ESP32_RESET ESP32_RESETN
#define ESP32_IO0 ESP32_GPIO0
#else
#define ESP32_RESET 2
#define ESP32_IO0 3
#endif
#if defined(ARDUINO_PYPORTAL_M4)
#define SD_CS 32
#define SD_DETECT 33
#else
#define SD_CS 4
#define SD_DETECT 5 // optional
#endif
#define ESP32_BAUDRATE 2000000
//#define ESP32_BAUDRATE 1500000
//#define ESP32_BAUDRATE 921600
//#define ESP32_BAUDRATE 115200
//--------------------------------------------------------------------+
// Binaries and Path
//--------------------------------------------------------------------+
#define BIN_DIR "/" // SD card's directory that contains bin files
#include "esp_binaries.h"
struct {
uint32_t addr;
esp32_zipfile_t const *zfile;
} bin_files[] = {
{0x00000, &NINA_W102_1_7_5}
};
enum { BIN_FILES_COUNT = sizeof(bin_files) / sizeof(bin_files[0]) };
//--------------------------------------------------------------------+
// Defined an boot rom object that use UART Serial1
ESP32BootROMClass ESP32BootROM(Serial1, ESP32_IO0, ESP32_RESET);
SdFat SD;
File32 fbin;
//--------------------------------------------------------------------+
// Implementation
//--------------------------------------------------------------------+
void print_speed(size_t count, uint32_t ms) {
float count_k = count / 1000.0F;
float sec = ms / 1000.0F;
float speed = count_k / sec;
Serial.print(count_k); Serial.print("KB "); Serial.print(sec); Serial.println("s");
Serial.print("Spd: "); Serial.print(speed); Serial.println(" KB/s");
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("TestBed: Programming ESP32 with UART!");
#ifdef SD_DETECT
pinMode(SD_DETECT, INPUT_PULLUP);
if (digitalRead(SD_DETECT) == LOW) {
Serial.println("SD Card not inserted");
while (1) delay(10);
}
#endif
if (!SD.begin(SD_CS, SD_SCK_MHZ(12))) {
Serial.println("SD Card init failed");
while (1) delay(10);
}
Serial.println("SD Card init OK");
TB.begin();
while ( !TB.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE) ) {
// retry syncing
delay(100);
}
// Writing bin files
size_t total_bytes = 0;
uint32_t ms = millis();
for(size_t i=0; i<BIN_FILES_COUNT; i++) {
Serial.printf("Flashing file %u\r\n", i);
Serial.printf("File: %s\r\n", bin_files[i].zfile->name);
char bin_path[128] = BIN_DIR;
strcat(bin_path, bin_files[i].zfile->name);
fbin.open(&SD, bin_path);
if (!fbin) {
Serial.printf("Failed to open file %s\r\n", bin_files[i].zfile->name);
continue;
}
size_t wr_count = TB.esp32_programFlashDefl(bin_files[i].zfile, bin_files[i].addr, &fbin);
total_bytes += wr_count;
if (!wr_count) {
Serial.printf("Failed to flash");
}
fbin.close();
}
print_speed(total_bytes, millis() - ms);
TB.esp32_end();
// reset ESP32 to run new firmware
TB.targetReset();
}
void loop() {
}

View file

@ -1,5 +1,5 @@
name=Adafruit TestBed name=Adafruit TestBed
version=1.14.2 version=1.10.0
author=Adafruit author=Adafruit
maintainer=Adafruit <info@adafruit.com> maintainer=Adafruit <info@adafruit.com>
sentence=Adafruit's internal test bed code library sentence=Adafruit's internal test bed code library

View file

@ -1,25 +1,10 @@
#include "Adafruit_TestBed.h" #include "Adafruit_TestBed.h"
// change to 1 to skip pre-flash md5 check for testing
#define SKIP_PRE_FLASH_MD5_CHECK 0
static inline uint32_t div_ceil(uint32_t v, uint32_t d) {
return (v + d - 1) / d;
}
Adafruit_TestBed::Adafruit_TestBed(void) { Adafruit_TestBed::Adafruit_TestBed(void) {
#if defined(ADAFRUIT_METRO_M0_EXPRESS) #if defined(ADAFRUIT_METRO_M0_EXPRESS)
neopixelPin = 40; neopixelPin = 40;
neopixelNum = 1; neopixelNum = 1;
#elif defined(ADAFRUIT_FEATHER_M0_EXPRESS)
neopixelPin = 8;
neopixelNum = 1;
#endif #endif
esp32boot = NULL;
_esp32_flash_defl = false;
_esp32_chip_detect = 0;
_esp32s3_in_reset = false;
} }
/**************************************************************************/ /**************************************************************************/
@ -48,11 +33,6 @@ void Adafruit_TestBed::begin(void) {
digitalWrite(ledPin, LOW); digitalWrite(ledPin, LOW);
} }
if (targetResetPin >= 0) {
pinMode(targetResetPin, OUTPUT);
digitalWrite(targetResetPin, HIGH);
}
#if defined(__AVR__) #if defined(__AVR__)
analogRef = 5.0; analogRef = 5.0;
#elif defined(ARDUINO_ARCH_RP2040) #elif defined(ARDUINO_ARCH_RP2040)
@ -170,23 +150,6 @@ void Adafruit_TestBed::targetPowerCycle(uint16_t off_time) {
targetPower(1); targetPower(1);
} }
void Adafruit_TestBed::targetReset(uint32_t reset_ms) {
digitalWrite(targetResetPin, LOW);
delay(reset_ms);
digitalWrite(targetResetPin, HIGH);
// Note: S3 has an USB-OTG errata
// https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf
// which is walkarounded by idf/arduino-esp32 to always mux JTAG to USB for
// uploading and/or power on. Afterwards USB-OTG will be set up if selected
// so. However rp2040 USBH is running too fast and can actually retrieve
// device/configuration descriptor of JTAG before the OTG is fully setup.
// Mark this for application usage
if (_esp32_chip_detect == CHIP_DETECT_MAGIC_ESP32S3) {
_esp32s3_in_reset = true;
}
}
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief Read the ADC on a pin and convert it to a voltage @brief Read the ADC on a pin and convert it to a voltage
@ -221,13 +184,11 @@ float Adafruit_TestBed::readAnalogVoltage(uint16_t pin, float multiplier) {
@param name Human readable name for the pin @param name Human readable name for the pin
@param multiplier If there's a resistor divider, put the inverse here @param multiplier If there's a resistor divider, put the inverse here
@param value What voltage the pin should be @param value What voltage the pin should be
@param error Percent of error permitted (10 is 10%)
@return True if the pin voltage is within 10% of target @return True if the pin voltage is within 10% of target
*/ */
/**************************************************************************/ /**************************************************************************/
bool Adafruit_TestBed::testAnalogVoltage(uint16_t pin, const char *name, bool Adafruit_TestBed::testAnalogVoltage(uint16_t pin, const char *name,
float multiplier, float value, float multiplier, float value) {
uint8_t error) {
float voltage = readAnalogVoltage(pin, multiplier); float voltage = readAnalogVoltage(pin, multiplier);
theSerial->print(name); theSerial->print(name);
theSerial->print(F(" output voltage: ")); theSerial->print(F(" output voltage: "));
@ -235,13 +196,11 @@ bool Adafruit_TestBed::testAnalogVoltage(uint16_t pin, const char *name,
theSerial->print(F(" V (should be ")); theSerial->print(F(" V (should be "));
theSerial->print(value); theSerial->print(value);
theSerial->print(" V)..."); theSerial->print(" V)...");
if (abs(voltage - value) > (value * error / 100.0)) { if (abs(voltage - value) > (value / 10.0)) {
theSerial->println("Failed"); theSerial->println("Failed");
return false; return false;
} }
theSerial->print(F("OK within ")); theSerial->println(F("OK within 10%"));
theSerial->print(error);
theSerial->println("%");
return true; return true;
} }
@ -455,203 +414,4 @@ void Adafruit_TestBed::beepNblink(void) {
#endif #endif
} }
/**************************************************************************/
/*!
@brief light the LED for 500ms, if defined
*/
/**************************************************************************/
void Adafruit_TestBed::blink(void) {
if (ledPin >= 0) {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
delay(500);
if (ledPin >= 0) {
digitalWrite(ledPin, LOW);
}
}
//--------------------------------------------------------------------+
// ESP32 Target
//--------------------------------------------------------------------+
bool Adafruit_TestBed::esp32_begin(ESP32BootROMClass *bootrom,
uint32_t baudrate) {
esp32boot = bootrom;
Serial.println("Syncing ESP32");
_esp32_chip_detect = esp32boot->begin(baudrate);
if (_esp32_chip_detect) {
setColor(0xFFFFFF);
Serial.println("Synced OK");
return true;
} else {
Serial.println("Sync failed!");
return false;
}
}
void Adafruit_TestBed::esp32_end(bool reset_esp) {
if (esp32boot->isRunningStub()) {
// skip sending flash_finish to ROM loader here,
// as it causes the loader to exit and run user code
esp32boot->beginFlash(0, 0, esp32boot->getFlashWriteSize());
if (_esp32_flash_defl) {
esp32boot->endFlashDefl(reset_esp);
} else {
esp32boot->endFlash(reset_esp);
}
}
esp32boot->end();
}
bool Adafruit_TestBed::esp32_s3_inReset(void) { return _esp32s3_in_reset; }
void Adafruit_TestBed::esp32_s3_clearReset(void) { _esp32s3_in_reset = false; }
static void print_buf(uint8_t const *buf, size_t len) {
for (size_t i = 0; i < len; i++) {
Serial.print(buf[i], HEX);
}
Serial.println();
}
size_t
Adafruit_TestBed::_esp32_programFlashDefl_impl(const esp32_zipfile_t *zfile,
uint32_t addr, File32 *fsrc) {
if (!esp32boot) {
return 0;
}
// Check if MD5 matches to skip this file
uint8_t esp_md5[16];
#if !SKIP_PRE_FLASH_MD5_CHECK
esp32boot->md5Flash(addr, zfile->uncompressed_len, esp_md5);
Serial.print("Flash MD5: ");
print_buf(esp_md5, 16);
if (0 == memcmp(zfile->md5, esp_md5, 16)) {
Serial.println("MD5 matched");
return zfile->uncompressed_len;
}
#endif
// Write Size is different depending on ROM (1K) or Stub (16KB)
uint32_t const block_size = esp32boot->getFlashWriteSize();
uint8_t *buf = NULL;
bool const use_sdcard = (fsrc != NULL);
if (use_sdcard) {
buf = (uint8_t *)malloc(block_size);
if (!buf) {
Serial.print("No memory ");
Serial.println(block_size);
return 0;
}
}
Serial.print("Compressed ");
Serial.print(zfile->uncompressed_len);
Serial.print(" bytes to ");
Serial.println(zfile->compressed_len);
if (!esp32boot->beginFlashDefl(addr, zfile->uncompressed_len,
zfile->compressed_len)) {
Serial.println("beginFlash failed!");
if (buf) {
free(buf);
}
return 0;
}
_esp32_flash_defl = true;
//------------- Flashing -------------//
uint32_t written = 0;
uint32_t const block_num = div_ceil(zfile->compressed_len, block_size);
for (uint32_t i = 0; i < block_num; i++) {
setLED(HIGH);
// Serial.print("Pckt %lu/%lu", i + 1, block_num);
Serial.print("Packet ");
Serial.print(i + 1);
Serial.print("/");
Serial.println(block_num);
uint32_t const remain = zfile->compressed_len - written;
uint32_t const wr_count = (remain < block_size) ? remain : block_size;
uint8_t const *data;
if (!use_sdcard) {
// file contents is stored in internal flash (e.g rp2040)
data = zfile->data + written;
} else {
// file contents is stored in sdcard
memset(buf, 0xff, block_size); // empty it out
if (wr_count != fsrc->read(buf, wr_count)) {
Serial.println("File contents does not matched with compressed_len");
free(buf);
return 0;
}
data = buf;
}
// Note: flash deflat does not need padding
if (!esp32boot->dataFlashDefl(data, wr_count)) {
Serial.println("Failed to flash");
break;
}
written += wr_count;
setLED(LOW);
}
Serial.println();
// Stub only writes each block to flash after 'ack'ing the receive,
// so do a final dummy operation which will not be 'ack'ed
// until the last block has actually been written out to flash
if (esp32boot->isRunningStub()) {
Serial.println("Dummy read chip detect after final block");
(void)esp32boot->read_chip_detect();
}
//------------- MD5 verification -------------//
Serial.println("Verifying MD5");
esp32boot->md5Flash(addr, zfile->uncompressed_len, esp_md5);
if (0 == memcmp(zfile->md5, esp_md5, 16)) {
Serial.println("MD5 matched");
} else {
Serial.println("MD5 mismatched!!");
Serial.print("File: ");
print_buf(zfile->md5, 16);
Serial.print("ESP : ");
print_buf(esp_md5, 16);
}
if (buf) {
free(buf);
}
return zfile->uncompressed_len;
}
size_t Adafruit_TestBed::esp32_programFlashDefl(const esp32_zipfile_t *zfile,
uint32_t addr) {
return _esp32_programFlashDefl_impl(zfile, addr, NULL);
}
size_t Adafruit_TestBed::esp32_programFlashDefl(const esp32_zipfile_t *zfile,
uint32_t addr, File32 *fsrc) {
return _esp32_programFlashDefl_impl(zfile, addr, fsrc);
}
Adafruit_TestBed TB; Adafruit_TestBed TB;

View file

@ -5,9 +5,6 @@
#include "Arduino.h" #include "Arduino.h"
#include "Wire.h" #include "Wire.h"
#include "ESP32BootROM.h"
#include "SdFat_Adafruit_Fork.h"
#define RED 0xFF0000 #define RED 0xFF0000
#define YELLOW 0xFFFF00 #define YELLOW 0xFFFF00
#define GREEN 0x00FF00 #define GREEN 0x00FF00
@ -16,14 +13,6 @@
#define PURPLE 0xFF00FF #define PURPLE 0xFF00FF
#define WHITE 0xFFFFFF #define WHITE 0xFFFFFF
typedef struct {
const char *name;
const uint8_t *data;
const uint32_t compressed_len;
const uint32_t uncompressed_len;
const uint8_t md5[16];
} esp32_zipfile_t;
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief A helper class for making test beds and functions. Lots of handy lil @brief A helper class for making test beds and functions. Lots of handy lil
@ -44,11 +33,9 @@ public:
void targetPower(bool on); void targetPower(bool on);
void targetPowerCycle(uint16_t off_time = 10); void targetPowerCycle(uint16_t off_time = 10);
void targetReset(uint32_t reset_ms = 20);
float readAnalogVoltage(uint16_t pin, float multiplier = 1); float readAnalogVoltage(uint16_t pin, float multiplier = 1);
bool testAnalogVoltage(uint16_t pin, const char *name, float multiplier, bool testAnalogVoltage(uint16_t pin, const char *name, float multiplier,
float value, uint8_t error = 10); float value);
bool testpins(uint8_t a, uint8_t b, uint8_t *allpins, uint8_t num_allpins); bool testpins(uint8_t a, uint8_t b, uint8_t *allpins, uint8_t num_allpins);
@ -59,29 +46,10 @@ public:
void beep(uint32_t freq, uint32_t duration); void beep(uint32_t freq, uint32_t duration);
void beepNblink(void); void beepNblink(void);
void blink(void);
uint32_t timestamp(void); uint32_t timestamp(void);
void printTimeTaken(bool restamp = false); void printTimeTaken(bool restamp = false);
//--------------------------------------------------------------------+
// ESP32 Target
//--------------------------------------------------------------------+
bool esp32_begin(ESP32BootROMClass *bootrom, uint32_t baudrate);
void esp32_end(bool reset_esp = false);
// program esp32 target with compressed data stored in internal flash
size_t esp32_programFlashDefl(const esp32_zipfile_t *zfile, uint32_t addr);
// program esp32 target with compressed file from SDCard
size_t esp32_programFlashDefl(const esp32_zipfile_t *zfile, uint32_t addr,
File32 *fsrc);
bool esp32_s3_inReset(void);
void esp32_s3_clearReset(void);
ESP32BootROMClass *esp32boot; // ESP32 ROM
////////////////// //////////////////
TwoWire *theWire = &Wire; ///< The I2C port used in scanning TwoWire *theWire = &Wire; ///< The I2C port used in scanning
Stream *theSerial = &Serial; ///< The Serial port used for debugging Stream *theSerial = &Serial; ///< The Serial port used for debugging
@ -92,8 +60,6 @@ public:
int16_t targetPowerPin = -1; ///< Set to a target power pin if used int16_t targetPowerPin = -1; ///< Set to a target power pin if used
bool targetPowerPolarity = HIGH; ///< What to set the power pin to, for ON bool targetPowerPolarity = HIGH; ///< What to set the power pin to, for ON
int targetResetPin = -1; ///< Set to target reset pin if used
int16_t neopixelPin = -1; ///< The neopixel connected pin if any int16_t neopixelPin = -1; ///< The neopixel connected pin if any
uint8_t neopixelNum = 0; ///< How many neopixels are on board, if any uint8_t neopixelNum = 0; ///< How many neopixels are on board, if any
Adafruit_NeoPixel *pixels = Adafruit_NeoPixel *pixels =
@ -104,15 +70,6 @@ public:
private: private:
uint32_t millis_timestamp = 0; ///< A general purpose timestamp uint32_t millis_timestamp = 0; ///< A general purpose timestamp
bool _esp32_flash_defl;
uint32_t _esp32_chip_detect;
bool _esp32s3_in_reset;
size_t _esp32_programFlashDefl_impl(const esp32_zipfile_t *zfile,
uint32_t addr, File32 *fsrc);
}; };
extern Adafruit_TestBed TB;
#endif #endif

View file

@ -22,9 +22,9 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifdef ARDUINO_ARCH_RP2040 #ifdef ARDUINO_RASPBERRY_PI_PICO
#include "SdFat_Adafruit_Fork.h" #include "SdFat.h"
#include "pio_usb.h" #include "pio_usb.h"
#include "Adafruit_DAP.h" #include "Adafruit_DAP.h"
@ -34,12 +34,6 @@
#define USBHOST_RHPORT 1 #define USBHOST_RHPORT 1
// Workaround force F_CPU to 240MHz for programming RP2350 due to handshake
// timeout
#if F_CPU != 120000000L && F_CPU != 240000000L
#error "F_CPU must be set to either 120Mhz or 240Mhz for pio-usb host"
#endif
Adafruit_TestBed_Brains Brain; Adafruit_TestBed_Brains Brain;
volatile bool LCD_semaphore = false; volatile bool LCD_semaphore = false;
@ -71,6 +65,10 @@ private:
uint32_t crc; uint32_t crc;
}; };
static inline uint32_t div_ceil(uint32_t v, uint32_t d) {
return (v + d - 1) / d;
}
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief Initializer, sets up the timestamp, neopixels, piezo, led, @brief Initializer, sets up the timestamp, neopixels, piezo, led,
@ -96,11 +94,16 @@ Adafruit_TestBed_Brains::Adafruit_TestBed_Brains() {
_usbh_dp_pin = 20; // USB Host D+ _usbh_dp_pin = 20; // USB Host D+
_vbus_en_pin = 22; // USB Host VBus enable _vbus_en_pin = 22; // USB Host VBus enable
targetResetPin = 27; _target_rst = 27;
_target_swdio = 2; _target_swdio = 2;
_target_swdclk = 3; _target_swdclk = 3;
dap = NULL; dap = NULL;
esp32boot = NULL;
_esp32_flash_defl = false;
_esp32_chip_detect = 0;
_esp32s3_in_reset = false;
} }
void Adafruit_TestBed_Brains::begin(void) { void Adafruit_TestBed_Brains::begin(void) {
@ -112,8 +115,8 @@ void Adafruit_TestBed_Brains::begin(void) {
neopixelNum = 1; neopixelNum = 1;
pinMode(neopixelPin, OUTPUT); pinMode(neopixelPin, OUTPUT);
pinMode(targetResetPin, OUTPUT); pinMode(_target_rst, OUTPUT);
digitalWrite(targetResetPin, HIGH); digitalWrite(_target_rst, HIGH);
pinMode(_sd_detect_pin, INPUT_PULLUP); pinMode(_sd_detect_pin, INPUT_PULLUP);
pinMode(_vbus_en_pin, OUTPUT); pinMode(_vbus_en_pin, OUTPUT);
@ -135,13 +138,31 @@ void Adafruit_TestBed_Brains::begin(void) {
bool Adafruit_TestBed_Brains::inited(void) { return _inited; } bool Adafruit_TestBed_Brains::inited(void) { return _inited; }
void Adafruit_TestBed_Brains::targetReset(uint32_t reset_ms) {
digitalWrite(_target_rst, LOW);
delay(reset_ms);
digitalWrite(_target_rst, HIGH);
// Note: S3 has an USB-OTG errata
// https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf
// which is walkarounded by idf/arduino-esp32 to always mux JTAG to USB for
// uploading and/or power on. Afterwards USB-OTG will be set up if selected
// so. However rp2040 USBH is running too fast and can actually retrieve
// device/configuration descriptor of JTAG before the OTG is fully setup.
// Mark this for application usage
if (_esp32_chip_detect == CHIP_DETECT_MAGIC_ESP32S3) {
_esp32s3_in_reset = true;
}
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// RP2040 Target // RP2040 Target
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void Adafruit_TestBed_Brains::rp2_targetResetBootRom(int bootsel_pin, void Adafruit_TestBed_Brains::rp2040_targetResetBootRom(int bootsel_pin,
uint32_t reset_ms) { uint32_t reset_ms) {
pinMode(bootsel_pin, OUTPUT); pinMode(bootsel_pin, OUTPUT);
digitalWrite(bootsel_pin, LOW); digitalWrite(bootsel_pin, LOW);
targetReset(reset_ms); targetReset(reset_ms);
@ -152,41 +173,7 @@ void Adafruit_TestBed_Brains::rp2_targetResetBootRom(int bootsel_pin,
pinMode(bootsel_pin, INPUT); pinMode(bootsel_pin, INPUT);
} }
size_t Adafruit_TestBed_Brains::rp2_programUF2(const uint8_t *buffer, size_t Adafruit_TestBed_Brains::rp2040_programUF2(const char *fpath) {
size_t bufsize) {
size_t copied_bytes = 0;
const char *dst_name = "FIRMWARE.UF2";
File32 fdst = USBH_FS.open(dst_name, O_WRONLY | O_CREAT);
if (!fdst) {
Serial.printf("USBH_FS: cannot create file: %s\r\n", dst_name);
} else {
while (copied_bytes < bufsize) {
size_t count = bufsize - copied_bytes;
if (count > 4096) {
count = 4096; // write 1 sector each
}
setLED(HIGH);
size_t wr_count = fdst.write(buffer, count);
setLED(LOW);
buffer += wr_count;
copied_bytes += wr_count;
if (wr_count != count) {
Serial.println("USBH_FS: Failed to write file");
break;
}
}
}
fdst.close();
return copied_bytes;
}
size_t Adafruit_TestBed_Brains::rp2_programUF2(const char *fpath) {
File32 fsrc = SD.open(fpath); File32 fsrc = SD.open(fpath);
if (!fsrc) { if (!fsrc) {
Serial.printf("SD: cannot open file: %s\r\n", fpath); Serial.printf("SD: cannot open file: %s\r\n", fpath);
@ -194,6 +181,7 @@ size_t Adafruit_TestBed_Brains::rp2_programUF2(const char *fpath) {
} }
size_t copied_bytes = 0; size_t copied_bytes = 0;
const char *dst_name = "FIRMWARE.UF2"; const char *dst_name = "FIRMWARE.UF2";
File32 fdst = USBH_FS.open(dst_name, O_WRONLY | O_CREAT); File32 fdst = USBH_FS.open(dst_name, O_WRONLY | O_CREAT);
@ -252,17 +240,17 @@ bool Adafruit_TestBed_Brains::dap_begin(Adafruit_DAP *dp) {
dap = dp; dap = dp;
return dap->begin(_target_swdclk, _target_swdio, targetResetPin, return dap->begin(_target_swdclk, _target_swdio, _target_rst,
dap_err_hanlder); dap_err_hanlder);
} }
bool Adafruit_TestBed_Brains::dap_connect(uint32_t swj_clock) { bool Adafruit_TestBed_Brains::dap_connect(void) {
if (!dap) { if (!dap) {
return false; return false;
} }
LCD_printf("Connecting..."); LCD_printf("Connecting...");
if (!dap->targetConnect(swj_clock)) { if (!dap->targetConnect()) {
return false; return false;
} }
@ -272,6 +260,10 @@ bool Adafruit_TestBed_Brains::dap_connect(uint32_t swj_clock) {
LCD_printf(0, "Unknown MCU"); LCD_printf(0, "Unknown MCU");
LCD_printf(1, "ID = %08X", dsu_did); LCD_printf(1, "ID = %08X", dsu_did);
while (1) {
delay(1);
}
return false; return false;
} }
@ -301,9 +293,9 @@ bool Adafruit_TestBed_Brains::dap_unprotectBoot(void) {
return false; return false;
} }
Serial.println("Unlock chip..."); LCD_printf("Unlock chip...");
bool ret = dap->unprotectBoot(); bool ret = dap->unprotectBoot();
Serial.println(ret ? "OK" : "Failed"); LCD_printf(ret ? "OK" : "Failed");
return ret; return ret;
} }
@ -312,9 +304,9 @@ bool Adafruit_TestBed_Brains::dap_protectBoot(void) {
return false; return false;
} }
Serial.println("Lock chip..."); LCD_printf("Lock chip...");
bool ret = dap->protectBoot(); bool ret = dap->protectBoot();
Serial.println(ret ? "OK" : "Failed"); LCD_printf(ret ? "OK" : "Failed");
return ret; return ret;
} }
@ -335,15 +327,14 @@ bool Adafruit_TestBed_Brains::dap_eraseChip(void) {
dap->erase(); dap->erase();
ms = millis() - ms; ms = millis() - ms;
LCD_printf("Erased in %.02fs", ms / 1000.0F); LCD_printf("done in %.02fs", ms / 1000.0F);
} }
return true; return true;
} }
size_t Adafruit_TestBed_Brains::dap_programFlash(const char *fpath, size_t Adafruit_TestBed_Brains::dap_programFlash(const char *fpath,
uint32_t addr, bool do_verify, uint32_t addr) {
bool do_crc32) {
if (!dap) { if (!dap) {
return 0; return 0;
} }
@ -386,8 +377,7 @@ size_t Adafruit_TestBed_Brains::dap_programFlash(const char *fpath,
return 0; return 0;
} }
LCD_printf("Programming..."); LCD_printf("Programming..");
uint32_t ms = millis();
BrainCRC32 crc32; BrainCRC32 crc32;
dap->program_start(addr, fsize); dap->program_start(addr, fsize);
@ -395,42 +385,22 @@ size_t Adafruit_TestBed_Brains::dap_programFlash(const char *fpath,
uint32_t addr_tmp = addr; uint32_t addr_tmp = addr;
while (fsrc.available()) { while (fsrc.available()) {
memset(buf, 0xff, bufsize); // empty it out memset(buf, 0xff, bufsize); // empty it out
uint32_t rd_count = fsrc.read(buf, bufsize); uint32_t rd_count = fsrc.read(buf, bufsize);
setLED(HIGH); setLED(HIGH);
dap->programBlock(addr_tmp, buf, bufsize);
// don't verify each write if we use crc32
if (!dap->programFlash(addr_tmp, buf, bufsize, !do_crc32 && do_verify)) {
Serial.printf("Failed to program block at %08lX\n", addr_tmp);
free(buf);
fsrc.close();
return addr_tmp - addr;
}
if (do_crc32) {
crc32.add(buf, rd_count); crc32.add(buf, rd_count);
} setLED(LOW);
addr_tmp += bufsize; addr_tmp += bufsize;
setLED(LOW);
} }
Serial.printf("Programming end, t = %lu ms\r\n", millis(), millis() - ms);
if (do_crc32) {
ms = millis();
Serial.printf("CRC32 start\r\n", ms);
uint32_t target_crc = dap->computeFlashCRC32(addr, fsize); uint32_t target_crc = dap->computeFlashCRC32(addr, fsize);
Serial.printf("CRC32 end, t = %lu ms\r\n", millis(), millis() - ms);
if (target_crc != crc32.get()) { if (target_crc != crc32.get()) {
LCD_printf("CRC Failed"); LCD_printf("CRC Failed");
Serial.printf("CRC mismtached: %08lX != %08lX\n", crc32.get(), Serial.printf("CRC mismtached: %08lX != %08lX\n", crc32.get(), target_crc);
target_crc);
} else {
LCD_printf("Done!");
}
} else { } else {
LCD_printf("Done!"); LCD_printf("Done!");
} }
@ -441,47 +411,237 @@ size_t Adafruit_TestBed_Brains::dap_programFlash(const char *fpath,
return fsize; return fsize;
} }
size_t Adafruit_TestBed_Brains::dap_readFlash(const char *fpath, uint32_t addr, //--------------------------------------------------------------------+
size_t size) { // ESP32 Target
if (!dap) { //--------------------------------------------------------------------+
bool Adafruit_TestBed_Brains::esp32_begin(ESP32BootROMClass *bootrom,
uint32_t baudrate) {
esp32boot = bootrom;
LCD_printf("Syncing ESP32");
_esp32_chip_detect = esp32boot->begin(baudrate);
if (_esp32_chip_detect) {
setColor(0xFFFFFF);
LCD_printf("Synced OK");
return true;
} else {
LCD_printf_error("Sync failed!");
return false;
}
}
void Adafruit_TestBed_Brains::esp32_end(bool reset_esp) {
if (esp32boot->isRunningStub()) {
// skip sending flash_finish to ROM loader here,
// as it causes the loader to exit and run user code
esp32boot->beginFlash(0, 0, esp32boot->getFlashWriteSize());
if (_esp32_flash_defl) {
esp32boot->endFlashDefl(reset_esp);
} else {
esp32boot->endFlash(reset_esp);
}
}
esp32boot->end();
}
bool Adafruit_TestBed_Brains::esp32_s3_inReset(void) {
return _esp32s3_in_reset;
}
void Adafruit_TestBed_Brains::esp32_s3_clearReset(void) {
_esp32s3_in_reset = false;
}
size_t
Adafruit_TestBed_Brains::esp32_programFlashDefl(const esp32_zipfile_t *zfile,
uint32_t addr) {
if (!esp32boot) {
return 0; return 0;
} }
size_t bufsize = 4096; // Check if MD5 matches to skip this file
uint8_t *buf = (uint8_t *)malloc(bufsize); uint8_t esp_md5[16];
#if 1 // change to 0 to skip pre-flash md5 check for testing
esp32boot->md5Flash(addr, zfile->uncompressed_len, esp_md5);
Serial.printf("Flash MD5: ");
for (size_t i = 0; i < 16; i++) {
Serial.printf("%02X ", esp_md5[i]);
}
Serial.println();
if (0 == memcmp(zfile->md5, esp_md5, 16)) {
LCD_printf(2, "MD5 matched");
return zfile->uncompressed_len;
}
#endif
// Write Size is different depending on ROM (1K) or Stub (16KB)
uint32_t const block_size = esp32boot->getFlashWriteSize();
Serial.printf("Compressed %lu bytes to %lu\r\n", zfile->uncompressed_len,
zfile->compressed_len);
if (!esp32boot->beginFlashDefl(addr, zfile->uncompressed_len,
zfile->compressed_len)) {
LCD_printf_error("beginFlash failed!");
} else {
_esp32_flash_defl = true;
uint32_t const block_num = div_ceil(zfile->compressed_len, block_size);
//------------- Flashing -------------//
uint8_t const *data = zfile->data;
uint32_t remain = zfile->compressed_len;
for (uint32_t i = 0; i < block_num; i++) {
setLED(HIGH);
LCD_printf(1, "Pckt %u/%u", i + 1, block_num);
uint32_t const wr_count = MIN(block_size, remain);
// Note: flash deflat does not need padding
if (!esp32boot->dataFlashDefl(data, wr_count)) {
LCD_printf_error("Failed to flash");
break;
}
setLED(LOW);
data += wr_count;
remain -= wr_count;
}
Serial.println();
// Stub only writes each block to flash after 'ack'ing the receive,
// so do a final dummy operation which will not be 'ack'ed
// until the last block has actually been written out to flash
if (esp32boot->isRunningStub()) {
Serial.println("Dummy read chip detect after final block");
(void)esp32boot->read_chip_detect();
}
//------------- MD5 verification -------------//
Serial.println("Verifying MD5");
esp32boot->md5Flash(addr, zfile->uncompressed_len, esp_md5);
if (0 == memcmp(zfile->md5, esp_md5, 16)) {
LCD_printf(2, "MD5 matched");
} else {
LCD_error(NULL, "MD5 mismatched!!");
Serial.printf("File: ");
for (size_t i = 0; i < 16; i++) {
Serial.printf("%02X ", zfile->md5[i]);
}
Serial.println();
Serial.printf("ESP : ");
for (size_t i = 0; i < 16; i++) {
Serial.printf("%02X ", esp_md5[i]);
}
Serial.println();
}
}
return zfile->uncompressed_len;
}
size_t Adafruit_TestBed_Brains::esp32_programFlash(const char *fpath,
uint32_t addr) {
if (!esp32boot) {
return 0;
}
// Write Size is different depending on ROM (1K) or Stub (16KB)
uint32_t const block_size = esp32boot->getFlashWriteSize();
uint8_t *buf = (uint8_t *)malloc(block_size);
if (!buf) { if (!buf) {
LCD_printf_error("No memory %u\n", block_size);
return 0; return 0;
} }
File32 fsrc = SD.open(fpath, O_CREAT | O_WRONLY); File32 fsrc = SD.open(fpath);
if (!fsrc) { if (!fsrc) {
Serial.printf("SD: cannot open file: %s\r\n", fpath); Serial.printf("SD: cannot open file: %s\r\n", fpath);
return 0; return 0;
} }
uint32_t fsize = fsrc.fileSize();
uint32_t total_count = 0;
LCD_printf("Reading..."); Serial.printf("fsize = %lu, block size = %lu\r\n", fsize, block_size);
size_t remain = size; if (!esp32boot->beginFlash(addr, fsize, block_size)) {
while (remain) { LCD_printf_error("beginFlash failed!");
uint32_t count = min(remain, bufsize); } else {
LCD_printf("#Packets %u", div_ceil(fsize, block_size));
MD5Builder md5;
md5.begin();
//------------- Flashing -------------//
while (fsrc.available()) {
memset(buf, 0xff, block_size); // empty it out
uint32_t const rd_count = fsrc.read(buf, block_size);
setLED(HIGH); setLED(HIGH);
if (!dap->dap_read_block(addr, buf, (int)count)) { Serial.printf("#");
Serial.printf("Failed to read block at %08lX\n", addr);
if (!esp32boot->dataFlash(buf, block_size)) {
LCD_printf_error("Failed to flash");
break; break;
} }
setLED(LOW); setLED(LOW);
fsrc.write(buf, count); md5.add(buf, rd_count);
LCD_printf("%d remaining", remain); total_count += rd_count;
addr += count; }
remain -= count; Serial.println();
// Stub only writes each block to flash after 'ack'ing the receive,
// so do a final dummy operation which will not be 'ack'ed
// until the last block has actually been written out to flash
if (esp32boot->isRunningStub()) {
(void)esp32boot->read_chip_detect();
} }
fsrc.close(); //------------- MD5 verification -------------//
LCD_printf("Done!"); md5.calculate();
Serial.printf("md5 = %s\r\n", md5.toString().c_str());
return size - remain; uint8_t file_md5[16];
md5.getBytes(file_md5);
uint8_t esp_md5[16];
esp32boot->md5Flash(addr, fsize, esp_md5);
if (0 == memcmp(file_md5, esp_md5, 16)) {
LCD_printf("MD5 matched");
} else {
LCD_printf_error("MD5 mismatched!!");
Serial.printf("File: ");
for (size_t i = 0; i < 16; i++) {
Serial.printf("%02X ", file_md5[i]);
}
Serial.println();
Serial.printf("ESP : ");
for (size_t i = 0; i < 16; i++) {
Serial.printf("%02X ", esp_md5[i]);
}
Serial.println();
}
}
free(buf);
fsrc.close();
return total_count;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -514,209 +674,6 @@ bool Adafruit_TestBed_Brains::SD_begin(uint32_t max_clock) {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// LCD // LCD
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define NOP1 __asm volatile("nop");
#define NOP2 NOP1 NOP1
#define NOP3 NOP2 NOP1
#define NOP4 NOP2 NOP2
#define NOP5 NOP4 NOP1
#define NOP6 NOP4 NOP2
#define NOP7 NOP4 NOP3
#define NOP8 NOP4 NOP4
#define NOP9 NOP8 NOP1
#define NOP10 NOP8 NOP2
#define NOP11 NOP8 NOP3
#define NOP12 NOP8 NOP4
#define NOP13 NOP8 NOP5
#define NOP14 NOP8 NOP6
#define NOP15 NOP8 NOP7
#define NOP16 NOP8 NOP8
#define NOP17 NOP16 NOP1
#define NOP18 NOP16 NOP2
#define NOP19 NOP16 NOP3
#define NOP20 NOP16 NOP4
#define NOP21 NOP16 NOP5
#define NOP22 NOP16 NOP6
#define NOP23 NOP16 NOP7
#define NOP24 NOP16 NOP8
#define NOP25 NOP16 NOP9
#define NOP26 NOP16 NOP10
#define NOP27 NOP16 NOP11
#define NOP28 NOP16 NOP12
#define NOP29 NOP16 NOP13
#define NOP30 NOP16 NOP14
#define NOP31 NOP16 NOP15
#define NOP32 NOP16 NOP16
#define NOP33 NOP32 NOP1
#define NOP34 NOP32 NOP2
#define NOP35 NOP32 NOP3
#define NOP36 NOP32 NOP4
#define NOP37 NOP32 NOP5
#define NOP38 NOP32 NOP6
#define NOP39 NOP32 NOP7
#define NOP40 NOP32 NOP8
#define NOP41 NOP32 NOP9
#define NOP42 NOP32 NOP10
#define NOP43 NOP32 NOP11
#define NOP44 NOP32 NOP12
#define NOP45 NOP32 NOP13
#define NOP46 NOP32 NOP14
#define NOP47 NOP32 NOP15
#define NOP48 NOP32 NOP16
#define NOP49 NOP48 NOP1
#define NOP50 NOP48 NOP2
#define NOP51 NOP48 NOP3
#define NOP52 NOP48 NOP4
#define NOP53 NOP48 NOP5
#define NOP54 NOP48 NOP6
#define NOP55 NOP48 NOP7
#define NOP56 NOP48 NOP8
#define NOP57 NOP48 NOP9
#define NOP58 NOP48 NOP10
#define NOP59 NOP48 NOP11
#define NOP60 NOP48 NOP12
#define NOP61 NOP48 NOP13
#define NOP62 NOP48 NOP14
#define NOP63 NOP48 NOP15
#define NOP64 NOP48 NOP16
#define NOP65 NOP64 NOP1
#define NOP66 NOP64 NOP2
#define NOP67 NOP64 NOP3
#define NOP68 NOP64 NOP4
#define NOP69 NOP64 NOP5
#define NOP70 NOP64 NOP6
#define NOP71 NOP64 NOP7
#define NOP72 NOP64 NOP8
#define NOP73 NOP64 NOP9
#define NOP74 NOP64 NOP10
#define NOP75 NOP64 NOP11
#define NOP76 NOP64 NOP12
#define NOP77 NOP64 NOP13
#define NOP78 NOP64 NOP14
#define NOP79 NOP64 NOP15
#define NOP80 NOP64 NOP16
#define NOP81 NOP80 NOP1
#define NOP82 NOP80 NOP2
#define NOP83 NOP80 NOP3
#define NOP84 NOP80 NOP4
#define NOP85 NOP80 NOP5
#define NOP86 NOP80 NOP6
#define NOP87 NOP80 NOP7
#define NOP88 NOP80 NOP8
#define NOP89 NOP80 NOP9
#define NOP90 NOP80 NOP10
#define NOP91 NOP80 NOP11
#define NOP92 NOP80 NOP12
#define NOP93 NOP80 NOP13
#define NOP94 NOP80 NOP14
#define NOP95 NOP80 NOP15
#define NOP96 NOP80 NOP16
#define NOP97 NOP96 NOP1
#define NOP98 NOP96 NOP2
#define NOP99 NOP96 NOP3
#define NOP100 NOP96 NOP4
#define NOP101 NOP100 NOP1
#define NOP102 NOP100 NOP2
#define NOP103 NOP100 NOP3
#define NOP104 NOP100 NOP4
#define NOP105 NOP100 NOP5
#define NOP106 NOP100 NOP6
#define NOP107 NOP100 NOP7
#define NOP108 NOP100 NOP8
#define NOP109 NOP100 NOP9
#define NOP110 NOP100 NOP10
#define NOP111 NOP100 NOP11
#define NOP112 NOP100 NOP12
#define NOP113 NOP100 NOP13
#define NOP114 NOP100 NOP14
#define NOP115 NOP100 NOP15
#define NOP116 NOP100 NOP16
#define NOP117 NOP116 NOP1
#define NOP118 NOP116 NOP2
#define NOP119 NOP116 NOP3
#define NOP120 NOP116 NOP4
#define NOP121 NOP116 NOP5
#define NOP122 NOP116 NOP6
#define NOP123 NOP116 NOP7
#define NOP124 NOP116 NOP8
#define NOP125 NOP116 NOP9
#define NOP126 NOP116 NOP10
#define NOP127 NOP116 NOP11
#define NOP128 NOP116 NOP12
#define NOP129 NOP128 NOP1
#define NOP130 NOP128 NOP2
#define NOP131 NOP128 NOP3
#define NOP132 NOP128 NOP4
#define NOP133 NOP128 NOP5
#define NOP134 NOP128 NOP6
#define NOP135 NOP128 NOP7
#define NOP136 NOP128 NOP8
#define NOP137 NOP128 NOP9
#define NOP138 NOP128 NOP10
#define NOP139 NOP128 NOP11
#define NOP140 NOP128 NOP12
#define NOP141 NOP128 NOP13
#define NOP142 NOP128 NOP14
#define NOP143 NOP128 NOP15
#define NOP144 NOP128 NOP16
#define NOP145 NOP144 NOP1
#define NOP146 NOP144 NOP2
#define NOP147 NOP144 NOP3
#define NOP148 NOP144 NOP4
#define NOP149 NOP144 NOP5
#define NOP150 NOP144 NOP6
#define NOP151 NOP144 NOP7
#define NOP152 NOP144 NOP8
#define NOP153 NOP144 NOP9
#define NOP154 NOP144 NOP10
#define NOP155 NOP144 NOP11
#define NOP156 NOP144 NOP12
#define NOP157 NOP144 NOP13
#define NOP158 NOP144 NOP14
#define NOP159 NOP144 NOP15
#define NOP160 NOP144 NOP16
#define NOP161 NOP160 NOP1
#define NOP162 NOP160 NOP2
#define NOP163 NOP160 NOP3
#define NOP164 NOP160 NOP4
#define NOP165 NOP160 NOP5
#define NOP166 NOP160 NOP6
#define NOP167 NOP160 NOP7
#define NOP168 NOP160 NOP8
#define NOP169 NOP160 NOP9
#define NOP170 NOP160 NOP10
#define NOP171 NOP160 NOP11
#define NOP172 NOP160 NOP12
#define NOP173 NOP160 NOP13
#define NOP174 NOP160 NOP14
#define NOP175 NOP160 NOP15
#define NOP176 NOP160 NOP16
#define NOP177 NOP176 NOP1
#define NOP178 NOP176 NOP2
#define NOP179 NOP176 NOP3
#define NOP180 NOP176 NOP4
#define NOP181 NOP176 NOP5
#define NOP182 NOP176 NOP6
#define NOP183 NOP176 NOP7
#define NOP184 NOP176 NOP8
#define NOP185 NOP176 NOP9
#define NOP186 NOP176 NOP10
#define NOP187 NOP176 NOP11
#define NOP188 NOP176 NOP12
#define NOP189 NOP176 NOP13
#define NOP190 NOP176 NOP14
#define NOP191 NOP176 NOP15
#define NOP192 NOP176 NOP16
#define NOP193 NOP192 NOP1
#define NOP194 NOP192 NOP2
#define NOP195 NOP192 NOP3
#define NOP196 NOP192 NOP4
#define NOP197 NOP192 NOP5
#define NOP198 NOP192 NOP6
#define NOP199 NOP192 NOP7
#define NOP200 NOP192 NOP8
#define _NOP_COUNT(n) NOP##n
#define NOP_COUNT(n) _NOP_COUNT(n)
void __no_inline_not_in_flash_func(Adafruit_TestBed_Brains::setColor)( void __no_inline_not_in_flash_func(Adafruit_TestBed_Brains::setColor)(
uint32_t color) { uint32_t color) {
@ -757,69 +714,53 @@ void __no_inline_not_in_flash_func(Adafruit_TestBed_Brains::setColor)(
uint32_t const isr_context = save_and_disable_interrupts(); uint32_t const isr_context = save_and_disable_interrupts();
/* Neopixel is 800 KHz, 1T = 1.25 us = 150 nop (120Mhz), 300 nop (240Mhz) // RP2040 is 120 MHz, 120 cycle = 1us = 1000 ns
- T1H = 0.8 us, T1L = 0.45 us // Neopixel is 800 KHz, 1T = 1.25 us = 150 nop
- T0H = 0.4 us, T0L = 0.85 us
If F_CPU is 120 MHz: 120 nop = 1us -> 1 nop = 8.33 ns
- T1H = 0.8 us = 96 nop, T1L = 0.45 us = 54 nop
- T0H = 0.4 us = 48 nop, T0L = 0.85 us = 102 nop
If F_CPU is 240 MHz: 240 nop = 1us -> 1 nop = 4.17 ns
- T1H = 0.8 us = 192 nop, T1L = 0.45 us = 108 nop
- T0H = 0.4 us = 96 nop, T0L = 0.85 us = 204 nop
Due to overhead the number of NOP is actually smaller, also M33 run faster
(higher IPC) therefore these are hand tuned,
*/
#if defined(ARDUINO_RASPBERRY_PI_PICO)
// value for rp2040 at 120MHz
#define T1H_CYCLE 90
#define T1L_CYCLE 39
#define T0H_CYCLE 42
#define T0L_CYCLE 84
#define LOOP_OVERHEAD_CYCLE 10 // overhead for if/else and loop
#elif defined(ARDUINO_RASPBERRY_PI_PICO_2)
// value for rp2350 at 120MHz
#define T1H_CYCLE 190
#define T1L_CYCLE 90
#define T0H_CYCLE 88
#define T0L_CYCLE 180
#define LOOP_OVERHEAD_CYCLE 5
#endif
while (1) { while (1) {
if (p & bitMask) { if (p & bitMask) {
// T1H 0.8 us = 96 nop (without overhead) // T1H 0,8 us = 96 - 1 = 95 nop
sio_hw->gpio_set = pinMask; sio_hw->gpio_set = pinMask;
NOP_COUNT(T1H_CYCLE); __asm volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#if F_CPU == 240000000L "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
NOP_COUNT(T1H_CYCLE); "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#endif "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;");
// T1L 0.45 = 54 - 10 (ifelse) - 5 (overhead) = 44 nop // T1L 0,45 = 54 - 10 (ifelse) - 5 (overhead) = 44 nop
sio_hw->gpio_clr = pinMask; sio_hw->gpio_clr = pinMask;
NOP_COUNT(T1L_CYCLE); __asm volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#if F_CPU == 240000000L "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
NOP_COUNT(T1L_CYCLE); "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#endif "nop; nop; nop; nop; nop; nop; nop; nop; nop;");
} else { } else {
// T0H 0.4 us = 48 cycles // T0H 0,4 us = 48 - 1 = 47 nop
sio_hw->gpio_set = pinMask; sio_hw->gpio_set = pinMask;
NOP_COUNT(T0H_CYCLE); __asm volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#if F_CPU == 240000000L "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
NOP_COUNT(T0H_CYCLE); "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#endif "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop;");
// T0L 0.85 us = 102 - 10 (ifelse) - 5 (overhead) = 87 nop // T0L 0.85 us = 102 - 10 (ifelse) - 5 (overhead) = 87 nop
sio_hw->gpio_clr = pinMask; sio_hw->gpio_clr = pinMask;
NOP_COUNT(T0L_CYCLE); __asm volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#if F_CPU == 240000000L "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
NOP_COUNT(T0L_CYCLE); "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
#endif "nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"
"nop; nop; nop; nop;");
} }
if (bitMask >>= 1) { if (bitMask >>= 1) {
// not full byte, shift to next bit // not full byte, shift to next bit
NOP_COUNT(LOOP_OVERHEAD_CYCLE); __asm volatile("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;");
} else { } else {
// probably take 10 nops // probably take 10 nops
// if a full byte is sent, next to another byte // if a full byte is sent, next to another byte
@ -829,9 +770,6 @@ void __no_inline_not_in_flash_func(Adafruit_TestBed_Brains::setColor)(
p = *ptr++; p = *ptr++;
bitMask = 0x80; bitMask = 0x80;
} }
#if F_CPU == 240000000L
NOP_COUNT(LOOP_OVERHEAD_CYCLE);
#endif
} }
restore_interrupts(isr_context); restore_interrupts(isr_context);
@ -913,14 +851,15 @@ void Adafruit_TestBed_Brains::usbh_setVBus(bool en) {
bool Adafruit_TestBed_Brains::usbh_begin(void) { bool Adafruit_TestBed_Brains::usbh_begin(void) {
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
uint32_t cpu_hz = clock_get_hz(clk_sys); uint32_t cpu_hz = clock_get_hz(clk_sys);
if (cpu_hz % 12000000UL) { if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
while (!Serial) { while (!Serial) {
delay(10); // wait for native usb delay(10); // wait for native usb
} }
Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be " Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be "
"multiple of 12 Mhz\r\n", "multiple of 120 Mhz\r\n",
cpu_hz); cpu_hz);
Serial.println("Change your CPU Clock to 12*n Mhz in Menu->CPU Speed"); Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU "
"Speed \r\n");
while (1) { while (1) {
delay(1); delay(1);
} }

View file

@ -1,16 +1,26 @@
#ifndef ADAFRUIT_TESTBED_BRAINS_H #ifndef ADAFRUIT_TESTBED_BRAINS_H
#define ADAFRUIT_TESTBED_BRAINS_H #define ADAFRUIT_TESTBED_BRAINS_H
#ifdef ARDUINO_ARCH_RP2040 #ifdef ARDUINO_RASPBERRY_PI_PICO
#include "SdFat_Adafruit_Fork.h"
#include "Adafruit_TestBed.h" #include "Adafruit_TestBed.h"
#include "SdFat.h"
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
#include "Adafruit_DAP.h" #include "Adafruit_DAP.h"
#include "Adafruit_TinyUSB.h" #include "Adafruit_TinyUSB.h"
#include "ESP32BootROM.h"
#include "MD5Builder.h"
typedef struct {
const char *name;
const uint8_t *data;
const uint32_t compressed_len;
const uint32_t uncompressed_len;
const uint8_t md5[16];
} esp32_zipfile_t;
/**************************************************************************/ /**************************************************************************/
/*! /*!
@brief A helper class for making RP2040 "Tester Brains" @brief A helper class for making RP2040 "Tester Brains"
@ -49,31 +59,24 @@ public:
bool usbh_mountFS(uint8_t dev_addr); bool usbh_mountFS(uint8_t dev_addr);
bool usbh_umountFS(uint8_t dev_addr); bool usbh_umountFS(uint8_t dev_addr);
//--------------------------------------------------------------------+1 // Target
// RP2 (rp2040 and rp2350) Target void targetReset(uint32_t reset_ms = 20);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// reset rp2 target to Boot ROM // RP2040 Target
void rp2_targetResetBootRom(int bootsel_pin = 28, uint32_t reset_ms = 20); //--------------------------------------------------------------------+
// reset rp2040 target to Boot ROM
void rp2040_targetResetBootRom(int bootsel_pin = 28, uint32_t reset_ms = 20);
// program rp2 target by copying UF2 file stored in flash // program rp2040 target by copying UF2 file from SDCard
size_t rp2_programUF2(const uint8_t *buffer, size_t bufsize);
// program rp2 target by copying UF2 file from SDCard
// return number of copied bytes (typically uf2 file size) // return number of copied bytes (typically uf2 file size)
size_t rp2_programUF2(const char *fpath); size_t rp2040_programUF2(const char *fpath);
// backward compatibility
void rp2040_targetResetBootRom(int bootsel_pin = 28, uint32_t reset_ms = 20) {
rp2_targetResetBootRom(bootsel_pin, reset_ms);
}
size_t rp2040_programUF2(const char *fpath) { return rp2_programUF2(fpath); }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// DAP (samd21/51, nrf5x, stm32f4 etc..) Target // DAP (samd21/51, nrf5x, stm32f4 etc..) Target
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
bool dap_begin(Adafruit_DAP *dp); bool dap_begin(Adafruit_DAP *dp);
bool dap_connect(uint32_t swj_clock = 50); bool dap_connect(void);
void dap_disconnect(void); void dap_disconnect(void);
bool dap_unprotectBoot(void); bool dap_unprotectBoot(void);
@ -83,12 +86,24 @@ public:
// program dap target with file from SDCard // program dap target with file from SDCard
// return number of programmed bytes // return number of programmed bytes
// Note: if do_crc32 is false, we will verify each write by reading back size_t dap_programFlash(const char *fpath, uint32_t addr);
size_t dap_programFlash(const char *fpath, uint32_t addr,
bool do_verify = true, bool do_crc32 = true);
// read dap target flash to file on SDCard //--------------------------------------------------------------------+
size_t dap_readFlash(const char *fpath, uint32_t addr, size_t size); // ESP32 Target
//--------------------------------------------------------------------+
bool esp32_begin(ESP32BootROMClass *bootrom, uint32_t baudrate);
void esp32_end(bool reset_esp = false);
// program esp32 target with file from SDCard
// return number of programmed bytes
size_t esp32_programFlash(const char *fpath, uint32_t addr);
// program flash with compressed using zipfile struct
size_t esp32_programFlashDefl(const esp32_zipfile_t *zfile, uint32_t addr);
bool esp32_s3_inReset(void);
void esp32_s3_clearReset(void);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Public Variables // Public Variables
@ -108,6 +123,11 @@ public:
// Dap // Dap
Adafruit_DAP *dap; Adafruit_DAP *dap;
// ESP32 ROM
ESP32BootROMClass *esp32boot;
int _target_rst;
private: private:
bool _inited; bool _inited;
uint8_t _lcd_line; uint8_t _lcd_line;
@ -120,6 +140,10 @@ private:
int _target_swdio; int _target_swdio;
int _target_swdclk; int _target_swdclk;
bool _esp32_flash_defl;
uint32_t _esp32_chip_detect;
bool _esp32s3_in_reset;
void lcd_write(uint8_t linenum, char buf[17]); void lcd_write(uint8_t linenum, char buf[17]);
}; };

View file

@ -19,14 +19,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
// https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html #if defined(ARDUINO_RASPBERRY_PI_PICO) || defined(__SAMD51__) || \
#if defined(ARDUINO_ARCH_RP2040) || defined(__SAMD51__) || \
defined(TARGET_RP2040) || defined(ARDUINO_ARCH_ESP32) || \
(defined(ARDUINO_ARCH_SAMD) && defined(ARM_MATH_CM0PLUS)) (defined(ARDUINO_ARCH_SAMD) && defined(ARM_MATH_CM0PLUS))
#include "ESP32BootROM.h" #include "ESP32BootROM.h"
#include "stub_esp.h" #include "stub_esp32.h"
#ifdef USE_TINYUSB #ifdef USE_TINYUSB
#include "Adafruit_TinyUSB.h" #include "Adafruit_TinyUSB.h"
@ -199,7 +196,7 @@ void ESP32BootROMClass::resetBootloader(void) {
// IO0 high: done // IO0 high: done
digitalWrite(_gpio0Pin, HIGH); digitalWrite(_gpio0Pin, HIGH);
} }
#if defined(USE_TINYUSB) && defined(ARDUINO_ARCH_RP2040) #ifdef USE_TINYUSB
else { else {
// Serial Host using setDtrRts() // Serial Host using setDtrRts()
// - DTR -> IO0 // - DTR -> IO0
@ -232,12 +229,14 @@ uint32_t ESP32BootROMClass::begin(unsigned long baudrate) {
resetBootloader(); resetBootloader();
bool synced = false; bool synced = false;
for (int retries = 0; !synced && (retries < 5); retries++) { for (int retries = 0; !synced && (retries < 5); retries++) {
Serial.println("Trying to sync"); Serial.println("Trying to sync");
synced = sync(); synced = sync();
if (synced) { if (synced) {
break; break;
} }
delay(10); delay(10);
} }
if (!synced) { if (!synced) {
@ -255,19 +254,36 @@ uint32_t ESP32BootROMClass::begin(unsigned long baudrate) {
Serial.printf("Chip Detect: 0x%08lX\r\n", _chip_detect); Serial.printf("Chip Detect: 0x%08lX\r\n", _chip_detect);
const esp32_stub_loader_t *stub = NULL; const esp32_stub_loader_t *stub = NULL;
for (uint32_t i = 0; i < ESP_STUB_COUNT; i++) { switch (_chip_detect) {
if (stub_esp_arr[i]->chip_detect == _chip_detect) { case CHIP_DETECT_MAGIC_ESP32:
stub = stub_esp_arr[i]; // only ESP32 have SUPPORTS_ENCRYPTED_FLASH = false
Serial.println("Found ESP32");
stub = &stub_esp32;
_supports_encrypted_flash = false;
break;
case CHIP_DETECT_MAGIC_ESP32S2:
Serial.println("Found ESP32-S2");
stub = &stub_esp32s2;
break;
case CHIP_DETECT_MAGIC_ESP32S3:
Serial.println("Found ESP32-S3");
stub = &stub_esp32s3;
break;
case CHIP_DETECT_MAGIC_ESP8266:
Serial.println("Found ESP8266");
stub = &stub_esp8266;
break;
default:
Serial.println("Found unknown ESP");
break; break;
}
} }
if (stub) { if (stub) {
Serial.printf("Found %s\r\n", stub->chip_name);
VERIFY(uploadStub(stub)); VERIFY(uploadStub(stub));
VERIFY(syncStub(3000)); VERIFY(syncStub(3000));
} else {
Serial.println("Found unknown ESP chip");
} }
if (baudrate != ESP_ROM_BAUD) { if (baudrate != ESP_ROM_BAUD) {

View file

@ -30,11 +30,9 @@ enum {
CHIP_DETECT_MAGIC_ESP32S2 = 0x000007C6, CHIP_DETECT_MAGIC_ESP32S2 = 0x000007C6,
CHIP_DETECT_MAGIC_ESP32S3 = 0x9, CHIP_DETECT_MAGIC_ESP32S3 = 0x9,
CHIP_DETECT_MAGIC_ESP8266 = 0xFFF0C101, CHIP_DETECT_MAGIC_ESP8266 = 0xFFF0C101,
CHIP_DETECT_MAGIC_ESP32C6 = 0x2CE0806F,
}; };
typedef struct { typedef struct {
uint32_t chip_detect;
uint32_t entry; uint32_t entry;
uint32_t text_start; uint32_t text_start;
uint32_t text_length; uint32_t text_length;
@ -42,7 +40,6 @@ typedef struct {
uint32_t data_start; uint32_t data_start;
uint32_t data_length; uint32_t data_length;
const uint8_t *data; const uint8_t *data;
const char *chip_name;
} esp32_stub_loader_t; } esp32_stub_loader_t;
class ESP32BootROMClass { class ESP32BootROMClass {

View file

@ -1,11 +1,7 @@
// Generated by tools/esp_stub.py
#define ESP_STUB_COUNT (5)
// const esp32_stub_loader_t stub_esp32 // const esp32_stub_loader_t stub_esp32
// const esp32_stub_loader_t stub_esp32s2 // const esp32_stub_loader_t stub_esp32s2
// const esp32_stub_loader_t stub_esp32s3 // const esp32_stub_loader_t stub_esp32s3
// const esp32_stub_loader_t stub_esp8266 // const esp32_stub_loader_t stub_esp8266
// const esp32_stub_loader_t stub_esp32c6
//------------- esp32 -------------// //------------- esp32 -------------//
const uint8_t _stub_esp32_data[4] = { const uint8_t _stub_esp32_data[4] = {
@ -305,7 +301,6 @@ const uint8_t _stub_esp32_text[3432] = {
}; };
const esp32_stub_loader_t stub_esp32 = { const esp32_stub_loader_t stub_esp32 = {
.chip_detect = 0x00f01d83,
.entry = 0x400be5ac, .entry = 0x400be5ac,
.text_start = 0x400be000, .text_start = 0x400be000,
.text_length = 3432, .text_length = 3432,
@ -313,7 +308,6 @@ const esp32_stub_loader_t stub_esp32 = {
.data_start = 0x3ffdeba8, .data_start = 0x3ffdeba8,
.data_length = 4, .data_length = 4,
.data = _stub_esp32_data, .data = _stub_esp32_data,
.chip_name = "ESP32",
}; };
//------------- esp32s2 -------------// //------------- esp32s2 -------------//
@ -673,7 +667,6 @@ const uint8_t _stub_esp32s2_text[4136] = {
}; };
const esp32_stub_loader_t stub_esp32s2 = { const esp32_stub_loader_t stub_esp32s2 = {
.chip_detect = 0x000007c6,
.entry = 0x40028760, .entry = 0x40028760,
.text_start = 0x40028000, .text_start = 0x40028000,
.text_length = 4136, .text_length = 4136,
@ -681,7 +674,6 @@ const esp32_stub_loader_t stub_esp32s2 = {
.data_start = 0x3ffe2bf4, .data_start = 0x3ffe2bf4,
.data_length = 4, .data_length = 4,
.data = _stub_esp32s2_data, .data = _stub_esp32s2_data,
.chip_name = "ESP32S2",
}; };
//------------- esp32s3 -------------// //------------- esp32s3 -------------//
@ -1099,7 +1091,6 @@ const uint8_t _stub_esp32s3_text[4836] = {
}; };
const esp32_stub_loader_t stub_esp32s3 = { const esp32_stub_loader_t stub_esp32s3 = {
.chip_detect = 0x00000009,
.entry = 0x40378988, .entry = 0x40378988,
.text_start = 0x40378000, .text_start = 0x40378000,
.text_length = 4836, .text_length = 4836,
@ -1107,7 +1098,6 @@ const esp32_stub_loader_t stub_esp32s3 = {
.data_start = 0x3fcb2bf4, .data_start = 0x3fcb2bf4,
.data_length = 4, .data_length = 4,
.data = _stub_esp32s3_data, .data = _stub_esp32s3_data,
.chip_name = "ESP32S3",
}; };
//------------- esp8266 -------------// //------------- esp8266 -------------//
@ -1869,7 +1859,6 @@ const uint8_t _stub_esp8266_text[8240] = {
}; };
const esp32_stub_loader_t stub_esp8266 = { const esp32_stub_loader_t stub_esp8266 = {
.chip_detect = 0xfff0c101,
.entry = 0x4010d004, .entry = 0x4010d004,
.text_start = 0x4010d000, .text_start = 0x4010d000,
.text_length = 8240, .text_length = 8240,
@ -1877,358 +1866,4 @@ const esp32_stub_loader_t stub_esp8266 = {
.data_start = 0x3fffaca8, .data_start = 0x3fffaca8,
.data_length = 768, .data_length = 768,
.data = _stub_esp8266_data, .data = _stub_esp8266_data,
.chip_name = "ESP8266",
};
//------------- esp32c6 -------------//
const uint8_t _stub_esp32c6_data[160] = {
0x14, 0x00, 0x84, 0x40, 0x72, 0x0a, 0x80, 0x40, 0xc2, 0x0a, 0x80, 0x40,
0x1a, 0x0b, 0x80, 0x40, 0xe8, 0x0b, 0x80, 0x40, 0x54, 0x0c, 0x80, 0x40,
0x02, 0x0c, 0x80, 0x40, 0x3e, 0x09, 0x80, 0x40, 0xa4, 0x0b, 0x80, 0x40,
0xe4, 0x0b, 0x80, 0x40, 0x2e, 0x0b, 0x80, 0x40, 0xee, 0x08, 0x80, 0x40,
0x62, 0x0b, 0x80, 0x40, 0xee, 0x08, 0x80, 0x40, 0x4c, 0x0a, 0x80, 0x40,
0x92, 0x0a, 0x80, 0x40, 0xc2, 0x0a, 0x80, 0x40, 0x1a, 0x0b, 0x80, 0x40,
0x5e, 0x0a, 0x80, 0x40, 0xa2, 0x09, 0x80, 0x40, 0xd2, 0x09, 0x80, 0x40,
0x5a, 0x0a, 0x80, 0x40, 0xac, 0x0e, 0x80, 0x40, 0xc2, 0x0a, 0x80, 0x40,
0x6c, 0x0d, 0x80, 0x40, 0x64, 0x0e, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40,
0x8c, 0x0e, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40,
0x2e, 0x08, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40,
0x2e, 0x08, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40,
0x08, 0x0d, 0x80, 0x40, 0x2e, 0x08, 0x80, 0x40, 0x8a, 0x0d, 0x80, 0x40,
0x64, 0x0e, 0x80, 0x40,
};
const uint8_t _stub_esp32c6_text[3792] = {
0x41, 0x11, 0x22, 0xc4, 0x26, 0xc2, 0x06, 0xc6, 0xb7, 0xf7, 0x00, 0x60,
0x11, 0x47, 0x37, 0x04, 0x84, 0x40, 0xd8, 0xcb, 0xb7, 0xf4, 0x00, 0x60,
0x13, 0x04, 0x04, 0x00, 0xdc, 0x40, 0x91, 0x8b, 0x91, 0xe7, 0xb2, 0x40,
0x22, 0x44, 0x92, 0x44, 0x41, 0x01, 0x82, 0x80, 0x88, 0x40, 0x1c, 0x40,
0x13, 0x75, 0xf5, 0x0f, 0x82, 0x97, 0xdd, 0xb7, 0x01, 0x11, 0xb7, 0x07,
0x00, 0x60, 0x4e, 0xc6, 0x83, 0xa9, 0x87, 0x00, 0x4a, 0xc8, 0x37, 0x09,
0x84, 0x40, 0x26, 0xca, 0x52, 0xc4, 0x06, 0xce, 0x22, 0xcc, 0xb7, 0x04,
0x00, 0x60, 0x7d, 0x5a, 0x13, 0x09, 0x09, 0x00, 0xc0, 0x4c, 0x13, 0x74,
0xf4, 0x0f, 0x0d, 0xe0, 0xf2, 0x40, 0x62, 0x44, 0x23, 0xa8, 0x34, 0x01,
0x42, 0x49, 0xd2, 0x44, 0xb2, 0x49, 0x22, 0x4a, 0x05, 0x61, 0x82, 0x80,
0x88, 0x40, 0x83, 0x27, 0x09, 0x00, 0x13, 0x75, 0xf5, 0x0f, 0x82, 0x97,
0x7d, 0x14, 0xe3, 0x19, 0x44, 0xff, 0xc9, 0xbf, 0x13, 0x07, 0x00, 0x0c,
0x94, 0x41, 0xaa, 0x87, 0x63, 0x18, 0xe5, 0x00, 0x85, 0x47, 0x85, 0xc6,
0x23, 0xa0, 0x05, 0x00, 0x79, 0x55, 0x82, 0x80, 0x05, 0x47, 0x63, 0x87,
0xe6, 0x00, 0x09, 0x46, 0x63, 0x8d, 0xc6, 0x00, 0x7d, 0x55, 0x82, 0x80,
0x42, 0x05, 0x13, 0x07, 0xb0, 0x0d, 0x41, 0x85, 0x63, 0x95, 0xe7, 0x02,
0x89, 0x47, 0x9c, 0xc1, 0xf5, 0xb7, 0x93, 0x06, 0xc0, 0x0d, 0x63, 0x16,
0xd5, 0x00, 0x98, 0xc1, 0x13, 0x05, 0x00, 0x0c, 0x82, 0x80, 0x93, 0x06,
0xd0, 0x0d, 0x7d, 0x55, 0x63, 0x95, 0xd7, 0x00, 0x98, 0xc1, 0x13, 0x05,
0xb0, 0x0d, 0x82, 0x80, 0xb7, 0x35, 0x85, 0x40, 0x41, 0x11, 0x93, 0x85,
0x85, 0xba, 0x06, 0xc6, 0x61, 0x3f, 0x63, 0x45, 0x05, 0x06, 0xb7, 0x37,
0x85, 0x40, 0x93, 0x87, 0x07, 0xb2, 0x03, 0xa7, 0x07, 0x08, 0x03, 0xd6,
0x47, 0x08, 0x13, 0x75, 0xf5, 0x0f, 0x93, 0x06, 0x16, 0x00, 0xc2, 0x06,
0xc1, 0x82, 0x23, 0x92, 0xd7, 0x08, 0x32, 0x97, 0x23, 0x00, 0xa7, 0x00,
0x03, 0xd7, 0x47, 0x08, 0x91, 0x67, 0x93, 0x87, 0x07, 0x04, 0x63, 0x1e,
0xf7, 0x02, 0x37, 0xb7, 0x84, 0x40, 0x13, 0x07, 0x07, 0xb2, 0xa1, 0x67,
0xba, 0x97, 0x03, 0xa6, 0x07, 0x08, 0xb7, 0xf6, 0x84, 0x40, 0xb7, 0x37,
0x85, 0x40, 0x93, 0x87, 0x07, 0xb2, 0x93, 0x86, 0x06, 0xb6, 0x63, 0x1f,
0xe6, 0x00, 0x23, 0xa6, 0xc7, 0x08, 0x23, 0xa0, 0xd7, 0x08, 0x23, 0x92,
0x07, 0x08, 0x21, 0xa0, 0xf9, 0x57, 0xe3, 0x06, 0xf5, 0xfc, 0xb2, 0x40,
0x41, 0x01, 0x82, 0x80, 0x23, 0xa6, 0xd7, 0x08, 0x23, 0xa0, 0xe7, 0x08,
0xdd, 0xb7, 0x37, 0x37, 0x00, 0x60, 0x7c, 0x4b, 0x9d, 0x8b, 0xf5, 0xff,
0x37, 0x27, 0x00, 0x60, 0x7c, 0x4b, 0x9d, 0x8b, 0xf5, 0xff, 0x82, 0x80,
0x41, 0x11, 0x06, 0xc6, 0xdd, 0x37, 0xb7, 0x37, 0x00, 0x60, 0x23, 0xa6,
0x07, 0x02, 0x37, 0x07, 0x00, 0x08, 0x98, 0xc3, 0x98, 0x43, 0x7d, 0xff,
0xc8, 0x57, 0xb2, 0x40, 0x13, 0x45, 0xf5, 0xff, 0x05, 0x89, 0x41, 0x01,
0x82, 0x80, 0x41, 0x11, 0x06, 0xc6, 0xd9, 0x3f, 0x7d, 0xdd, 0x37, 0x07,
0x00, 0x40, 0xb7, 0x37, 0x00, 0x60, 0x98, 0xc3, 0x37, 0x37, 0x00, 0x60,
0x1c, 0x43, 0xfd, 0xff, 0xb2, 0x40, 0x41, 0x01, 0x82, 0x80, 0x41, 0x11,
0x22, 0xc4, 0x37, 0x84, 0x84, 0x40, 0x93, 0x07, 0x44, 0x01, 0x4a, 0xc0,
0x03, 0xa9, 0x07, 0x01, 0x06, 0xc6, 0x26, 0xc2, 0x63, 0x0a, 0x09, 0x04,
0x45, 0x37, 0x39, 0xc5, 0xbd, 0x47, 0x13, 0x04, 0x44, 0x01, 0x81, 0x44,
0x63, 0xd6, 0x27, 0x01, 0x04, 0x44, 0xbd, 0x88, 0x93, 0xb4, 0x14, 0x00,
0x7d, 0x37, 0x85, 0x3f, 0x1c, 0x44, 0x37, 0x06, 0x80, 0x00, 0x13, 0x97,
0xc7, 0x00, 0x99, 0xe0, 0x37, 0x06, 0x00, 0x01, 0xb7, 0xf6, 0xff, 0x00,
0x75, 0x8f, 0xb7, 0x36, 0x00, 0x60, 0xd8, 0xc2, 0x90, 0xc2, 0x98, 0x42,
0x7d, 0xff, 0x41, 0x47, 0x91, 0xe0, 0x05, 0x47, 0x33, 0x09, 0xe9, 0x40,
0xba, 0x97, 0x23, 0x28, 0x24, 0x01, 0x1c, 0xc4, 0xb2, 0x40, 0x22, 0x44,
0x92, 0x44, 0x02, 0x49, 0x41, 0x01, 0x82, 0x80, 0x01, 0x11, 0x06, 0xce,
0x22, 0xcc, 0x25, 0x37, 0x37, 0x04, 0xce, 0x3f, 0x6c, 0x00, 0x13, 0x05,
0x44, 0xff, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0xa0, 0xf2, 0xaa, 0x87,
0x05, 0x45, 0x95, 0xe7, 0xb2, 0x47, 0x93, 0xf7, 0x07, 0x20, 0x3e, 0xc6,
0x89, 0x37, 0x37, 0x37, 0x00, 0x60, 0x1c, 0x47, 0xb7, 0x06, 0x40, 0x00,
0x13, 0x05, 0x44, 0xff, 0xd5, 0x8f, 0x1c, 0xc7, 0xb2, 0x45, 0x97, 0x00,
0x80, 0xff, 0xe7, 0x80, 0x20, 0xf0, 0x33, 0x35, 0xa0, 0x00, 0xf2, 0x40,
0x62, 0x44, 0x05, 0x61, 0x82, 0x80, 0x41, 0x11, 0xb7, 0x87, 0x84, 0x40,
0x06, 0xc6, 0x93, 0x87, 0x47, 0x01, 0x05, 0x47, 0x23, 0x80, 0xe7, 0x00,
0x13, 0xd7, 0xc5, 0x00, 0x98, 0xc7, 0x05, 0x67, 0x7d, 0x17, 0xcc, 0xc3,
0xc8, 0xc7, 0xf9, 0x8d, 0x3a, 0x95, 0xaa, 0x95, 0xb1, 0x81, 0x8c, 0xcb,
0x23, 0xaa, 0x07, 0x00, 0x41, 0x37, 0x19, 0xc1, 0x13, 0x05, 0x50, 0x0c,
0xb2, 0x40, 0x41, 0x01, 0x82, 0x80, 0x01, 0x11, 0x22, 0xcc, 0x37, 0x84,
0x84, 0x40, 0x93, 0x07, 0x44, 0x01, 0x26, 0xca, 0xc4, 0x47, 0x4e, 0xc6,
0x06, 0xce, 0x4a, 0xc8, 0xaa, 0x89, 0x13, 0x04, 0x44, 0x01, 0x63, 0xf3,
0x95, 0x00, 0xae, 0x84, 0xa9, 0xc0, 0x03, 0x29, 0x44, 0x00, 0x26, 0x99,
0x13, 0x59, 0xc9, 0x00, 0x1c, 0x48, 0x63, 0x55, 0xf0, 0x00, 0x1c, 0x44,
0x63, 0x5e, 0xf9, 0x02, 0xb5, 0x3d, 0x7d, 0xdd, 0x48, 0x40, 0x26, 0x86,
0xce, 0x85, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x20, 0xe3, 0x13, 0x75,
0xf5, 0x0f, 0x01, 0xc5, 0x93, 0x07, 0x40, 0x0c, 0x5c, 0xc8, 0x5c, 0x40,
0xa6, 0x97, 0x5c, 0xc0, 0x5c, 0x44, 0x85, 0x8f, 0x5c, 0xc4, 0xf2, 0x40,
0x62, 0x44, 0xd2, 0x44, 0x42, 0x49, 0xb2, 0x49, 0x05, 0x61, 0x82, 0x80,
0x69, 0x35, 0x6d, 0xbf, 0x41, 0x11, 0x06, 0xc6, 0x97, 0x00, 0x80, 0xff,
0xe7, 0x80, 0x40, 0xd6, 0x03, 0x45, 0x85, 0x01, 0xb2, 0x40, 0x75, 0x15,
0x13, 0x35, 0x15, 0x00, 0x41, 0x01, 0x82, 0x80, 0x41, 0x11, 0x06, 0xc6,
0xc5, 0x37, 0x0d, 0xc5, 0xb7, 0x07, 0x84, 0x40, 0x93, 0x87, 0x07, 0x00,
0xd4, 0x43, 0x99, 0xce, 0x37, 0x67, 0x09, 0x60, 0x13, 0x07, 0x07, 0x11,
0x1c, 0x43, 0x37, 0x06, 0xfd, 0xff, 0x7d, 0x16, 0xf1, 0x8f, 0x37, 0x06,
0x03, 0x00, 0xf1, 0x8e, 0xd5, 0x8f, 0x1c, 0xc3, 0xb2, 0x40, 0x41, 0x01,
0x82, 0x80, 0x41, 0x11, 0x06, 0xc6, 0x6d, 0x37, 0x11, 0xc1, 0x0d, 0x45,
0xb2, 0x40, 0x41, 0x01, 0x17, 0x03, 0x80, 0xff, 0x67, 0x00, 0x83, 0xcc,
0x41, 0x11, 0x06, 0xc6, 0x26, 0xc2, 0x22, 0xc4, 0xaa, 0x84, 0x97, 0x00,
0x80, 0xff, 0xe7, 0x80, 0xe0, 0xc9, 0x59, 0x37, 0x0d, 0xc9, 0x37, 0x07,
0x84, 0x40, 0x93, 0x06, 0x07, 0x00, 0x83, 0xd7, 0x86, 0x00, 0x13, 0x04,
0x07, 0x00, 0x85, 0x07, 0xc2, 0x07, 0xc1, 0x83, 0x23, 0x94, 0xf6, 0x00,
0x93, 0x06, 0x00, 0x0c, 0x63, 0x86, 0xd4, 0x00, 0x13, 0x07, 0xe0, 0x03,
0x63, 0x75, 0xf7, 0x00, 0x6d, 0x37, 0x23, 0x14, 0x04, 0x00, 0xb2, 0x40,
0x22, 0x44, 0x92, 0x44, 0x41, 0x01, 0x82, 0x80, 0x41, 0x11, 0x06, 0xc6,
0x13, 0x07, 0x00, 0x0c, 0x63, 0x1a, 0xe5, 0x00, 0x13, 0x05, 0xb0, 0x0d,
0x45, 0x37, 0x13, 0x05, 0xc0, 0x0d, 0xb2, 0x40, 0x41, 0x01, 0x59, 0xbf,
0x13, 0x07, 0xb0, 0x0d, 0xe3, 0x1b, 0xe5, 0xfe, 0x71, 0x37, 0x13, 0x05,
0xd0, 0x0d, 0xf5, 0xb7, 0x41, 0x11, 0x22, 0xc4, 0x26, 0xc2, 0x06, 0xc6,
0x2a, 0x84, 0xb3, 0x04, 0xb5, 0x00, 0x63, 0x17, 0x94, 0x00, 0xb2, 0x40,
0x22, 0x44, 0x92, 0x44, 0x41, 0x01, 0x82, 0x80, 0x03, 0x45, 0x04, 0x00,
0x05, 0x04, 0x4d, 0x3f, 0xed, 0xb7, 0x35, 0x71, 0x26, 0xcb, 0x4e, 0xc7,
0xfd, 0x72, 0x85, 0x69, 0xfd, 0x74, 0x22, 0xcd, 0x4a, 0xc9, 0x52, 0xc5,
0x56, 0xc3, 0x06, 0xcf, 0x93, 0x84, 0x84, 0xfa, 0x16, 0x91, 0x93, 0x87,
0x09, 0x07, 0xa6, 0x97, 0x18, 0x08, 0xb3, 0x84, 0xe7, 0x00, 0x2a, 0x89,
0x26, 0x85, 0x2e, 0x84, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x80, 0x2c,
0x93, 0x87, 0x09, 0x07, 0x18, 0x08, 0x05, 0x6a, 0xba, 0x97, 0xb3, 0x8a,
0x47, 0x41, 0x31, 0xe4, 0x05, 0x67, 0x7d, 0x75, 0x93, 0x05, 0x85, 0xfa,
0x93, 0x07, 0x07, 0x07, 0x13, 0x05, 0x85, 0xf9, 0x14, 0x08, 0xaa, 0x97,
0x33, 0x85, 0xd7, 0x00, 0x93, 0x07, 0x07, 0x07, 0xae, 0x97, 0xb3, 0x85,
0xd7, 0x00, 0x2a, 0xc6, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x40, 0x29,
0x32, 0x45, 0xc1, 0x45, 0x95, 0x37, 0x01, 0x45, 0x85, 0x62, 0x16, 0x91,
0xfa, 0x40, 0x6a, 0x44, 0xda, 0x44, 0x4a, 0x49, 0xba, 0x49, 0x2a, 0x4a,
0x9a, 0x4a, 0x0d, 0x61, 0x82, 0x80, 0xa2, 0x89, 0x63, 0x73, 0x8a, 0x00,
0x85, 0x69, 0x4e, 0x86, 0xd6, 0x85, 0x4a, 0x85, 0x97, 0x00, 0x80, 0xff,
0xe7, 0x80, 0xc0, 0xc5, 0x13, 0x75, 0xf5, 0x0f, 0x01, 0xed, 0x4e, 0x86,
0xd6, 0x85, 0x26, 0x85, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x80, 0x24,
0x4e, 0x99, 0x33, 0x04, 0x34, 0x41, 0x51, 0xb7, 0x13, 0x05, 0x30, 0x06,
0x55, 0xbf, 0x13, 0x05, 0x00, 0x0c, 0x49, 0xbd, 0x31, 0x71, 0xfd, 0x72,
0x05, 0x67, 0x4e, 0xd7, 0x52, 0xd5, 0x56, 0xd3, 0x5e, 0xcf, 0x06, 0xdf,
0x22, 0xdd, 0x26, 0xdb, 0x4a, 0xd9, 0x5a, 0xd1, 0x62, 0xcd, 0x66, 0xcb,
0x6a, 0xc9, 0x6e, 0xc7, 0xfd, 0x77, 0x16, 0x91, 0x13, 0x07, 0x07, 0x07,
0x3e, 0x97, 0x1c, 0x08, 0xba, 0x97, 0x3e, 0xc6, 0x23, 0xaa, 0x07, 0xf8,
0xaa, 0x89, 0x2e, 0x8a, 0xb2, 0x8a, 0xb6, 0x8b, 0xf5, 0x33, 0x93, 0x07,
0x00, 0x02, 0x19, 0xc1, 0xb7, 0x07, 0x02, 0x00, 0x3e, 0x85, 0x97, 0x00,
0x80, 0xff, 0xe7, 0x80, 0x20, 0x1d, 0x85, 0x67, 0x63, 0xe5, 0x57, 0x13,
0x05, 0x64, 0x7d, 0x79, 0x13, 0x09, 0x89, 0xfa, 0x93, 0x07, 0x04, 0x07,
0xca, 0x97, 0x18, 0x08, 0x33, 0x89, 0xe7, 0x00, 0x4a, 0x85, 0x97, 0x00,
0x80, 0xff, 0xe7, 0x80, 0xa0, 0x1b, 0x7d, 0x7b, 0x13, 0x0c, 0x3b, 0xf9,
0x93, 0x0c, 0x8b, 0xf9, 0x13, 0x07, 0x04, 0x07, 0x93, 0x07, 0x04, 0x07,
0x14, 0x08, 0x62, 0x97, 0xe6, 0x97, 0x81, 0x44, 0x33, 0x0c, 0xd7, 0x00,
0xb3, 0x8c, 0xd7, 0x00, 0x52, 0x4d, 0x63, 0x7c, 0x4d, 0x09, 0x63, 0xf1,
0xa4, 0x03, 0x41, 0xa8, 0x99, 0x3f, 0xa2, 0x85, 0x08, 0x01, 0x8d, 0x35,
0xb9, 0x37, 0x22, 0x86, 0x0c, 0x01, 0x4a, 0x85, 0x97, 0x00, 0x80, 0xff,
0xe7, 0x80, 0x80, 0x17, 0xa2, 0x99, 0xa2, 0x94, 0x63, 0xf5, 0x44, 0x03,
0xb3, 0x87, 0xa4, 0x41, 0x63, 0xf1, 0x77, 0x03, 0x33, 0x04, 0x9a, 0x40,
0x63, 0xf3, 0x8a, 0x00, 0x56, 0x84, 0x22, 0x86, 0x0c, 0x01, 0x4e, 0x85,
0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x00, 0xb5, 0x13, 0x75, 0xf5, 0x0f,
0x55, 0xdd, 0x02, 0xcc, 0x01, 0x44, 0x79, 0x5d, 0x8d, 0x4d, 0xa3, 0x09,
0x01, 0x00, 0x62, 0x85, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x40, 0xa4,
0x7d, 0xf9, 0x03, 0x45, 0x31, 0x01, 0xe6, 0x85, 0x85, 0x34, 0x63, 0x4f,
0x05, 0x00, 0xe3, 0xe2, 0x8d, 0xfe, 0x85, 0x67, 0x93, 0x87, 0x07, 0x07,
0xa2, 0x97, 0x18, 0x08, 0xba, 0x97, 0xda, 0x97, 0x23, 0x8a, 0xa7, 0xf8,
0x05, 0x04, 0xf1, 0xb7, 0xe3, 0x15, 0xa5, 0xfd, 0x91, 0x47, 0xe3, 0x05,
0xf4, 0xf6, 0x05, 0x67, 0x7d, 0x75, 0x93, 0x07, 0x07, 0x07, 0x93, 0x05,
0x85, 0xfa, 0x13, 0x05, 0x85, 0xf9, 0x14, 0x08, 0xaa, 0x97, 0x33, 0x85,
0xd7, 0x00, 0x93, 0x07, 0x07, 0x07, 0xae, 0x97, 0xb3, 0x85, 0xd7, 0x00,
0x2a, 0xc6, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0xa0, 0x0d, 0x71, 0x3d,
0x32, 0x45, 0xc1, 0x45, 0x65, 0x33, 0x51, 0x3d, 0xc1, 0x31, 0xb7, 0x07,
0x02, 0x00, 0x19, 0xe1, 0x93, 0x07, 0x00, 0x02, 0x3e, 0x85, 0x97, 0x00,
0x80, 0xff, 0xe7, 0x80, 0xa0, 0x0a, 0x85, 0x62, 0x16, 0x91, 0xfa, 0x50,
0x6a, 0x54, 0xda, 0x54, 0x4a, 0x59, 0xba, 0x59, 0x2a, 0x5a, 0x9a, 0x5a,
0x0a, 0x5b, 0xfa, 0x4b, 0x6a, 0x4c, 0xda, 0x4c, 0x4a, 0x4d, 0xba, 0x4d,
0x29, 0x61, 0x82, 0x80, 0xb7, 0x57, 0x41, 0x49, 0x19, 0x71, 0x93, 0x87,
0xf7, 0x84, 0x01, 0x45, 0x86, 0xde, 0xa2, 0xdc, 0xa6, 0xda, 0xca, 0xd8,
0xce, 0xd6, 0xd2, 0xd4, 0xd6, 0xd2, 0xda, 0xd0, 0xde, 0xce, 0xe2, 0xcc,
0xe6, 0xca, 0xea, 0xc8, 0xee, 0xc6, 0x3e, 0xce, 0x97, 0x00, 0x80, 0xff,
0xe7, 0x80, 0x80, 0x9d, 0xa1, 0x39, 0x0d, 0xc1, 0x37, 0x67, 0x09, 0x60,
0x13, 0x07, 0x07, 0x11, 0x1c, 0x43, 0xb7, 0x06, 0x84, 0x40, 0x23, 0xa2,
0xf6, 0x00, 0xb7, 0x06, 0xfd, 0xff, 0xfd, 0x16, 0xf5, 0x8f, 0xc1, 0x66,
0xd5, 0x8f, 0x1c, 0xc3, 0x15, 0x39, 0x05, 0xcd, 0xb7, 0x27, 0x0b, 0x60,
0x37, 0x47, 0xd8, 0x50, 0x93, 0x86, 0x87, 0xc1, 0x13, 0x07, 0x17, 0xaa,
0x98, 0xc2, 0x13, 0x86, 0x07, 0xc0, 0x23, 0x20, 0x06, 0x00, 0x23, 0xa0,
0x06, 0x00, 0x93, 0x86, 0x07, 0xc2, 0x98, 0xc2, 0x93, 0x87, 0xc7, 0xc1,
0x98, 0x43, 0x37, 0x06, 0x04, 0x00, 0x51, 0x8f, 0x98, 0xc3, 0x23, 0xa0,
0x06, 0x00, 0xb7, 0x07, 0x84, 0x40, 0x37, 0x37, 0x85, 0x40, 0x93, 0x87,
0x07, 0x00, 0x13, 0x07, 0x07, 0xbb, 0x21, 0xa0, 0x23, 0xa0, 0x07, 0x00,
0x91, 0x07, 0xe3, 0xed, 0xe7, 0xfe, 0x45, 0x3b, 0x91, 0x45, 0x68, 0x08,
0x75, 0x39, 0x65, 0x33, 0xb7, 0xb7, 0x84, 0x40, 0x93, 0x87, 0x07, 0xb2,
0x21, 0x67, 0x3e, 0x97, 0x23, 0x20, 0xf7, 0x08, 0xb7, 0x07, 0x80, 0x40,
0x37, 0x09, 0x84, 0x40, 0x93, 0x87, 0x87, 0x0e, 0x23, 0x20, 0xf9, 0x00,
0xb7, 0x39, 0x85, 0x40, 0x45, 0x3e, 0x13, 0x09, 0x09, 0x00, 0x93, 0x89,
0x09, 0xb2, 0x63, 0x05, 0x05, 0x10, 0xb7, 0x07, 0x01, 0x60, 0x45, 0x47,
0x23, 0xa0, 0xe7, 0x0c, 0x85, 0x45, 0x45, 0x45, 0x97, 0x00, 0x80, 0xff,
0xe7, 0x80, 0x00, 0xf6, 0xb7, 0x05, 0x80, 0x40, 0x01, 0x46, 0x93, 0x85,
0x05, 0x00, 0x45, 0x45, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x00, 0xf7,
0xb7, 0xf7, 0x00, 0x60, 0x11, 0x47, 0x98, 0xcb, 0x37, 0x05, 0x02, 0x00,
0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x40, 0xf6, 0xb7, 0x17, 0x09, 0x60,
0x88, 0x5f, 0x81, 0x45, 0xb7, 0x84, 0x84, 0x40, 0x71, 0x89, 0x61, 0x15,
0x13, 0x35, 0x15, 0x00, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x00, 0x9e,
0xc1, 0x67, 0xfd, 0x17, 0x13, 0x07, 0x00, 0x10, 0x85, 0x66, 0x41, 0x66,
0xb7, 0x05, 0x00, 0x01, 0x01, 0x45, 0x93, 0x84, 0x44, 0x01, 0xb7, 0x0a,
0x84, 0x40, 0x0d, 0x6a, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x00, 0x94,
0x13, 0x8b, 0x4a, 0x01, 0x26, 0x9a, 0x83, 0xa7, 0xc9, 0x08, 0xf5, 0xdf,
0x83, 0xab, 0xc9, 0x08, 0x85, 0x47, 0x23, 0xa6, 0x09, 0x08, 0x23, 0x02,
0xf1, 0x02, 0x83, 0xc7, 0x1b, 0x00, 0x09, 0x47, 0x23, 0x13, 0xe1, 0x02,
0xa3, 0x02, 0xf1, 0x02, 0x02, 0xd4, 0x4d, 0x47, 0x63, 0x81, 0xe7, 0x08,
0x51, 0x47, 0x63, 0x8f, 0xe7, 0x06, 0x29, 0x47, 0x63, 0x9f, 0xe7, 0x00,
0x83, 0xc7, 0x3b, 0x00, 0x03, 0xc7, 0x2b, 0x00, 0xa2, 0x07, 0xd9, 0x8f,
0x11, 0x47, 0x63, 0x96, 0xe7, 0x00, 0x83, 0xa7, 0x8b, 0x00, 0x9c, 0x43,
0x3e, 0xd4, 0x45, 0x31, 0xa1, 0x45, 0x48, 0x10, 0x75, 0x36, 0x83, 0xc7,
0x3b, 0x00, 0x03, 0xc7, 0x2b, 0x00, 0xa2, 0x07, 0xd9, 0x8f, 0x11, 0x67,
0x41, 0x07, 0x63, 0x74, 0xf7, 0x04, 0x13, 0x05, 0xb0, 0x0d, 0x19, 0x3e,
0x13, 0x05, 0xc0, 0x0d, 0x01, 0x3e, 0x13, 0x05, 0xe0, 0x0e, 0x29, 0x36,
0x8d, 0x39, 0x41, 0xb7, 0xb7, 0x05, 0x80, 0x40, 0x01, 0x46, 0x93, 0x85,
0x85, 0x03, 0x15, 0x45, 0x97, 0x00, 0x80, 0xff, 0xe7, 0x80, 0x00, 0xe8,
0x37, 0x07, 0x00, 0x60, 0x5c, 0x47, 0x13, 0x05, 0x00, 0x02, 0x93, 0xe7,
0x17, 0x10, 0x5c, 0xc7, 0x31, 0xb7, 0xc9, 0x47, 0x23, 0x13, 0xf1, 0x02,
0x4d, 0xb7, 0x03, 0xc7, 0x1b, 0x00, 0xd1, 0x46, 0x63, 0xe7, 0xe6, 0x02,
0x85, 0x46, 0x63, 0xe6, 0xe6, 0x00, 0x01, 0x4c, 0x13, 0x04, 0xf0, 0x0f,
0x85, 0xa8, 0x79, 0x17, 0x13, 0x77, 0xf7, 0x0f, 0xc9, 0x46, 0xe3, 0xe8,
0xe6, 0xfe, 0xb7, 0x36, 0x85, 0x40, 0x0a, 0x07, 0x93, 0x86, 0x46, 0xbb,
0x36, 0x97, 0x18, 0x43, 0x02, 0x87, 0x93, 0x06, 0x07, 0x03, 0x93, 0xf6,
0xf6, 0x0f, 0x11, 0x46, 0xe3, 0x69, 0xd6, 0xfc, 0x13, 0x07, 0xf7, 0x02,
0x13, 0x77, 0xf7, 0x0f, 0x8d, 0x46, 0x63, 0xeb, 0xe6, 0x08, 0xb7, 0x36,
0x85, 0x40, 0x0a, 0x07, 0x93, 0x86, 0x06, 0xc0, 0x36, 0x97, 0x18, 0x43,
0x02, 0x87, 0x13, 0x07, 0x40, 0x02, 0x63, 0x98, 0xe7, 0x10, 0x02, 0xd4,
0x1d, 0x44, 0x01, 0x45, 0xa5, 0x34, 0x01, 0x45, 0x55, 0x3c, 0xf1, 0x36,
0xe9, 0x36, 0xa1, 0x45, 0x48, 0x10, 0x7d, 0x14, 0xd1, 0x3c, 0x75, 0xf4,
0x01, 0x4c, 0x01, 0x44, 0x13, 0x75, 0xf4, 0x0f, 0x71, 0x3c, 0x13, 0x75,
0xfc, 0x0f, 0x59, 0x3c, 0x7d, 0x36, 0xe3, 0x1e, 0x04, 0xea, 0x83, 0xc7,
0x1b, 0x00, 0x49, 0x47, 0x63, 0x68, 0xf7, 0x30, 0x09, 0x47, 0xe3, 0x76,
0xf7, 0xea, 0xf5, 0x17, 0x93, 0xf7, 0xf7, 0x0f, 0x3d, 0x47, 0xe3, 0x60,
0xf7, 0xea, 0x37, 0x37, 0x85, 0x40, 0x8a, 0x07, 0x13, 0x07, 0x07, 0xc1,
0xba, 0x97, 0x9c, 0x43, 0x82, 0x87, 0x05, 0x44, 0x9d, 0xeb, 0x70, 0x10,
0x81, 0x45, 0x01, 0x45, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x00, 0x71,
0x1d, 0xe1, 0xd1, 0x45, 0x68, 0x10, 0x9d, 0x3c, 0x01, 0x44, 0x31, 0xa8,
0x05, 0x44, 0x81, 0xef, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x00, 0x76,
0x33, 0x34, 0xa0, 0x00, 0x29, 0xa0, 0x21, 0x47, 0x63, 0x85, 0xe7, 0x00,
0x05, 0x44, 0x01, 0x4c, 0x61, 0xb7, 0x03, 0xac, 0x8b, 0x00, 0x03, 0xa4,
0xcb, 0x00, 0xb3, 0x67, 0x8c, 0x00, 0xd2, 0x07, 0xf5, 0xf7, 0xef, 0xf0,
0xbf, 0x85, 0x7d, 0xf1, 0xc1, 0x6c, 0x22, 0x9c, 0xfd, 0x1c, 0x7d, 0x7d,
0x33, 0x05, 0x8c, 0x40, 0x55, 0xdc, 0xb3, 0x77, 0x95, 0x01, 0x95, 0xe3,
0xc1, 0x6c, 0x33, 0x05, 0x8c, 0x40, 0x63, 0xe6, 0x8c, 0x02, 0xfd, 0x7c,
0x33, 0x05, 0x8c, 0x40, 0x55, 0xd0, 0x31, 0x81, 0x97, 0xf0, 0x7f, 0xff,
0xe7, 0x80, 0x80, 0x72, 0x55, 0xf9, 0x66, 0x94, 0xf5, 0xb7, 0x31, 0x81,
0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x80, 0x71, 0x55, 0xf1, 0x6a, 0x94,
0xd1, 0xb7, 0x41, 0x81, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0xc0, 0x70,
0x51, 0xf9, 0x33, 0x04, 0x94, 0x41, 0xc1, 0xb7, 0x21, 0x47, 0xe3, 0x89,
0xe7, 0xf0, 0x01, 0x4c, 0x13, 0x04, 0x00, 0x0c, 0x31, 0xb7, 0x41, 0x47,
0xcd, 0xbf, 0x41, 0x47, 0x05, 0x44, 0xe3, 0x9c, 0xe7, 0xf6, 0x83, 0xa5,
0xcb, 0x00, 0x03, 0xa5, 0x8b, 0x00, 0xe5, 0x32, 0xb1, 0xbf, 0x41, 0x47,
0x05, 0x44, 0xe3, 0x92, 0xe7, 0xf6, 0x03, 0xa7, 0x0b, 0x01, 0x91, 0x67,
0x63, 0xea, 0xe7, 0x1e, 0x83, 0xa5, 0x4b, 0x01, 0x03, 0xa5, 0x8b, 0x00,
0xef, 0xf0, 0xff, 0x80, 0x35, 0xbf, 0x41, 0x47, 0x05, 0x44, 0xe3, 0x92,
0xe7, 0xf4, 0x83, 0xa7, 0x0b, 0x01, 0x11, 0x67, 0x63, 0x6a, 0xf7, 0x1c,
0x03, 0xa7, 0xcb, 0x00, 0x83, 0xa5, 0x4b, 0x01, 0x03, 0xa5, 0x8b, 0x00,
0x33, 0x84, 0xe7, 0x02, 0xef, 0xf0, 0x6f, 0xfe, 0x23, 0xac, 0x04, 0x00,
0x23, 0x24, 0x8a, 0xb0, 0x31, 0xb7, 0x03, 0xc7, 0x04, 0x00, 0x63, 0x03,
0x07, 0x14, 0x03, 0xa7, 0x8b, 0x00, 0xc1, 0x17, 0x13, 0x04, 0x00, 0x0c,
0x63, 0x13, 0xf7, 0x00, 0xc0, 0x48, 0x01, 0x47, 0x93, 0x06, 0xf0, 0x0e,
0x63, 0x46, 0xf7, 0x02, 0x83, 0xc7, 0x5b, 0x00, 0x03, 0xc7, 0x4b, 0x00,
0x01, 0x4c, 0xa2, 0x07, 0xd9, 0x8f, 0x03, 0xc7, 0x6b, 0x00, 0x42, 0x07,
0x5d, 0x8f, 0x83, 0xc7, 0x7b, 0x00, 0xe2, 0x07, 0xd9, 0x8f, 0xe3, 0x81,
0xf6, 0xe6, 0x13, 0x04, 0x10, 0x0c, 0xa9, 0xbd, 0x33, 0x86, 0xeb, 0x00,
0x03, 0x46, 0x86, 0x01, 0x05, 0x07, 0xb1, 0x8e, 0xe1, 0xb7, 0x83, 0xc7,
0x04, 0x00, 0xfd, 0xc7, 0xdc, 0x44, 0x63, 0x9d, 0x07, 0x14, 0xc0, 0x48,
0x23, 0x80, 0x04, 0x00, 0x7d, 0xb5, 0x61, 0x47, 0x63, 0x96, 0xe7, 0x02,
0x83, 0xa7, 0xcb, 0x01, 0x03, 0xa7, 0x8b, 0x01, 0x83, 0xa6, 0x4b, 0x01,
0x03, 0xa6, 0x0b, 0x01, 0x83, 0xa5, 0xcb, 0x00, 0x03, 0xa5, 0x8b, 0x00,
0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x40, 0x61, 0x2a, 0x8c, 0x33, 0x34,
0xa0, 0x00, 0x29, 0xb5, 0x01, 0x4c, 0x05, 0x44, 0x11, 0xb5, 0x11, 0x47,
0x05, 0x44, 0xe3, 0x9a, 0xe7, 0xe6, 0xb7, 0x97, 0x00, 0x60, 0xb4, 0x5f,
0x65, 0x77, 0x7d, 0x17, 0x05, 0x66, 0xf9, 0x8e, 0xd1, 0x8e, 0x03, 0xa5,
0x8b, 0x00, 0xb4, 0xdf, 0xb4, 0x57, 0x81, 0x45, 0xf9, 0x8e, 0xd1, 0x8e,
0xb4, 0xd7, 0xf4, 0x5f, 0xf9, 0x8e, 0xd1, 0x8e, 0xf4, 0xdf, 0xf4, 0x53,
0x75, 0x8f, 0x51, 0x8f, 0xf8, 0xd3, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80,
0x20, 0x64, 0x29, 0xbd, 0x13, 0xf7, 0xf7, 0x00, 0xe3, 0x15, 0x07, 0xea,
0x93, 0xdc, 0x47, 0x00, 0x13, 0x84, 0x8b, 0x00, 0x01, 0x4c, 0x7d, 0x5d,
0xe3, 0x74, 0x9c, 0xdb, 0x48, 0x44, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80,
0x20, 0x48, 0x18, 0x44, 0x54, 0x40, 0x10, 0x40, 0xf9, 0x8e, 0x63, 0x07,
0xa7, 0x01, 0x1c, 0x42, 0x13, 0x47, 0xf7, 0xff, 0x7d, 0x8f, 0xd9, 0x8e,
0x14, 0xc2, 0x05, 0x0c, 0x41, 0x04, 0xd9, 0xbf, 0x11, 0x47, 0xa5, 0xb5,
0x41, 0x47, 0x05, 0x44, 0xe3, 0x97, 0xe7, 0xde, 0x83, 0xa7, 0x8b, 0x00,
0x03, 0xa7, 0x4b, 0x01, 0x23, 0x28, 0xf9, 0x00, 0x23, 0x26, 0xe9, 0x00,
0x75, 0xbb, 0x83, 0x25, 0xc9, 0x00, 0xc1, 0x17, 0x91, 0xe5, 0x89, 0xcf,
0x01, 0x4c, 0x13, 0x04, 0x60, 0x0c, 0x89, 0xbb, 0x03, 0x27, 0x09, 0x01,
0x63, 0x66, 0xf7, 0x06, 0x13, 0xf7, 0x37, 0x00, 0xe3, 0x19, 0x07, 0xe2,
0x03, 0x28, 0x09, 0x01, 0x01, 0x46, 0x01, 0x47, 0x33, 0x05, 0xe8, 0x40,
0xb3, 0x86, 0xe5, 0x00, 0x63, 0x69, 0xf7, 0x00, 0xe3, 0x04, 0x06, 0xd2,
0x23, 0x28, 0xa9, 0x00, 0x23, 0x26, 0xd9, 0x00, 0x31, 0xbb, 0x33, 0x86,
0xeb, 0x00, 0x10, 0x4e, 0x11, 0x07, 0x90, 0xc2, 0x05, 0x46, 0xe9, 0xbf,
0x21, 0x47, 0x05, 0x44, 0xe3, 0x91, 0xe7, 0xd8, 0x03, 0x24, 0x09, 0x01,
0x19, 0xc0, 0x13, 0x04, 0x80, 0x0c, 0x23, 0x28, 0x09, 0x00, 0x23, 0x26,
0x09, 0x00, 0x33, 0x34, 0x80, 0x00, 0xa5, 0xb3, 0x01, 0x4c, 0x13, 0x04,
0x20, 0x0c, 0xed, 0xb1, 0x01, 0x4c, 0x13, 0x04, 0x80, 0x0c, 0xcd, 0xb1,
0x01, 0x4c, 0x13, 0x04, 0x90, 0x0c, 0xe9, 0xb9, 0x13, 0x07, 0x20, 0x0d,
0x63, 0x83, 0xe7, 0x0c, 0x13, 0x07, 0x40, 0x0d, 0xe3, 0x9b, 0xe7, 0xb8,
0x03, 0xc4, 0x3b, 0x00, 0x83, 0xc7, 0x2b, 0x00, 0x22, 0x04, 0x5d, 0x8c,
0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x40, 0x47, 0x03, 0xac, 0xc4, 0x00,
0x41, 0x14, 0x63, 0x73, 0x84, 0x01, 0x22, 0x8c, 0xe3, 0x09, 0x0c, 0xb6,
0xc0, 0x40, 0x62, 0x94, 0x31, 0x80, 0x9c, 0x48, 0x63, 0x55, 0xf0, 0x00,
0x9c, 0x44, 0x63, 0x5b, 0xf4, 0x0a, 0xef, 0xf0, 0xaf, 0xcb, 0x75, 0xdd,
0xc8, 0x40, 0x62, 0x86, 0x93, 0x85, 0x8b, 0x01, 0x97, 0xf0, 0x7f, 0xff,
0xe7, 0x80, 0x40, 0x43, 0x01, 0xc5, 0x93, 0x07, 0x40, 0x0c, 0xdc, 0xc8,
0xdc, 0x40, 0xe2, 0x97, 0xdc, 0xc0, 0xdc, 0x44, 0xb3, 0x87, 0x87, 0x41,
0xdc, 0xc4, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0x20, 0x42, 0x25, 0xb6,
0x09, 0x65, 0x13, 0x05, 0x05, 0x71, 0x03, 0xac, 0xcb, 0x00, 0x03, 0xa4,
0x8b, 0x00, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80, 0xa0, 0x32, 0xb7, 0x07,
0x00, 0x60, 0xd8, 0x4b, 0xb7, 0x06, 0x00, 0x01, 0xc1, 0x16, 0x93, 0x57,
0x47, 0x01, 0x12, 0x07, 0x75, 0x8f, 0xbd, 0x8b, 0xd9, 0x8f, 0xb3, 0x87,
0x87, 0x03, 0x01, 0x45, 0xb3, 0xd5, 0x87, 0x02, 0x97, 0xf0, 0x7f, 0xff,
0xe7, 0x80, 0xc0, 0x33, 0x13, 0x05, 0x80, 0x3e, 0x97, 0xf0, 0x7f, 0xff,
0xe7, 0x80, 0x40, 0x2f, 0xe9, 0xbc, 0x83, 0xa6, 0x4b, 0x01, 0x03, 0xa6,
0x0b, 0x01, 0x83, 0xa5, 0xcb, 0x00, 0x03, 0xa5, 0x8b, 0x00, 0xef, 0xf0,
0xef, 0xfb, 0xd1, 0xb4, 0x83, 0xc5, 0x3b, 0x00, 0x83, 0xc7, 0x2b, 0x00,
0x13, 0x85, 0x8b, 0x01, 0xa2, 0x05, 0xdd, 0x8d, 0xc1, 0x15, 0xef, 0xf0,
0x8f, 0xd5, 0x75, 0xb4, 0xef, 0xf0, 0xef, 0xc4, 0x3d, 0xbf, 0x03, 0xc4,
0x3b, 0x00, 0x83, 0xc7, 0x2b, 0x00, 0x13, 0x8c, 0x8b, 0x01, 0x22, 0x04,
0x5d, 0x8c, 0xdc, 0x44, 0x41, 0x14, 0xcd, 0xe3, 0x91, 0x47, 0x85, 0x4b,
0x63, 0xff, 0x87, 0x08, 0x93, 0x07, 0x90, 0x0c, 0xdc, 0xc8, 0x41, 0xb4,
0x03, 0xa7, 0x0d, 0x00, 0x22, 0xd0, 0x05, 0x48, 0xb3, 0x87, 0xec, 0x40,
0x3e, 0xd6, 0x83, 0x27, 0x8a, 0xb0, 0x63, 0x73, 0xf4, 0x00, 0x0d, 0x48,
0x42, 0xc6, 0x3a, 0xc4, 0xef, 0xf0, 0x6f, 0xc0, 0x22, 0x47, 0x32, 0x48,
0x37, 0x85, 0x84, 0x40, 0xe2, 0x85, 0x7c, 0x10, 0x93, 0x86, 0x4a, 0x01,
0x10, 0x10, 0x13, 0x05, 0xc5, 0x02, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80,
0x20, 0x31, 0x37, 0xb7, 0x84, 0x40, 0x93, 0x08, 0x47, 0x01, 0x82, 0x57,
0x03, 0xa7, 0x88, 0xb0, 0x83, 0xa5, 0x0d, 0x00, 0x1d, 0x8c, 0x1d, 0x8f,
0x3e, 0x9c, 0xb2, 0x57, 0x23, 0xa4, 0xe8, 0xb0, 0xaa, 0x8b, 0xbe, 0x95,
0x23, 0xa0, 0xbd, 0x00, 0x93, 0x87, 0x4a, 0x01, 0x9d, 0x8d, 0x01, 0xc5,
0xa1, 0x67, 0x63, 0x97, 0xf5, 0x00, 0x5a, 0x85, 0xef, 0xf0, 0x2f, 0xcb,
0x23, 0xa0, 0x6d, 0x01, 0x09, 0xc4, 0xdc, 0x44, 0x99, 0xc3, 0xe3, 0x4f,
0x70, 0xf7, 0x63, 0xdf, 0x0b, 0x00, 0x93, 0x07, 0x70, 0x0c, 0xbd, 0xb7,
0x85, 0x4b, 0xb7, 0x3d, 0x85, 0x40, 0xb7, 0x8c, 0x84, 0x40, 0x93, 0x8d,
0x0d, 0xbb, 0x93, 0x8c, 0x4c, 0x01, 0xe9, 0xbf, 0xe3, 0x9d, 0x0b, 0x9c,
0xdc, 0x44, 0xe3, 0x8a, 0x07, 0x9c, 0x93, 0x07, 0x80, 0x0c, 0xa9, 0xb7,
0x83, 0xa7, 0x8b, 0x00, 0xe3, 0x93, 0x07, 0x9c, 0xef, 0xf0, 0x2f, 0xd3,
0x09, 0x65, 0x13, 0x05, 0x05, 0x71, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80,
0xa0, 0x1c, 0xef, 0xf0, 0xaf, 0xce, 0x97, 0xf0, 0x7f, 0xff, 0xe7, 0x80,
0xe0, 0x20, 0x55, 0xb2, 0x03, 0xa4, 0xcb, 0x00, 0xe3, 0x0f, 0x04, 0x98,
0xef, 0xf0, 0xaf, 0xd0, 0x13, 0x05, 0x80, 0x3e, 0x97, 0xf0, 0x7f, 0xff,
0xe7, 0x80, 0x40, 0x1a, 0xef, 0xf0, 0x4f, 0xcc, 0x02, 0x94, 0x51, 0xb2,
0xef, 0xf0, 0xcf, 0xcb, 0xf6, 0x50, 0x66, 0x54, 0xd6, 0x54, 0x46, 0x59,
0xb6, 0x59, 0x26, 0x5a, 0x96, 0x5a, 0x06, 0x5b, 0xf6, 0x4b, 0x66, 0x4c,
0xd6, 0x4c, 0x46, 0x4d, 0xb6, 0x4d, 0x09, 0x61, 0x82, 0x80, 0x00, 0x00,
};
const esp32_stub_loader_t stub_esp32c6 = {
.chip_detect = 0x2ce0806f,
.entry = 0x408006c4,
.text_start = 0x40800000,
.text_length = 3792,
.text = _stub_esp32c6_text,
.data_start = 0x40852bb0,
.data_length = 160,
.data = _stub_esp32c6_data,
.chip_name = "ESP32C6",
};
const esp32_stub_loader_t *stub_esp_arr[] = {
&stub_esp32, &stub_esp32s2, &stub_esp32s3, &stub_esp8266, &stub_esp32c6,
}; };

View file

@ -1,7 +1,21 @@
import sys
import zlib import zlib
import hashlib import hashlib
from pathlib import Path from pathlib import Path
import click import os.path
output_header = 'esp_binaries.h'
# Argument is path to folder containing .bin files
# This script will create .bin.gz file with the same name to the folder
# and also print out C array of the gz along with MD5 checksum
dir = ''
if len(sys.argv) == 1:
print("No [DIRS] arguments, use current directory as default")
dir = Path('./')
else:
# only take 1 argument
dir = Path(sys.argv[1])
def print_carray(f, payload): def print_carray(f, payload):
while len(payload) > 0: while len(payload) > 0:
@ -11,31 +25,19 @@ def print_carray(f, payload):
payload = payload[16:] payload = payload[16:]
f.write('\n') f.write('\n')
with open(output_header, 'w') as fc:
@click.command()
@click.argument('dpath', type=click.Path(exists=True), default='.')
@click.option('--sd', is_flag=True, default=False, help='Generate header for using with SDCard')
def main(dpath, sd):
"""
This script takes a directory path (default is current directory) and
create compressed .bin.gz file along 'esp_binaries.h' containing metadata in esp32_zipfile_t struct.
Which can be used to program ESP32 with TestBed or Brain.
If '--sd' option is specified, it will skip generating C array data for gz file.
"""
output_header = 'esp_binaries.h'
with open(output_header, 'w') as fc:
# print typedef struct # print typedef struct
fc.write('// Generated by tools/esp_compress.py\n') fc.write('// Generated by tools/esp_compress.py\n')
file_list = sorted(Path(dpath).glob('*.bin')) file_list = sorted(dir.glob('*.bin'))
fc.write(f'#define ESP_BINARIES_COUNT ({len(file_list)})\n\n') fc.write('#define ESP_BINARIES_COUNT ({})\n\n'.format(len(file_list)))
# print list of struct first # print list of struct first
for fname in file_list: for fname in file_list:
var = fname.stem var = fname.stem
var = var.replace('.', '_') var = var.replace('.', '_')
var = var.replace('-', '_') var = var.replace('-', '_')
fc.write(f'// const esp32_zipfile_t {var}\n') fc.write('// const esp32_zipfile_t {}\n'.format(var))
fc.write('\n') fc.write('\n'.format(var))
for fname in file_list: for fname in file_list:
with open(fname, 'rb') as fi: with open(fname, 'rb') as fi:
@ -54,28 +56,19 @@ def main(dpath, sd):
var = var.replace('-', '_') var = var.replace('-', '_')
# bin gz contents # bin gz contents
if not sd: fc.write('const uint8_t _{}_gz[{}] = {{'.format(var, len(zimage)))
fc.write(f'const uint8_t _{var}_gz[{len(zimage)}] = {{')
print_carray(fc, zimage) print_carray(fc, zimage)
fc.write('};\n\n') fc.write('};\n\n')
fc.write(f'const esp32_zipfile_t {var} = {{\n') fc.write('const esp32_zipfile_t {} = {{\n'.format(var))
fc.write(f' .name = "{fzname}",\n') fc.write(' .name = "{}",\n'.format(var))
if sd: fc.write(' .data = _{}_gz,\n'.format(var))
fc.write(f' .data = NULL,\n') fc.write(' .compressed_len = {},\n'.format(len(zimage)))
else: fc.write(' .uncompressed_len = {},\n'.format(len(image)))
fc.write(f' .data = _{var}_gz,\n')
fc.write(f' .compressed_len = {len(zimage)},\n')
fc.write(f' .uncompressed_len = {len(image)},\n')
fc.write(' .md5 = {') fc.write(' .md5 = {')
print_carray(fc, md5.digest()) print_carray(fc, md5.digest())
fc.write(' },\n') fc.write(' },\n')
fc.write('};\n') fc.write('};\n')
fc.write('\n') fc.write('\n')
deflation = 100*(1-len(zimage)/len(image)) print("Compressed {}: {} to {} bytes, deflation: {:.2f}%".format(var, len(image), len(zimage), 100*(1-len(zimage)/len(image))))
print(f"Compressed {var}: {len(image)} to {len(zimage)} bytes, deflation: {deflation:.2f}%")
if __name__ == '__main__':
main()

File diff suppressed because one or more lines are too long

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python3
import argparse
import random
import os
import sys
import time
import subprocess
from pathlib import Path
from multiprocessing import Pool
from weakref import finalize
def print_carray(f, payload):
while len(payload) > 0:
f.write('\n ')
f.write(', '.join('0x{:02x}'.format(x) for x in payload[0:16]))
f.write(',')
payload = payload[16:]
f.write('\n')
def main():
parser = argparse.ArgumentParser(description='Convert binary files to C array format')
parser.add_argument('files', nargs='+', help='Binary files to convert')
args = parser.parse_args()
files = args.files
for fin_name in files:
if not os.path.isfile(fin_name):
print(f"File {fin_name} does not exist")
continue
with open(fin_name, 'rb') as fin:
contents = fin.read()
fout_name = fin_name + '.h'
with open(fout_name, 'w') as fout:
print(f"Converting {fin_name} to {fout_name}")
fout.write(f'const size_t bindata_len = {len(contents)};\n')
fout.write(f'const uint8_t bindata[] __attribute__((aligned(16))) = {{')
print_carray(fout, contents)
fout.write('};\n')
if __name__ == '__main__':
sys.exit(main())