Skip to content

Commit

Permalink
USB Reattach fixes + Specify reset time remaining + secrets != 0xFF
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Dec 17, 2024
1 parent 16bc28a commit 04f1c3c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
51 changes: 36 additions & 15 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ framework = arduino
monitor_speed = 115200
lib_compat_mode = strict
lib_deps =
;;;;;;;;;;; FunHouse / LVGL Boards uncomment these ;;;;;;;;;;;;;;
; https://github.com/adafruit/Adafruit_HX8357_Library.git
; https://github.com/adafruit/Adafruit_ILI9341.git
; https://github.com/adafruit/Adafruit_STMPE610.git
; https://github.com/adafruit/Adafruit-ST7735-Library.git
; https://github.com/adafruit/Adafruit_TouchScreen.git
; https://github.com/brentru/lvgl.git#wippersnapper
; https://github.com/brentru/Adafruit_LvGL_Glue.git#development
;;;;;;;;;;; All Boards need these libraries included ;;;;;;;;;;;;;;
adafruit/Adafruit Zero DMA Library
https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
adafruit/Adafruit NeoPixel
adafruit/Adafruit SPIFlash
adafruit/Adafruit DotStar
Expand Down Expand Up @@ -78,14 +86,8 @@ lib_deps =
https://github.com/Sensirion/arduino-i2c-sen5x.git
https://github.com/adafruit/WiFiNINA.git
https://github.com/Starmbi/hp_BH1750.git
;;;;;;;;;;; FunHouse / LVGL Boards ;;;;;;;;;;;;;;
https://github.com/adafruit/Adafruit_HX8357_Library.git
https://github.com/adafruit/Adafruit_ILI9341.git
https://github.com/adafruit/Adafruit_STMPE610.git
https://github.com/adafruit/Adafruit-ST7735-Library.git
https://github.com/adafruit/Adafruit_TouchScreen.git
https://github.com/brentru/lvgl.git#wippersnapper
https://github.com/brentru/Adafruit_LvGL_Glue.git#development
https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git



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

[common:rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
Expand Down Expand Up @@ -408,7 +411,23 @@ extra_scripts = pre:rename_usb_config.py
[env:huzzah]
extends=common:esp8266
board = huzzah
build_flags = -DARDUINO_ESP8266_ADAFRUIT_HUZZAH
board_build.f_cpu = 80000000L
; Arduino CLI uses this from adafruit_ci#ci-wippersnapper
; 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
build_flags =
-Wl,--gc-sections
-Wl,-Map=output.map
-DARDUINO_ESP8266_ADAFRUIT_HUZZAH
-DDEBUG_ESP_PORT=Serial
-DVTABLES_IN_FLASH
-DNO_EXCEPTIONS
-DNO_STACK_SMASH_PROTECTION
-DSSL_ALL
-DMMU_3232
-DNON32XFER_FAST
-DDEBUG_DISABLED
-DDEBUG_LEVEL_NONE
board_build.eesz=4M2M
board_build.filesystem = littlefs
upload_port = /dev/cu.SLAB_USBtoUART

Expand All @@ -418,8 +437,9 @@ upload_port = /dev/cu.SLAB_USBtoUART
[env:adafruit_pyportal_m4]
extends = common:atsamd
board = adafruit_pyportal_m4
build_flags = -DUSE_TINYUSB=1
build_flags = -DUSE_TINYUSB
-DADAFRUIT_PYPORTAL
extra_scripts = pre:rename_usb_config.py

; Adafruit PyPortal M4 Titano
[env:adafruit_pyportal_m4_titano]
Expand Down Expand Up @@ -463,8 +483,9 @@ build_flags = -DUSE_TINYUSB
[env:adafruit_metro_m4_airliftlite]
extends = common:atsamd
board = adafruit_metro_m4_airliftlite
build_flags = -DUSE_TINYUSB=1
build_flags = -DUSE_TINYUSB
-DADAFRUIT_METRO_M4_AIRLIFT_LITE
; extra_scripts = pre:rename_usb_config.py
upload_port = /dev/cu.usbmodem1201


Expand Down Expand Up @@ -494,7 +515,7 @@ build_flags =
-DDEBUG_RP2040_CORE
-DDEBUG_RP2040_WIFI
-DNDEBUG
-DLWIP_DEBUG
-DLWIP_DEBUG=1
-DDEBUG_RP2040_PORT=Serial1
-DDEBUG_RP2040_UART_1
-DDEBUG_RP2040_UART=1
Expand Down
12 changes: 10 additions & 2 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2500,8 +2500,10 @@ void Wippersnapper::runNetFSM() {
*/
/**************************************************************************/
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
for (;;) {
WS_DEBUG_PRINT("ERROR [WDT RESET]: ");
for (int i = 0;; i++) {
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
WS_DEBUG_PRINT(25 - i);
WS_DEBUG_PRINTLN("]: ");
WS_DEBUG_PRINTLN(error);
// let the WDT fail out and reset!
statusLEDSolid(ledStatusColor);
Expand All @@ -2512,6 +2514,12 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
// hardware and software watchdog timers, delayMicroseconds does not.
delayMicroseconds(1000000);
#endif
if (i < 20) {
yield();
WS.feedWDT(); // feed the WDT for the first 20 seconds
} else if (i == 20) {
WS.enableWDT(5000);
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/provisioning/tinyusb/Wippersnapper_FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Wippersnapper_FS::Wippersnapper_FS() {
// If a filesystem does not already exist - attempt to initialize a new
// filesystem
if (!initFilesystem() && !initFilesystem(true)) {
TinyUSBDevice.attach();
setStatusLEDColor(RED);
fsHalt("ERROR Initializing Filesystem");
}
Expand Down Expand Up @@ -217,7 +218,12 @@ void Wippersnapper_FS::initUSBMSC() {

// init MSC
usb_msc.begin();

// Attach MSC and wait for enumeration
if (TinyUSBDevice.mounted()) {
TinyUSBDevice.detach();
delay(10);
}
TinyUSBDevice.attach();
delay(500);
}
Expand All @@ -232,6 +238,13 @@ bool Wippersnapper_FS::configFileExists() {
// Does secrets.json file exist?
if (!wipperFatFs.exists("/secrets.json"))
return false;
File32 file = wipperFatFs.open("/secrets.json", FILE_READ);
if (!file)
return false;
int firstChar = file.peek();
file.close();
if (firstChar <= 0 || firstChar == 255)
return false;
return true;
}

Expand Down Expand Up @@ -318,7 +331,7 @@ bool Wippersnapper_FS::createBootFile() {
void Wippersnapper_FS::createSecretsFile() {
// Open file for writing
File32 secretsFile = wipperFatFs.open("/secrets.json", FILE_WRITE);

secretsFile.truncate(0);
// Create a default secretsConfig structure
secretsConfig secretsConfig;
strcpy(secretsConfig.aio_user, "YOUR_IO_USERNAME_HERE");
Expand Down Expand Up @@ -485,8 +498,6 @@ void Wippersnapper_FS::writeToBootOut(PGM_P str) {
*/
/**************************************************************************/
void Wippersnapper_FS::fsHalt(String msg) {
TinyUSBDevice.attach();
delay(500);
statusLEDSolid(WS_LED_STATUS_FS_WRITE);
while (1) {
WS_DEBUG_PRINTLN("Fatal Error: Halted execution!");
Expand Down

0 comments on commit 04f1c3c

Please sign in to comment.