Skip to content

Commit 1b2c10b

Browse files
committed
continue fix flash failure
1 parent 3093b50 commit 1b2c10b

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

platformio.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ extra_scripts = upload_no_build.py
1818
lib_compat_mode = strict
1919
lib_deps =
2020
adafruit/Adafruit Zero DMA Library
21-
https://github.com/adafruit/Adafruit_TinyUSB_Arduino
22-
adafruit/Adafruit NeoPixel
21+
adafruit/Adafruit TinyUSB Library
2322
adafruit/Adafruit SPIFlash
23+
adafruit/Adafruit NeoPixel
2424
adafruit/Adafruit DotStar
2525
adafruit/ENS160 - Adafruit Fork
2626
adafruit/Adafruit SleepyDog Library
@@ -82,7 +82,8 @@ lib_deps =
8282

8383
; Common build environment for ESP32 platform
8484
[common:esp32]
85-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
85+
;platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
86+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
8687
lib_ignore = WiFiNINA, WiFi101
8788
monitor_filters = esp32_exception_decoder, time
8889
; upload_speed = 921600

src/provisioning/tinyusb/Wippersnapper_FS_V2.cpp

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ Adafruit_USBD_MSC usb_msc_v2; /*!< USB mass storage object */
5959
FATFS elmchamFatfs_v2; ///< Elm Cham's fatfs object
6060
uint8_t workbuf_v2[4096]; ///< Working buffer for f_fdisk function.
6161

62-
bool mk_fs(void) {
62+
FRESULT mk_fs(void) {
6363
// Make filesystem
6464
FRESULT r = f_mkfs("", FM_FAT | FM_SFD, 0, workbuf_v2, sizeof(workbuf_v2));
65-
if (r != FR_OK)
66-
return false;
67-
return true;
65+
return r;
6866
}
6967

7068
bool mk_mount_disk_label(void) {
@@ -92,12 +90,43 @@ bool mk_set_disk_label(void) {
9290
return true;
9391
}
9492

93+
String getFRESULTMessage(FRESULT result) {
94+
switch(result) {
95+
case FR_OK: return "Succeeded";
96+
case FR_DISK_ERR: return "A hard error occurred in the low level disk I/O layer";
97+
case FR_INT_ERR: return "Assertion failed";
98+
case FR_NOT_READY: return "The physical drive cannot work";
99+
case FR_NO_FILE: return "Could not find the file";
100+
case FR_NO_PATH: return "Could not find the path";
101+
case FR_INVALID_NAME: return "The path name format is invalid";
102+
case FR_DENIED: return "Access denied due to prohibited access or directory full";
103+
case FR_EXIST: return "Access denied due to prohibited access";
104+
case FR_INVALID_OBJECT: return "The file/directory object is invalid";
105+
case FR_WRITE_PROTECTED: return "The physical drive is write protected";
106+
case FR_INVALID_DRIVE: return "The logical drive number is invalid";
107+
case FR_NOT_ENABLED: return "The volume has no work area";
108+
case FR_NO_FILESYSTEM: return "There is no valid FAT volume";
109+
case FR_MKFS_ABORTED: return "The f_mkfs() aborted due to any problem";
110+
case FR_TIMEOUT: return "Could not get a grant to access the volume within defined period";
111+
case FR_LOCKED: return "The operation is rejected according to the file sharing policy";
112+
case FR_NOT_ENOUGH_CORE: return "LFN working buffer could not be allocated";
113+
case FR_TOO_MANY_OPEN_FILES: return "Number of open files > FF_FS_LOCK";
114+
case FR_INVALID_PARAMETER: return "Given parameter is invalid";
115+
default: return "Unknown error";
116+
}
117+
}
118+
95119
/**************************************************************************/
96120
/*!
97121
@brief Initializes USB-MSC and the QSPI flash filesystem.
98122
*/
99123
/**************************************************************************/
100124
Wippersnapper_FS_V2::Wippersnapper_FS_V2() {
125+
// Detach USB device during init.
126+
TinyUSBDevice.detach();
127+
// Wait for detach
128+
delay(500);
129+
101130
// Attempt to initialize the flash chip
102131
if (!flash_v2.begin()) {
103132
setStatusLEDColor(RED);
@@ -106,16 +135,16 @@ Wippersnapper_FS_V2::Wippersnapper_FS_V2() {
106135

107136
// Check if the filesystem is formatted
108137
_isFormatted = wipperFatFs_v2.begin(&flash_v2);
138+
_isFormatted = false;
109139

110140
// If we are not formatted, attempt to format the filesystem as fat12
111141
if (!_isFormatted) {
112-
if (! mk_fs()) {
113-
setStatusLEDColor(RED);
114-
fsHalt("Failed to format the filesystem!");
115-
}
142+
FRESULT rc = mk_fs();
143+
fsHalt(getFRESULTMessage(rc));
144+
116145
if (! mk_mount_disk_label() ) {
117146
setStatusLEDColor(RED);
118-
fsHalt("Failed to mount the filesystem!");
147+
fsHalt("L125: Failed to mount the filesystem!");
119148
}
120149
if (! mk_set_disk_label() ) {
121150
setStatusLEDColor(RED);
@@ -131,6 +160,12 @@ Wippersnapper_FS_V2::Wippersnapper_FS_V2() {
131160
_freshFS = true;
132161
}
133162

163+
if (!wipperFatFs_v2.begin(&flash_v2)) {
164+
setStatusLEDColor(RED);
165+
// pass res to the fsHalt
166+
fsHalt("L143: Failed to mount the filesystem");
167+
}
168+
134169
// Write contents to the filesystem
135170
if (! writeFSContents()) {
136171
setStatusLEDColor(RED);

0 commit comments

Comments
 (0)