• AVR Freaks

Hot!SDCARD SYS_FS_DirectoryMake [Error]

Author
Acuzio
Senior Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2012/08/28 11:15:53
  • Location: 0
  • Status: offline
2016/01/11 13:59:13 (permalink)
0

SDCARD SYS_FS_DirectoryMake [Error]

Hi, i am working on a project where i need to develop a storage device using an sd card and a fyle system.
Hardware development tools:
-Explorer16 + PIC32MX795F512L(PIM)+PICTail Board for SD cards connected to SPI2
Software development tools:
-MPLABX V3.10
-Harmony 1.06
-Compiler XC32 v1.40
 
I am starting with the demo app code "sdcard_fat_single_disk" demo.
 
The disk succesfully mounts and unmounts, succesfully opens the "FILE_TOO_LONG_NAME_EXAMPLE_123.JPG" file, previously created in the sdcard.
The problem is located when the applications enters APP_CREATE_DIRECTORY state, the call to SYS_FS_DirectoryMake  it returns SYS_FS_FAILURE.
[DEBUG]
I have done a little bit of debugging and the SYS_FS_Error returns that the failure is SYS_FS_ERROR_DISK_ERR.
Some deeper debugging leads me to f_mkdir which seems to have some error.
Anyway i am really lost in this so any help would be appreciated.
if(SYS_FS_DirectoryMake("dir1") == SYS_FS_RES_FAILURE)
            {
                fserror = SYS_FS_Error();
                /* Error while setting current drive */
                appData.state = APP_ERROR;
            }
            else
            {
                /* Open a second file for writing. */
                appData.state = APP_OPEN_SECOND_FILE;
            }

 
 
Thank you
 

Attached Image(s)


Hey! It compiles! Ship it!

  www.micro-pic.es
#1

10 Replies Related Threads

    muellernick
    Super Member
    • Total Posts : 466
    • Reward points : 0
    • Joined: 2015/01/06 23:58:23
    • Location: Germany
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/12 02:26:26 (permalink)
    4 (2)
    Does the directory already exist?
    If it does exist, makedir returns an error (but I don't know which one). Out of my head, you can't distinguish what the error cause was. Means, there is no error "Directory exists".
     
     
    Nick
    #2
    Hologram
    Junior Member
    • Total Posts : 46
    • Reward points : 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/12 02:42:46 (permalink)
    5 (1)
    Hi Acuzio,
     
    As it's the "sdcard_fat_single_disk" example, I would tend rule out the possibility of failure at the SYS_FS level due to the possible need to prefix the path with the mounted device path, e.g. "/mnt/myDrive/" if the SD card is not the current drive (you could call SYS_FS_CurrentDriveSet() first, in this case).
     
    Without reproducing your error scenario, it looks possible that the error is arising out of a failure in create_chain() in the FAT file system implementation in framework/system/fs/fat_fs/src/file_system/ff.c that gets called from f_mkdir().
    This would cause f_mkdir() to fail with FR_DISK_ERR ( 1 = "Hard error occurred in the low level disk I/O layer ) and aliasing to SYS_FS_ERROR_DISK_ERROR in SYS_FS_DirectoryMake().
     
    This can be failing for several reasons such as the file system not being recognised as FS_FAT12, FS_FAT16 or FS_FAT32 or underlying FAT chaining functions failing, such as get_fat() failing to get the next cluster of the chain or put_fat() failing to link the next cluster or a sector read failure inside move_window().
     
    Is the disk somehow set to be read-only (even if SD card is being reported as writeable by the write-protect pin)?
    Is the file system full - i.e. no free clusters left in the FAT to form a chain?
    Are you sure of the integrity of the file system on the card - does it flag any errors with chkdsk or file system utilities when mounted on another platform (Linux, Windows or Mac OS X)?
    Does the issue reproduce if you use different physical media (just to rule out a defective SD card)?
    Sounds silly, but can you check for stack corruption due to dubious pointer dereferencing elsewhere, totally unrelated to the file system, as I had a similar obscure file system problem at the low-level that turned out to have nothing to do with the FS, it just got clobbered!
    post edited by Hologram - 2016/01/12 02:48:25
    #3
    Hologram
    Junior Member
    • Total Posts : 46
    • Reward points : 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/12 03:04:19 (permalink)
    4 (2)
    I think a pre-existing directory of the specified name will cause the FAT file system implementation function f_mkdir() to return FR_EXIST ( 8 = "Access denied due to prohibited access" ) as follow_path() should find the path name. This will get aliased to SYS_FS_ERROR_EXIST by SYS_FS_DirectoryMake().
    #4
    Acuzio
    Senior Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2012/08/28 11:15:53
    • Location: 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/12 13:08:09 (permalink)
    3 (1)
    Hi Nick,
    Thank you for your response.
     
    Does the directory already exist?
    If it does exist, makedir returns an error (but I don't know which one). Out of my head, you can't distinguish what the error cause was. Means, there is no error "Directory exists"

    Yes im sure the directory is not already created.
    *****************************************
    Hi Hologram,
    First of all thak you for your response.
    I am working on a solution on the issue, and i have several impediments.
    I have three sdcards, all different(Picture1).
    uSDCARD1: Will not mount even if i format it in FAT32,FAT..., changed cluster size.
    uSDCARD3: Will not mount even if i format it in FAT32,FAT...
    SDCARD2: Will mount, but not able to create a directory.
    Why can this be? Does the cluster size have anything to do(512,1024,etc...), could be changed on format of sdcard?
    Is there any known issue of what sdcard are not compatible?
    What actions can be done for these sdcards to mount?
     
    Another question is what impact have the parameters highlighted in picture 2.
     
    One last question is what levels should i see on pin WD of sd card?
     
    Thank you

    Attached Image(s)


    Hey! It compiles! Ship it!

      www.micro-pic.es
    #5
    Hologram
    Junior Member
    • Total Posts : 46
    • Reward points : 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/13 01:31:40 (permalink)
    3 (1)
    WD pin?
     
    The SD card detect - SD - pin on the connector is usually shorted to ground on card insertion and you have an external pull-up resistor (or configure an internal pull up on the connected port pin of your microcontroller) so you should see this go low as the card is inserted.
    Similarly, the write protect pin - WP - on the connector is shorted to ground if the write-protect tab on the card is in the write-enabled state (or by default if the card has no write-protect tab) and open if it is write-protected, so the pull-up will give you a logic high for write-protect and low for write-enabled.
     
    Of course, a micro-SD card doesn't have a write-protect tab. It will have, if installed in a micro to full-sized SD card adapter and the adapter itself has one.
     
    If your hardware doesn't allow detection of the write protection state, as a quick workaround, you could patch _DRV_SDCARD_CheckWriteProtectStatus() in Harmony's framework/driver/sdcard/src/dynamic/drv_sdcard.c implementation to always set the state false, or determine the state of the card some other way.
    #6
    Acuzio
    Senior Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2012/08/28 11:15:53
    • Location: 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/13 12:16:17 (permalink)
    3 (1)
    Hi Hologram,
    The SD card detect - SD - pin on the connector is usually shorted to ground on card insertion and you have an external pull-up resistor (or configure an internal pull up on the connected port pin of your microcontroller) so you should see this go low as the card is inserted.
    Similarly, the write protect pin - WP - on the connector is shorted to ground if the write-protect tab on the card is in the write-enabled state (or by default if the card has no write-protect tab) and open if it is write-protected, so the pull-up will give you a logic high for write-protect and low for write-enabled.

    Yes i have debugged WD and CD pins and both have correct levels.
    I am at the moment trying to figure out what is the reason for the other uSDcard`s not to mount.
    Aswell as trying to debug the problem for the directory make error...
     
    Thank you

    Hey! It compiles! Ship it!

      www.micro-pic.es
    #7
    Hologram
    Junior Member
    • Total Posts : 46
    • Reward points : 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/14 01:23:54 (permalink)
    3 (1)
    Hi Acuzio,
     
    I am using the same Harmony File System configuration settings as you, with the exception of the maximum simultaneous file access parameter, which in my case is set to 10. The file system seems to be okay.
    At the moment the SD card I am using is a Transcend 1GB micro SD. I note that all of the cards you are using are SDHC. I don't know if that makes a difference? I'll try a SDHC and see if I get the same results.
    My card is currently formatted with a 4KB cluster size.
     
    #8
    Hologram
    Junior Member
    • Total Posts : 46
    • Reward points : 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/14 01:56:33 (permalink)
    3 (1)
    Just verified I can mount and create a new directory on a Kingston 8GB micro SDHC, speed class 10, using a PIC32MX575F512L, formatted to FAT32 with 4KB clusters on Windows 7. I attach my Harmony File System and SD card configuration parameters for comparison.

    Attached Image(s)

    #9
    Acuzio
    Senior Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2012/08/28 11:15:53
    • Location: 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2016/01/14 14:23:25 (permalink)
    3 (1)
    Hi Hologram
     
    Will have a look at it tomorrow, and come back to you with the results.
     
     

    Hey! It compiles! Ship it!

      www.micro-pic.es
    #10
    tixmcprods
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2019/06/12 15:33:51
    • Location: 0
    • Status: offline
    Re: SDCARD SYS_FS_DirectoryMake [Error] 2019/06/14 05:12:41 (permalink)
    0
    Hello,
    Any news for this error ? Also have a SYS_FS_ERROR_DISK_ERR, but not always, even with the same file.
    This happen only with SYS_FS_FileOpen...
    Refer to this thread for details : https://www.microchip.com/forums/m1051951.aspx
    Thanks !
    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5