• AVR Freaks

Hot!NVM File System Detaching for some reason and unable to recover (remount)

Author
Valin0126
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2020/02/07 04:53:15
  • Location: 0
  • Status: offline
2020/07/08 04:48:02 (permalink)
0

NVM File System Detaching for some reason and unable to recover (remount)

Harmony 2.06
PIC32MZ1024EFE64
 
Using the NVM driver and FAT File System.  Have had it working for months.  The system stores two files, one for configuration data the other for calibration data.
 
Recently added a second method to launch the calibration routine.  When calling the routine from the second entry point it performs two file system writes as expected then subsequent attempts to write result in a SYS_FS_ERROR_INVALID_NAME (error code 6).  Debugging the code, the file name isn't corrupted. 
 
Can anyone explain what could cause an invalid filename error when the file name is valid?  Again, the confusing part is that the code works when called from one launch point but generates this error when called from a different launch point.  The data being saved is a constant sized struct and that doesn't change.
 
Thanks.
 
Update: Somehow the sys_fs SYS_FS_GetDisk() is being called with an invalid path name (still trying to trace down how that's happening).  Though the filesystem doesn't seem to recover from this error once it does occur, which is another issue.
 
Second Update: Traced it as far as sys_fs_media_manager.c SYS_FS_MEDIA_MANAGER_Tasks() for case SYS_FS_MEDIA_CHECK_ATTACH_STATUS.  This is causing the media to detach.  Which it then doesn't recover from (re-attach).
post edited by Valin0126 - 2020/07/08 08:21:54
#1

4 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 630
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: NVM File System Detaching for some reason and unable to recover (remount) 2020/07/08 09:17:20 (permalink)
    4 (1)
    sufficient heap?
    #2
    Valin0126
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2020/02/07 04:53:15
    • Location: 0
    • Status: offline
    Re: NVM File System Detaching for some reason and unable to recover (remount) 2020/07/08 09:44:48 (permalink)
    0
    Plenty of heap (32k).  Was able to recover from the error by deinitializine and re-initializing the NVM driver.  Not a perfect solution and would still like to understand the root case of the detaching. 
     
    This is not the first time the application has had to de-init and re-init one of the peripheral Harmony drivers to recover from a bad state.
    #3
    Paul PortSol
    Super Member
    • Total Posts : 630
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: NVM File System Detaching for some reason and unable to recover (remount) 2020/07/14 07:50:47 (permalink)
    0
    PIC operating as Host?
    If PIC providing power then ensure Good capacitor on VBUS/5V
    Try 150uF 6V ceramic (Not higher voltage as different capacitance if not near operating voltage)
     
    Heap and Capacitance were the two thinks that affected my swapping out USB Memory Sticks. I have a cfg file and a log file, and I can eject and reinsert without re-init.
     
    Are you waiting appropriately for connected SYS_FS_EVENT_MOUNT from your callback before trying to open files? If try too soon FS may not be fully ready.
     
    I use Callback to detect removal and insert, though it is best to do a manual disconnect/close before removal to ensure that files have finished writing: SYS_FS_FileClose().
    If the USB stick may be randomly removed it may be worth doing a FileSync periodically/appropriately to ensure no unwritten data pending to avoid incomplete file end.
     
    Callback setup before BusEnable:
    SYS_FS_EventHandlerSet(vCallback_FilesystemEvent, (uintptr_t)NULL);// Set the event handler and enable the bus (No Context needed)
    USB_HOST_BusEnable(D_USB_FirstBus);//Note vUSB_EnableH() called above in case default USBHSInit doesn't point to vUSB_EnableH()
     
     
    void vCallback_FilesystemEvent(SYS_FS_EVENT eEvent, void *pEventDataUnused, uintptr_t pContextUnused)
    {
        sFiles.uFsCallbacks++;
        switch (eEvent)
        {
            case SYS_FS_EVENT_MOUNT:
                sFiles.bFsConnected = true;
                break;
            case SYS_FS_EVENT_UNMOUNT:
                sFiles.bFsConnected = false;
                sFiles.sLogU.bReady = false;//File not ready for Read
                sFiles.sCfgM.bReady = false;//File not ready for Read
                break;
            case SYS_FS_EVENT_ERROR:
                sFiles.uFsCallbackError++;
                break;
            default:
                sFiles.eFsCallbackUnknown = eEvent;
                sFiles.uFsCallbackUnknown++;
                break;
        }
    }

    Paul
    #4
    Valin0126
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2020/02/07 04:53:15
    • Location: 0
    • Status: offline
    Re: NVM File System Detaching for some reason and unable to recover (remount) 2020/07/15 02:47:53 (permalink)
    0
    This is using the PIC's internal Flash as the NVM, not an external device. 
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5