Skip to content
Snippets Groups Projects
Commit 3c4c5bd6 authored by schneider's avatar schneider
Browse files

feat(fatfs): Print string error message when mount fails

parent e0900d87
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,12 @@
#include <FreeRTOS.h>
#include <semphr.h>
static const TCHAR *rcstrings =
_T("OK\0DISK_ERR\0INT_ERR\0NOT_READY\0NO_FILE\0NO_PATH\0INVALID_NAME\0")
_T("DENIED\0EXIST\0INVALID_OBJECT\0WRITE_PROTECTED\0INVALID_DRIVE\0")
_T("NOT_ENABLED\0NO_FILESYSTEM\0MKFS_ABORTED\0TIMEOUT\0LOCKED\0")
_T("NOT_ENOUGH_CORE\0TOO_MANY_OPEN_FILES\0INVALID_PARAMETER\0");
static bool mount(void);
DIR dir;
......@@ -21,31 +27,50 @@ static volatile struct {
.initiaized = false,
};
bool mount()
void fatfs_init()
{
if (mount()) {
s_state.initiaized = true;
printf("FatFs mounted\n");
}
}
const char *f_get_rc_string(FRESULT rc)
{
FRESULT i;
const char *p = rcstrings;
for (i = 0; i != rc && *p; i++) {
while (*p++)
;
}
return p;
}
static bool mount()
{
FRESULT res;
res = f_mount(&FatFs, "/", 0);
if (res != FR_OK) {
printf("f_mount error %d\n", res);
printf("f_mount error %s\n", f_get_rc_string(res));
return false;
}
res = f_opendir(&dir, "0:");
if (res != FR_OK) {
printf("f_opendir error %d\n", res);
printf("f_opendir error %s\n", f_get_rc_string(res));
return false;
}
return true;
}
void fatfs_init()
{
if (mount()) {
s_state.initiaized = true;
printf("FatFs mounted\n");
}
}
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to create a new
/ synchronization object for the volume, such as semaphore and mutex.
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
*/
/*
* Return value:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment