Ignore:
Timestamp:
Jan 30, 2025, 8:24:51 AM (3 months ago)
Author:
Zed
Message:

FatFs? is working, but without DMA.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/SES/Core/Src/main_task.cpp

    r74 r75  
    1919//UINT ret;
    2020
    21 static FATFS fs;     // Filesystem object
     21static FATFS fs;// __attribute__((section(".DTCM_RAM")));     // Filesystem object
    2222
     23FRESULT scan_files (TCHAR* path);
     24FRESULT list_dir (const char* path);
    2325
    2426//------------------------------------------------------------------------------
     
    2628[[noreturn]] void mainTaskStart(void *argument)
    2729{
     30        (void)argument;
     31
    2832    FRESULT  r = f_mount(&fs, (const TCHAR*)"", 1);            // Mount the default drive
    2933        if (r != FR_OK) printf("Cannot mount SD-card!\n");
    30         else printf("SD-card was mounted.\n");
     34        else
     35        {
     36                printf("SD-card was mounted.\n");
     37
     38                static TCHAR buff[256];
     39                strcpy (buff, "/");
     40                list_dir(buff);
     41        }
    3142
    3243        while(1)
     
    3748        }
    3849}
     50
     51//------------------------------------------------------------------------------
     52
     53/* List contents of a directory */
     54
     55FRESULT list_dir (const TCHAR *path)
     56{
     57    FRESULT res;
     58    DIR dir;
     59    FILINFO fno;
     60    int nfile, ndir;
     61
     62
     63    res = f_opendir(&dir, path);                       /* Open the directory */
     64    if (res == FR_OK) {
     65        nfile = ndir = 0;
     66        for (;;) {
     67            res = f_readdir(&dir, &fno);                   /* Read a directory item */
     68            if (res != FR_OK || fno.fname[0] == 0) break;  /* Error or end of dir */
     69            if (fno.fattrib & AM_DIR) {            /* Directory */
     70                printf("   <DIR>   %s\n", fno.fname);
     71                ndir++;
     72            } else {                               /* File */
     73                printf("%10u %s\n", fno.fsize, fno.fname);
     74                nfile++;
     75            }
     76        }
     77        f_closedir(&dir);
     78        printf("%d dirs, %d files.\n", ndir, nfile);
     79    } else {
     80        printf("Failed to open \"%s\". (%u)\n", path, res);
     81    }
     82    return res;
     83}
     84
     85//------------------------------------------------------------------------------
     86
     87/* Recursive scan of all items in the directory */
     88
     89FRESULT scan_files (
     90    TCHAR* path        /* Start node to be scanned (***also used as work area***) */
     91)
     92{
     93    FRESULT res;
     94    DIR dir;
     95    UINT i;
     96    static FILINFO fno;
     97
     98
     99    res = f_opendir(&dir, path);                       /* Open the directory */
     100    if (res == FR_OK) {
     101        for (;;) {
     102            res = f_readdir(&dir, &fno);                   /* Read a directory item */
     103            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
     104            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
     105                i = strlen(path);
     106                sprintf(&path[i], "/%s", fno.fname);
     107                res = scan_files(path);                    /* Enter the directory */
     108                if (res != FR_OK) break;
     109                path[i] = 0;
     110            } else {                                       /* It is a file. */
     111                printf("%s/%s\n", path, fno.fname);
     112            }
     113        }
     114        f_closedir(&dir);
     115    }
     116
     117    return res;
     118}
Note: See TracChangeset for help on using the changeset viewer.