Skip to content

Commit

Permalink
Merge pull request #24 from adafruit/add-8266-binary
Browse files Browse the repository at this point in the history
Add 8266 binary
  • Loading branch information
hathach authored Jan 9, 2024
2 parents 38c0a28 + 87f1fa0 commit f13cdaa
Show file tree
Hide file tree
Showing 22 changed files with 16,381 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define ESP_BINARIES_H_

// Configuration: select which bins to flash
#define BIN_FILES BIN_DEVKIT_S3
#define BIN_FILES BIN_FEATHER_8266_BLINKY

//--------------------------------------------------------------------+
// LIST OF BINARIES
Expand All @@ -44,6 +44,8 @@
#define BIN_DEVKIT_S2 20 // Espressif s2 devkit
#define BIN_DEVKIT_S3 21 // Espressif s3 devkit

#define BIN_FEATHER_8266_BLINKY 30 // Feather esp8266 blinky sketch

//--------------------------------------------------------------------+
// Binaries include
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -72,6 +74,9 @@
#elif BIN_FILES == BIN_DEVKIT_S3
#include "esp_binaries/esp32s3_devkit_binaries.h"

#elif BIN_FILES == BIN_FEATHER_8266_BLINKY
#include "esp_binaries/feather_esp8266_blinky.h"

#endif

struct {
Expand Down Expand Up @@ -119,6 +124,12 @@ struct {
{0x8000, &Blink_ino_partitions},
{0xe000, &boot_app0},
{0x10000, &Blink_ino},

#elif BIN_FILES == BIN_FEATHER_8266_BLINKY
{0x0000, &Blink_ino},

#else
#error bin_files[] not defined
#endif
};

Expand Down
16,347 changes: 16,347 additions & 0 deletions examples/Brain/program_esp_cdc/esp_binaries/feather_esp8266_blinky.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,25 @@

// Note: baudrate does not matter if programming S2/S3 native USB
// But does matter if programming ESP32/8266 via USB-to-UART chip
#define ESP32_BAUDRATE 921600
#define ESP32_BAUDRATE (115200*8)

// CDC Host object
Adafruit_USBH_CDC SerialHost;
Adafruit_USBH_CDC SerialHost;

#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
ESP32BootROMClass ESP32BootROM(SerialHost, ESP32_IO0, ESP32_RESET);

// Declare BootROM with IO0 and Reset will use GPIO for bootloader reset
// This is typically for programming ESP32-S2/S3 via native USB
ESP32BootROMClass ESP32BootROM(SerialHost, ESP32_IO0, ESP32_RESET);
#else

// Defined an boot rom object that use SerialHost
// Declare BootROM without IO0 and Reset will use SerialHost.setDtrRts() for bootloader reset
// This is for programming ESP32/8266 via USB-to-UART chip such as FTDI/CP210x/CH9102f
ESP32BootROMClass ESP32BootROM(SerialHost);

// Defined an boot rom object that use SerialHost
// Declare BootROM without IO0 and Reset will use SerialHost.setDtrRts() for bootloader reset
// This is for programming ESP32/8266 via USB-to-UART chip such as FTDI/CP210x/CH9102f
ESP32BootROMClass ESP32BootROM(SerialHost);
#endif


//--------------------------------------------------------------------+
// 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;
Expand All @@ -78,14 +72,14 @@ void setup() {
// 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) ) {
while (!Brain.esp32_begin(&ESP32BootROM, ESP32_BAUDRATE)) {
delay(100);
}

// Writing bin files
size_t total_bytes = 0;
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);
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);
Expand Down Expand Up @@ -128,7 +122,7 @@ void setup1() {

// core1's loop: process usb host task on core1
void loop1() {
if ( Brain.esp32_s3_inReset() ){
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
Expand All @@ -144,7 +138,7 @@ void loop1() {
Brain.USBHost.task();

// periodically flush SerialHost if connected
if ( SerialHost && SerialHost.connected() ) {
if (SerialHost && SerialHost.connected()) {
SerialHost.flush();
}

Expand All @@ -155,11 +149,10 @@ void loop1() {
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
extern "C" {
extern "C" {

// Invoked when device is mounted (configured)
void tuh_mount_cb (uint8_t daddr)
{
void tuh_mount_cb(uint8_t daddr) {
uint16_t vid, pid;
tuh_vid_pid_get(daddr, &vid, &pid);

Expand All @@ -168,8 +161,7 @@ void tuh_mount_cb (uint8_t daddr)
}

/// 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;
Brain.LCD_printf(1, "No USB Device");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void setup() {

// 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) ) {
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++) {
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);
Expand Down Expand Up @@ -93,7 +93,7 @@ void setup1() {

// core1's loop: process usb host task on core1
void loop1() {
if ( Brain.esp32_s3_inReset() ){
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
Expand All @@ -114,11 +114,10 @@ void loop1() {
// TinyUSB Host callbacks
// Note: running in the same core where Brain.USBHost.task() is called
//--------------------------------------------------------------------+
extern "C" {
extern "C" {

// Invoked when device is mounted (configured)
void tuh_mount_cb (uint8_t daddr)
{
void tuh_mount_cb(uint8_t daddr) {
uint16_t vid, pid;
tuh_vid_pid_get(daddr, &vid, &pid);

Expand All @@ -127,8 +126,7 @@ void tuh_mount_cb (uint8_t daddr)
}

/// 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;
Brain.LCD_printf(1, "No USB Device");
}
Expand Down
2 changes: 0 additions & 2 deletions src/ESP32BootROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,12 @@ uint32_t ESP32BootROMClass::begin(unsigned long baudrate) {
resetBootloader();

bool synced = false;

for (int retries = 0; !synced && (retries < 5); retries++) {
Serial.println("Trying to sync");
synced = sync();
if (synced) {
break;
}

delay(10);
}
if (!synced) {
Expand Down

0 comments on commit f13cdaa

Please sign in to comment.