Skip to content

Commit

Permalink
Merge remote-tracking branch 'tyeth/tinyusb-reattach-print-reset-time…
Browse files Browse the repository at this point in the history
…' into uat-xmas2024
  • Loading branch information
tyeth committed Dec 20, 2024
2 parents 418e785 + b594a3b commit f46c204
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
49 changes: 35 additions & 14 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#develop
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
29 changes: 24 additions & 5 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,14 +2494,27 @@ void Wippersnapper::runNetFSM() {
@brief Prints an error to the serial and halts the hardware until
the WDT bites.
@param error
The desired error to print to serial.
The error to print to serial.
@param ledStatusColor
The desired color to blink.
The color to blink.
@param seconds_until_reboot
The amount of time to wait before rebooting.
*/
/**************************************************************************/
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
for (;;) {
WS_DEBUG_PRINT("ERROR [WDT RESET]: ");
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
uint8_t seconds_until_reboot) {
#ifdef ARDUINO_ARCH_ESP8266
uint8_t wdt_timeout_ms = 3200;
#else
uint8_t wdt_timeout_ms = 5000;
#endif
int seconds_until_wdt_enable =
seconds_until_reboot - (int)(wdt_timeout_ms / 1000);

for (int i = 0;; i++) {
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
WS_DEBUG_PRINT(seconds_until_reboot - i);
WS_DEBUG_PRINTLN("]: ");
WS_DEBUG_PRINTLN(error);
// let the WDT fail out and reset!
statusLEDSolid(ledStatusColor);
Expand All @@ -2512,6 +2525,12 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
// hardware and software watchdog timers, delayMicroseconds does not.
delayMicroseconds(1000000);
#endif
if (i < seconds_until_wdt_enable) {
yield();
WS.feedWDT(); // feed the WDT for the first X-5 seconds
} else if (i == seconds_until_reboot) {
WS.enableWDT(wdt_timeout_ms);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ class Wippersnapper {

// Error handling helpers
void haltError(String error,
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME);
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
uint8_t seconds_until_reboot = 25);
void errorWriteHang(String error);

// MQTT topic callbacks //
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 @@ -491,8 +504,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 f46c204

Please sign in to comment.