Skip to content

Commit b8cddae

Browse files
committed
wip: huzzah tweaks n map files
1 parent 15f49c8 commit b8cddae

File tree

7 files changed

+202219
-15
lines changed

7 files changed

+202219
-15
lines changed

examples/Wippersnapper_demo/Wippersnapper_demo.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// Brent Rubell for Adafruit Industries, 2021-2022
1313
//
1414
// All text above must be included in any redistribution.
15+
#include <GDBStub.h> // Include GDB Stub for debugging esp8266
1516

1617
#include "Wippersnapper_Networking.h"
1718
Wippersnapper_WiFi wipper;
@@ -20,13 +21,25 @@ Wippersnapper_WiFi wipper;
2021
#define WS_DEBUG
2122

2223
void setup() {
24+
pinMode(LED_BUILTIN, OUTPUT);
25+
digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED
26+
delay(500);
27+
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED
2328
// Provisioning must occur prior to serial init.
2429
wipper.provision();
25-
30+
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED
2631
Serial.begin(115200);
27-
//while (!Serial) delay(10);
32+
digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED
33+
delay(1000);
34+
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED
35+
WS_DEBUG_PRINTLN("WipperSnapper Demo Starting...");
36+
delay(500);
37+
digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED
38+
// while (!Serial) delay(10);
39+
gdbstub_init();
2840

2941
wipper.connect();
42+
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED
3043

3144
}
3245

output.map

Lines changed: 69851 additions & 0 deletions
Large diffs are not rendered by default.

output_8266.map

Lines changed: 62368 additions & 0 deletions
Large diffs are not rendered by default.

output_8266_debug.map

Lines changed: 69856 additions & 0 deletions
Large diffs are not rendered by default.

platformio.ini

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
; PlatformIO Defaults
77
[platformio]
88
description = "Adafruit.IO WipperSnapper Firmware"
9-
default_envs = adafruit_feather_esp32s3_tft, adafruit_magtag29_esp32s2, adafruit_feather_esp32s3, featheresp32s2, adafruit_feather_esp32s2_reversetft, adafruit_metro_esp32s2, adafruit_qtpy_esp32s2, adafruit_feather_esp32s3_reversetft, adafruit_feather_esp32s3_nopsram, adafruit_feather_esp32s2_tft, adafruit_qtpy_esp32, adafruit_qtpy_esp32c3, featheresp32, adafruit_qtpy_esp32s3_nopsram, featheresp32v2, huzzah, adafruit_pyportal_m4, adafruit_pyportal_m4_titano, dfrobot_beetle_esp32c3
9+
default_envs = adafruit_feather_esp32s3_tft, adafruit_magtag29_esp32s2, adafruit_feather_esp32s3, featheresp32s2, adafruit_feather_esp32s2_reversetft, adafruit_metro_esp32s2, adafruit_qtpy_esp32s2, adafruit_feather_esp32s3_reversetft, adafruit_feather_esp32s3_nopsram, adafruit_feather_esp32s2_tft, adafruit_qtpy_esp32, adafruit_qtpy_esp32c3, featheresp32, adafruit_qtpy_esp32s3_nopsram, featheresp32v2, huzzah_esp8266, adafruit_pyportal_m4, adafruit_pyportal_m4_titano, dfrobot_beetle_esp32c3
1010

1111

1212
; Common Build Environment
@@ -490,29 +490,61 @@ extra_scripts = pre:rename_usb_config.py
490490
; ESP8266 Boards
491491

492492
; Adafruit Feather HUZZAH ESP8266
493-
[env:huzzah]
493+
[env:huzzah_esp8266]
494494
extends=common:esp8266
495495
board = huzzah
496496
board_build.f_cpu = 80000000L
497497
; Arduino CLI uses this from adafruit_ci#ci-wippersnapper
498498
; esp8266:esp8266:huzzah:xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200
499499
build_flags =
500500
-Wl,--gc-sections
501-
-Wl,-Map=output.map
501+
-Wl,-Map=output_8266.map
502+
-DARDUINO_ESP8266_ADAFRUIT_HUZZAH
503+
; -DDEBUG_ESP_PORT=None
504+
-DVTABLES_IN_FLASH
505+
-DNO_EXCEPTIONS
506+
-DNO_STACK_SMASH_PROTECTION
507+
-DSSL_BASIC
508+
; -DSSL_ALL
509+
-DMMU_4816
510+
-DNON32XFER_FAST
511+
-DDEBUG_DISABLED
512+
-DDEBUG_LEVEL_NONE
513+
-DNDEBUG
514+
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48 ; avoid section `.text1' will not fit in region `iram1_0_seg'
515+
board_build.eesz=4M2M
516+
board_build.filesystem = littlefs
517+
upload_port = COM29
518+
monitor_filters = esp8266_exception_decoder
519+
520+
521+
; Adafruit Feather HUZZAH ESP8266 Debug
522+
[env:huzzah_esp8266_debug]
523+
extends=common:esp8266
524+
board = huzzah
525+
board_build.f_cpu = 80000000L
526+
build_type = debug
527+
; Arduino CLI uses this from adafruit_ci#ci-wippersnapper
528+
; esp8266:esp8266:huzzah:xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=4816,non32xfer=fast,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200
529+
build_flags =
530+
-Wl,--gc-sections
531+
-Wl,-Map=output_8266_debug.map
502532
-DARDUINO_ESP8266_ADAFRUIT_HUZZAH
503533
-DDEBUG_ESP_PORT=Serial
504534
-DVTABLES_IN_FLASH
505535
-DNO_EXCEPTIONS
506536
-DNO_STACK_SMASH_PROTECTION
507537
-DSSL_ALL
508-
-DMMU_3232
538+
-DMMU_4816
509539
-DNON32XFER_FAST
510-
-DDEBUG_DISABLED
540+
-DDEBUG_ENABLED
511541
-DDEBUG_LEVEL_NONE
512542
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48 ; avoid section `.text1' will not fit in region `iram1_0_seg'
513543
board_build.eesz=4M2M
514544
board_build.filesystem = littlefs
515-
upload_port = COM19
545+
upload_port = COM29
546+
monitor_filters = esp8266_exception_decoder
547+
516548

517549
; SAMD51 Boards ;
518550

src/Wippersnapper.cpp

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void Wippersnapper::provision() {
113113
_fileSystem->parseSecrets();
114114
#elif defined(USE_LITTLEFS)
115115
_littleFS->parseSecrets();
116+
117+
// ESP8266 stability: ensure LittleFS is fully unmounted and not referenced
118+
// during WiFi/MQTT connect (flash operations can interfere with WiFi).
119+
delete _littleFS;
120+
_littleFS = NULL;
116121
#else
117122
set_user_key(); // non-fs-backed, sets global credentials within network iface
118123
#endif
@@ -2338,17 +2343,17 @@ bool Wippersnapper::generateWSTopics() {
23382343
WS._config.aio_user, _device_uid, TOPIC_SIGNALS, TOPIC_DISPLAY);
23392344
} else {
23402345
WS_DEBUG_PRINTLN(
2341-
"FATAL ERROR: Failed to allocate memory for DISPLAY topic!");
2346+
"FATAL ERROR: Failed to allocate memory for b2d DISPLAY topic!");
23422347
return false;
23432348
}
23442349

23452350
// Subscribe to signal's DISPLAY sub-topic and set callback
23462351
_topic_signal_display_sub =
23472352
new Adafruit_MQTT_Subscribe(WS._mqtt, WS._topic_signal_display_brkr, 1);
2348-
WS_DEBUG_PRINTLN("Subscribing to DISPLAY topic: ");
2353+
WS_DEBUG_PRINTLN("Subscribing to b2d DISPLAY topic: ");
23492354
WS_DEBUG_PRINTLN(WS._topic_signal_display_brkr);
23502355
WS._mqtt->subscribe(_topic_signal_display_sub);
2351-
WS_DEBUG_PRINTLN("Subscribed to DISPLAY topic!");
2356+
WS_DEBUG_PRINTLN("Subscribed to b2d DISPLAY topic!");
23522357
_topic_signal_display_sub->setCallback(cbDisplayMessage);
23532358

23542359
// Calculate length of the topic for device-to-broker DISPLAY topic
@@ -2370,7 +2375,7 @@ bool Wippersnapper::generateWSTopics() {
23702375
TOPIC_SIGNALS, TOPIC_DISPLAY);
23712376
} else {
23722377
WS_DEBUG_PRINTLN(
2373-
"FATAL ERROR: Failed to allocate memory for DISPLAY topic!");
2378+
"FATAL ERROR: Failed to allocate memory for d2b DISPLAY topic!");
23742379
return false;
23752380
}
23762381

@@ -2553,6 +2558,11 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
25532558
WS.feedWDT(); // feed the WDT for the first X-5 seconds
25542559
} else if (i == seconds_until_reboot) {
25552560
WS.enableWDT(wdt_timeout_ms);
2561+
#ifdef ARDUINO_ARCH_ESP8266
2562+
// On ESP8266, explicitly restart as well. In some configurations the WDT
2563+
// may not reliably trigger if other system timers keep feeding it.
2564+
ESP.restart();
2565+
#endif
25562566
}
25572567
}
25582568
}
@@ -2771,6 +2781,15 @@ void printDeviceInfo() {
27712781
WS._macAddr[2], WS._macAddr[3], WS._macAddr[4], WS._macAddr[5]);
27722782
WS_DEBUG_PRINT("MAC Address: ");
27732783
WS_DEBUG_PRINTLN(sMAC);
2784+
2785+
#ifdef ARDUINO_ARCH_ESP8266
2786+
WS_DEBUG_PRINT("Free heap: ");
2787+
WS_DEBUG_PRINTLN(ESP.getFreeHeap());
2788+
WS_DEBUG_PRINT("Max free block: ");
2789+
WS_DEBUG_PRINTLN(ESP.getMaxFreeBlockSize());
2790+
WS_DEBUG_PRINT("Heap fragmentation (%): ");
2791+
WS_DEBUG_PRINTLN(ESP.getHeapFragmentation());
2792+
#endif
27742793
WS_DEBUG_PRINTLN("-------------------------------");
27752794

27762795
// (ESP32-Only) Print reason why device was reset
@@ -2798,6 +2817,62 @@ void Wippersnapper::connect() {
27982817
haltError("Unable to generate Device UID");
27992818
}
28002819

2820+
#ifdef ARDUINO_ARCH_ESP8266
2821+
// ESP8266 has very limited heap and WiFi scans/connect need a large
2822+
// contiguous block. Connect WiFi first before allocating MQTT topics.
2823+
WS_DEBUG_PRINTLN("Running WiFi connect (ESP8266 pre-MQTT)...");
2824+
WS_DEBUG_PRINT("Free heap before WiFi connect: ");
2825+
WS_DEBUG_PRINTLN(ESP.getFreeHeap());
2826+
WS_DEBUG_PRINT("Max free block before WiFi connect: ");
2827+
WS_DEBUG_PRINTLN(ESP.getMaxFreeBlockSize());
2828+
WS_DEBUG_PRINT("Heap fragmentation before WiFi connect (%): ");
2829+
WS_DEBUG_PRINTLN(ESP.getHeapFragmentation());
2830+
2831+
#if defined(USE_LITTLEFS)
2832+
// Extra safety: ensure LittleFS is not mounted during WiFi/MQTT connect.
2833+
LittleFS.end();
2834+
#endif
2835+
2836+
if (networkStatus() != WS_NET_CONNECTED) {
2837+
WS_DEBUG_PRINTLN("Establishing network connection...");
2838+
WS_PRINTER.flush();
2839+
WS_DEBUG_PRINT("Performing a WiFi scan for SSID...");
2840+
if (!check_valid_ssid()) {
2841+
haltError("ERROR: Unable to find WiFi network, rebooting soon...",
2842+
WS_LED_STATUS_WIFI_CONNECTING);
2843+
}
2844+
2845+
int maxAttempts = 5;
2846+
while (maxAttempts > 0) {
2847+
statusLEDBlink(WS_LED_STATUS_WIFI_CONNECTING);
2848+
feedWDT();
2849+
WS_DEBUG_PRINT("Connecting to WiFi (attempt #");
2850+
WS_DEBUG_PRINT(5 - maxAttempts);
2851+
WS_DEBUG_PRINTLN(")");
2852+
WS_PRINTER.flush();
2853+
feedWDT();
2854+
_connect();
2855+
feedWDT();
2856+
if (networkStatus() == WS_NET_CONNECTED)
2857+
break;
2858+
maxAttempts--;
2859+
}
2860+
2861+
if (networkStatus() != WS_NET_CONNECTED) {
2862+
WS_DEBUG_PRINTLN("ERROR: Unable to connect to WiFi!");
2863+
haltError("ERROR: Unable to connect to WiFi, rebooting soon...",
2864+
WS_LED_STATUS_WIFI_CONNECTING);
2865+
}
2866+
}
2867+
2868+
WS_DEBUG_PRINT("Free heap after WiFi connect: ");
2869+
WS_DEBUG_PRINTLN(ESP.getFreeHeap());
2870+
WS_DEBUG_PRINT("Max free block after WiFi connect: ");
2871+
WS_DEBUG_PRINTLN(ESP.getMaxFreeBlockSize());
2872+
WS_DEBUG_PRINT("Heap fragmentation after WiFi connect (%): ");
2873+
WS_DEBUG_PRINTLN(ESP.getHeapFragmentation());
2874+
#endif
2875+
28012876
// Initialize MQTT client with device identifier
28022877
setupMQTTClient(_device_uid);
28032878

@@ -2810,9 +2885,17 @@ void Wippersnapper::connect() {
28102885
haltError("Unable to allocate space for MQTT error topics");
28112886
}
28122887

2813-
// Connect to Network
2888+
#ifdef ARDUINO_ARCH_ESP8266
2889+
WS_DEBUG_PRINT("Heap after topic allocation: ");
2890+
WS_DEBUG_PRINTLN(ESP.getFreeHeap());
2891+
WS_DEBUG_PRINT("Max free block after topic allocation: ");
2892+
WS_DEBUG_PRINTLN(ESP.getMaxFreeBlockSize());
2893+
WS_DEBUG_PRINT("Heap fragmentation after topic allocation (%): ");
2894+
WS_DEBUG_PRINTLN(ESP.getHeapFragmentation());
2895+
#endif
2896+
2897+
// Connect to Network + MQTT
28142898
WS_DEBUG_PRINTLN("Running Network FSM...");
2815-
// Run the network fsm
28162899
runNetFSM();
28172900

28182901
// Enable WDT after wifi connection as wifiMulti doesnt feed WDT

src/Wippersnapper_demo.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Brent Rubell for Adafruit Industries, 2021-2022
1313
//
1414
// All text above must be included in any redistribution.
15-
15+
// #include <GDBStub.h> // Include GDB Stub for debugging esp8266
1616
#include "Wippersnapper_Networking.h"
1717
Wippersnapper_WiFi wipper;
1818

@@ -25,6 +25,7 @@ void setup() {
2525

2626
Serial.begin(115200);
2727
// while (!Serial) delay(10);
28+
// gdbstub_init();
2829

2930
wipper.connect();
3031

0 commit comments

Comments
 (0)