Fix SDcard size and format issue (#5004)

* - fix overflow in SDcard size computation
- fix format function
- implement more informative format error handling

* Move to a function
This commit is contained in:
3djc
2017-06-14 23:33:31 +02:00
committed by Bertrand Songis
parent 547606b44e
commit 656daa75fa
4 changed files with 38 additions and 14 deletions
+1 -5
View File
@@ -151,14 +151,10 @@ bool menuRadioSdManager(event_t _event)
showMessageBox(STR_FORMATTING); showMessageBox(STR_FORMATTING);
logsClose(); logsClose();
audioQueue.stopSD(); audioQueue.stopSD();
BYTE work[_MAX_SS]; if(sdCardFormat()) {
if (f_mkfs(0, FM_FAT32, 0, work, sizeof(work)) == FR_OK) {
f_chdir("/"); f_chdir("/");
REFRESH_FILES(); REFRESH_FILES();
} }
else {
POPUP_WARNING(STR_SDCARD_ERROR);
}
} }
event_t event = (EVT_KEY_MASK(_event) == KEY_ENTER ? 0 : _event); event_t event = (EVT_KEY_MASK(_event) == KEY_ENTER ? 0 : _event);
@@ -174,14 +174,10 @@ void menuRadioSdManager(event_t _event)
#if defined(CPUARM) #if defined(CPUARM)
audioQueue.stopSD(); audioQueue.stopSD();
#endif #endif
BYTE work[_MAX_SS]; if(sdCardFormat()) {
if (f_mkfs(0, FM_FAT32, 0, work, sizeof(work)) == FR_OK) {
f_chdir("/"); f_chdir("/");
REFRESH_FILES(); REFRESH_FILES();
} }
else {
POPUP_WARNING(STR_SDCARD_ERROR);
}
} }
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
+32 -1
View File
@@ -22,6 +22,37 @@
#include "opentx.h" #include "opentx.h"
#include "diskio.h" #include "diskio.h"
bool sdCardFormat()
{
BYTE work[_MAX_SS];
FRESULT res = f_mkfs("", FM_FAT32, 0, work, sizeof(work));
switch(res) {
case FR_OK :
return true;
case FR_DISK_ERR:
POPUP_WARNING("Format error");
return false;
case FR_NOT_READY:
POPUP_WARNING("SDCard not ready");
return false;
case FR_WRITE_PROTECTED:
POPUP_WARNING("SDCard write protected");
return false;
case FR_INVALID_PARAMETER:
POPUP_WARNING("Format param invalid");
return false;
case FR_INVALID_DRIVE:
POPUP_WARNING("Invalid drive");
return false;
case FR_MKFS_ABORTED:
POPUP_WARNING("Format aborted");
return false;
default:
POPUP_WARNING(STR_SDCARD_ERROR);
return false;
}
}
const char * sdCheckAndCreateDirectory(const char * path) const char * sdCheckAndCreateDirectory(const char * path)
{ {
DIR archiveFolder; DIR archiveFolder;
@@ -472,7 +503,7 @@ uint32_t sdGetNoSectors()
uint32_t sdGetSize() uint32_t sdGetSize()
{ {
return (sdGetNoSectors() * BLOCK_SIZE) / 1000000; return (sdGetNoSectors() / 1000000) * BLOCK_SIZE;
} }
uint32_t sdGetFreeSectors() uint32_t sdGetFreeSectors()
+1
View File
@@ -95,6 +95,7 @@ void logsInit();
void logsClose(); void logsClose();
void logsWrite(); void logsWrite();
bool sdCardFormat();
uint32_t sdGetNoSectors(); uint32_t sdGetNoSectors();
uint32_t sdGetSize(); uint32_t sdGetSize();
uint32_t sdGetFreeSectors(); uint32_t sdGetFreeSectors();