Skip to content

Commit 04f1c3c

Browse files
committed
USB Reattach fixes + Specify reset time remaining + secrets != 0xFF
1 parent 16bc28a commit 04f1c3c

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

platformio.ini

Lines changed: 36 additions & 15 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
@@ -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

@@ -494,7 +515,7 @@ build_flags =
494515
-DDEBUG_RP2040_CORE
495516
-DDEBUG_RP2040_WIFI
496517
-DNDEBUG
497-
-DLWIP_DEBUG
518+
-DLWIP_DEBUG=1
498519
-DDEBUG_RP2040_PORT=Serial1
499520
-DDEBUG_RP2040_UART_1
500521
-DDEBUG_RP2040_UART=1

src/Wippersnapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,8 +2500,10 @@ void Wippersnapper::runNetFSM() {
25002500
*/
25012501
/**************************************************************************/
25022502
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
2503-
for (;;) {
2504-
WS_DEBUG_PRINT("ERROR [WDT RESET]: ");
2503+
for (int i = 0;; i++) {
2504+
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
2505+
WS_DEBUG_PRINT(25 - i);
2506+
WS_DEBUG_PRINTLN("]: ");
25052507
WS_DEBUG_PRINTLN(error);
25062508
// let the WDT fail out and reset!
25072509
statusLEDSolid(ledStatusColor);
@@ -2512,6 +2514,12 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
25122514
// hardware and software watchdog timers, delayMicroseconds does not.
25132515
delayMicroseconds(1000000);
25142516
#endif
2517+
if (i < 20) {
2518+
yield();
2519+
WS.feedWDT(); // feed the WDT for the first 20 seconds
2520+
} else if (i == 20) {
2521+
WS.enableWDT(5000);
2522+
}
25152523
}
25162524
}
25172525

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");
@@ -485,8 +498,6 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) {
485498
*/
486499
/**************************************************************************/
487500
void Wippersnapper_FS::fsHalt(String msg) {
488-
TinyUSBDevice.attach();
489-
delay(500);
490501
statusLEDSolid(WS_LED_STATUS_FS_WRITE);
491502
while (1) {
492503
WS_DEBUG_PRINTLN("Fatal Error: Halted execution!");

0 commit comments

Comments
 (0)