Skip to content

Commit f4a8558

Browse files
committed
Fix SAMD bug with tinyUSB attach being called second time
1 parent 413753a commit f4a8558

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Wippersnapper.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,8 +2500,12 @@ void Wippersnapper::runNetFSM() {
25002500
*/
25012501
/**************************************************************************/
25022502
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
2503-
WS.enableWDT(5000);
2504-
for (;;) {
2503+
#ifdef USE_TINYUSB
2504+
if (!TinyUSBDevice.mounted()) {
2505+
TinyUSBDevice.attach(); // calling when already attached breaks SAMD
2506+
}
2507+
#endif
2508+
for (int i=0;;i++) {
25052509
WS_DEBUG_PRINT("ERROR [WDT RESET]: ");
25062510
WS_DEBUG_PRINTLN(error);
25072511
// let the WDT fail out and reset!
@@ -2513,6 +2517,12 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
25132517
// hardware and software watchdog timers, delayMicroseconds does not.
25142518
delayMicroseconds(1000000);
25152519
#endif
2520+
if (i < 20) {
2521+
yield();
2522+
WS.feedWDT(); // feed the WDT for the first 20 seconds
2523+
} else if (i == 20) {
2524+
WS.enableWDT(5000);
2525+
}
25162526
}
25172527
}
25182528

@@ -2712,8 +2722,10 @@ void print_reset_reason(int reason) {
27122722
*/
27132723
/**************************************************************************/
27142724
void printDeviceInfo() {
2725+
WS_PRINTER.flush();
27152726
WS_DEBUG_PRINTLN("-------Device Information-------");
27162727
WS_DEBUG_PRINT("Firmware Version: ");
2728+
WS_PRINTER.flush();
27172729
WS_DEBUG_PRINTLN(WS_VERSION);
27182730
WS_DEBUG_PRINT("Board ID: ");
27192731
WS_DEBUG_PRINTLN(BOARD_ID);

src/network_interfaces/Wippersnapper_AIRLIFT.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,12 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
181181
// User-set network not found, print scan results to serial console
182182
WS_DEBUG_PRINTLN("ERROR: Your requested WiFi network was not found!");
183183
WS_DEBUG_PRINTLN("WipperSnapper found these WiFi networks:");
184-
for (uint8_t i = 0; i < n; ++i)
185-
{
184+
for (uint8_t i = 0; i < n; ++i) {
186185
WS_DEBUG_PRINT(WiFi.SSID(i));
187186
WS_DEBUG_PRINT(" (");
188187
uint8_t BSSID[WL_MAC_ADDR_LENGTH];
189188
WiFi.BSSID(i, BSSID);
190-
for (int m = 0; m < WL_MAC_ADDR_LENGTH; m++)
191-
{
189+
for (int m = 0; m < WL_MAC_ADDR_LENGTH; m++) {
192190
if (m != 0)
193191
WS_DEBUG_PRINT(":");
194192
WS_DEBUG_PRINTHEX(BSSID[m]);

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ void Wippersnapper_FS::initUSBMSC() {
217217

218218
// init MSC
219219
usb_msc.begin();
220+
220221
// Attach MSC and wait for enumeration
222+
if (TinyUSBDevice.mounted()) {
223+
TinyUSBDevice.detach();
224+
delay(10);
225+
}
221226
TinyUSBDevice.attach();
222227
delay(500);
223228
}

0 commit comments

Comments
 (0)