Skip to content

Commit f46c204

Browse files
committed
Merge remote-tracking branch 'tyeth/tinyusb-reattach-print-reset-time' into uat-xmas2024
2 parents 418e785 + b594a3b commit f46c204

File tree

4 files changed

+75
-23
lines changed

4 files changed

+75
-23
lines changed

platformio.ini

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ framework = arduino
1616
monitor_speed = 115200
1717
lib_compat_mode = strict
1818
lib_deps =
19+
;;;;;;;;;;; FunHouse / LVGL Boards uncomment these ;;;;;;;;;;;;;;
20+
; https://github.com/adafruit/Adafruit_HX8357_Library.git
21+
; https://github.com/adafruit/Adafruit_ILI9341.git
22+
; https://github.com/adafruit/Adafruit_STMPE610.git
23+
; https://github.com/adafruit/Adafruit-ST7735-Library.git
24+
; https://github.com/adafruit/Adafruit_TouchScreen.git
25+
; https://github.com/brentru/lvgl.git#wippersnapper
26+
; https://github.com/brentru/Adafruit_LvGL_Glue.git#development
27+
;;;;;;;;;;; All Boards need these libraries included ;;;;;;;;;;;;;;
1928
adafruit/Adafruit Zero DMA Library
20-
https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
2129
adafruit/Adafruit NeoPixel
2230
adafruit/Adafruit SPIFlash
2331
adafruit/Adafruit DotStar
@@ -78,14 +86,8 @@ lib_deps =
7886
https://github.com/Sensirion/arduino-i2c-sen5x.git
7987
https://github.com/adafruit/WiFiNINA.git
8088
https://github.com/Starmbi/hp_BH1750.git
81-
;;;;;;;;;;; FunHouse / LVGL Boards ;;;;;;;;;;;;;;
82-
https://github.com/adafruit/Adafruit_HX8357_Library.git
83-
https://github.com/adafruit/Adafruit_ILI9341.git
84-
https://github.com/adafruit/Adafruit_STMPE610.git
85-
https://github.com/adafruit/Adafruit-ST7735-Library.git
86-
https://github.com/adafruit/Adafruit_TouchScreen.git
87-
https://github.com/brentru/lvgl.git#wippersnapper
88-
https://github.com/brentru/Adafruit_LvGL_Glue.git#development
89+
https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
90+
8991

9092

9193
; Common build environment for ESP32 platform
@@ -107,9 +109,10 @@ platform = atmelsam
107109
platform_packages =
108110
platformio/framework-arduino-samd-adafruit@^1.7.13
109111
platformio/tool-jlink@^1.78811.0
110-
lib_ldf_mode = deep
112+
lib_ldf_mode = chain+
113+
lib_compat_mode = strict
111114
lib_archive = no ; debug timer issues see https://community.platformio.org/t/choose-usb-stack-as-tiny-usb/22451/5
112-
lib_ignore = OneWire
115+
lib_ignore = OneWire, USBHost
113116

114117
[common:rp2040]
115118
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#develop
@@ -408,7 +411,23 @@ extra_scripts = pre:rename_usb_config.py
408411
[env:huzzah]
409412
extends=common:esp8266
410413
board = huzzah
411-
build_flags = -DARDUINO_ESP8266_ADAFRUIT_HUZZAH
414+
board_build.f_cpu = 80000000L
415+
; Arduino CLI uses this from adafruit_ci#ci-wippersnapper
416+
; 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
417+
build_flags =
418+
-Wl,--gc-sections
419+
-Wl,-Map=output.map
420+
-DARDUINO_ESP8266_ADAFRUIT_HUZZAH
421+
-DDEBUG_ESP_PORT=Serial
422+
-DVTABLES_IN_FLASH
423+
-DNO_EXCEPTIONS
424+
-DNO_STACK_SMASH_PROTECTION
425+
-DSSL_ALL
426+
-DMMU_3232
427+
-DNON32XFER_FAST
428+
-DDEBUG_DISABLED
429+
-DDEBUG_LEVEL_NONE
430+
board_build.eesz=4M2M
412431
board_build.filesystem = littlefs
413432
upload_port = /dev/cu.SLAB_USBtoUART
414433

@@ -418,8 +437,9 @@ upload_port = /dev/cu.SLAB_USBtoUART
418437
[env:adafruit_pyportal_m4]
419438
extends = common:atsamd
420439
board = adafruit_pyportal_m4
421-
build_flags = -DUSE_TINYUSB=1
440+
build_flags = -DUSE_TINYUSB
422441
-DADAFRUIT_PYPORTAL
442+
extra_scripts = pre:rename_usb_config.py
423443

424444
; Adafruit PyPortal M4 Titano
425445
[env:adafruit_pyportal_m4_titano]
@@ -463,8 +483,9 @@ build_flags = -DUSE_TINYUSB
463483
[env:adafruit_metro_m4_airliftlite]
464484
extends = common:atsamd
465485
board = adafruit_metro_m4_airliftlite
466-
build_flags = -DUSE_TINYUSB=1
486+
build_flags = -DUSE_TINYUSB
467487
-DADAFRUIT_METRO_M4_AIRLIFT_LITE
488+
; extra_scripts = pre:rename_usb_config.py
468489
upload_port = /dev/cu.usbmodem1201
469490

470491

src/Wippersnapper.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,14 +2494,27 @@ void Wippersnapper::runNetFSM() {
24942494
@brief Prints an error to the serial and halts the hardware until
24952495
the WDT bites.
24962496
@param error
2497-
The desired error to print to serial.
2497+
The error to print to serial.
24982498
@param ledStatusColor
2499-
The desired color to blink.
2499+
The color to blink.
2500+
@param seconds_until_reboot
2501+
The amount of time to wait before rebooting.
25002502
*/
25012503
/**************************************************************************/
2502-
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
2503-
for (;;) {
2504-
WS_DEBUG_PRINT("ERROR [WDT RESET]: ");
2504+
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
2505+
uint8_t seconds_until_reboot) {
2506+
#ifdef ARDUINO_ARCH_ESP8266
2507+
uint8_t wdt_timeout_ms = 3200;
2508+
#else
2509+
uint8_t wdt_timeout_ms = 5000;
2510+
#endif
2511+
int seconds_until_wdt_enable =
2512+
seconds_until_reboot - (int)(wdt_timeout_ms / 1000);
2513+
2514+
for (int i = 0;; i++) {
2515+
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
2516+
WS_DEBUG_PRINT(seconds_until_reboot - i);
2517+
WS_DEBUG_PRINTLN("]: ");
25052518
WS_DEBUG_PRINTLN(error);
25062519
// let the WDT fail out and reset!
25072520
statusLEDSolid(ledStatusColor);
@@ -2512,6 +2525,12 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
25122525
// hardware and software watchdog timers, delayMicroseconds does not.
25132526
delayMicroseconds(1000000);
25142527
#endif
2528+
if (i < seconds_until_wdt_enable) {
2529+
yield();
2530+
WS.feedWDT(); // feed the WDT for the first X-5 seconds
2531+
} else if (i == seconds_until_reboot) {
2532+
WS.enableWDT(wdt_timeout_ms);
2533+
}
25152534
}
25162535
}
25172536

src/Wippersnapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ class Wippersnapper {
311311

312312
// Error handling helpers
313313
void haltError(String error,
314-
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME);
314+
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
315+
uint8_t seconds_until_reboot = 25);
315316
void errorWriteHang(String error);
316317

317318
// MQTT topic callbacks //

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
106106
// If a filesystem does not already exist - attempt to initialize a new
107107
// filesystem
108108
if (!initFilesystem() && !initFilesystem(true)) {
109+
TinyUSBDevice.attach();
109110
setStatusLEDColor(RED);
110111
fsHalt("ERROR Initializing Filesystem");
111112
}
@@ -217,7 +218,12 @@ void Wippersnapper_FS::initUSBMSC() {
217218

218219
// init MSC
219220
usb_msc.begin();
221+
220222
// Attach MSC and wait for enumeration
223+
if (TinyUSBDevice.mounted()) {
224+
TinyUSBDevice.detach();
225+
delay(10);
226+
}
221227
TinyUSBDevice.attach();
222228
delay(500);
223229
}
@@ -232,6 +238,13 @@ bool Wippersnapper_FS::configFileExists() {
232238
// Does secrets.json file exist?
233239
if (!wipperFatFs.exists("/secrets.json"))
234240
return false;
241+
File32 file = wipperFatFs.open("/secrets.json", FILE_READ);
242+
if (!file)
243+
return false;
244+
int firstChar = file.peek();
245+
file.close();
246+
if (firstChar <= 0 || firstChar == 255)
247+
return false;
235248
return true;
236249
}
237250

@@ -318,7 +331,7 @@ bool Wippersnapper_FS::createBootFile() {
318331
void Wippersnapper_FS::createSecretsFile() {
319332
// Open file for writing
320333
File32 secretsFile = wipperFatFs.open("/secrets.json", FILE_WRITE);
321-
334+
secretsFile.truncate(0);
322335
// Create a default secretsConfig structure
323336
secretsConfig secretsConfig;
324337
strcpy(secretsConfig.aio_user, "YOUR_IO_USERNAME_HERE");
@@ -491,8 +504,6 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) {
491504
*/
492505
/**************************************************************************/
493506
void Wippersnapper_FS::fsHalt(String msg) {
494-
TinyUSBDevice.attach();
495-
delay(500);
496507
statusLEDSolid(WS_LED_STATUS_FS_WRITE);
497508
while (1) {
498509
WS_DEBUG_PRINTLN("Fatal Error: Halted execution!");

0 commit comments

Comments
 (0)