• AVR Freaks

Hot!sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem

Author
TS9
Super Member
  • Total Posts : 785
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2019/05/24 14:18:14 (permalink)
0

sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem

Hi,
 
I am working on PIC32MZ2048EFM100 MCU. 
C:\microchip\harmony\v2_06\apps\fs\sdcard_msd_fat_multi_disk .. Demo work fine
 
I am trying to modify  sdcard_msd_fat_multi_disk :
I want to mount and use SDCard Only without using USB MSD.
and Only want to use USB Only once connected .
 
How to modify and use as SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
as in above case and also in state machine ?
 

 
void APP_SYSFSEventHandler(SYS_FS_EVENT event, void * eventData, uintptr_t context)
{
switch(event)
{
/* If the event is mount then check which media has been mounted */
case SYS_FS_EVENT_MOUNT:
if(0 == strcmp((const char *)eventData,"/mnt/sdDrive"))
{
appDataSd.deviceIsConnected = true;
}
else if(0 == strcmp((const char *)eventData,"/mnt/msdDrive/"))
{
appDataMsd.deviceIsConnected = true;
}
break;
/* If the event is unmount then check which media has been unmount */
case SYS_FS_EVENT_UNMOUNT:
if(0 == strcmp((const char *)eventData,"/mnt/sdDrive"))
{
appDataSd.deviceIsConnected = false;
}
else if(0 == strcmp((const char *)eventData,"/mnt/msdDrive/"))
{
appDataMsd.deviceIsConnected = false;
}
break;
case SYS_FS_EVENT_ERROR:
break;
}
}
 


 
void APP_USB_MSDTasks (void)
 
{
 
PrintString("APP_STATE_BUS_ENABLE\r\n") ;
/* Set the event handler and enable the bus */
SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
USB_HOST_EventHandlerSet(APP_USBHostEventHandler, 0);
USB_HOST_BusEnable(0);
 
|
 
|
 
}


void APP_SDCardTasks ( void )
{
SYS_FS_RESULT result = SYS_FS_RES_FAILURE;
/* The application task state machine */
switch(appDataSd.state)
{
case APP_OPEN_FIRST_FILE:
|
|
}

 
Thanks in advance..
 
--
TS9
post edited by TS9 - 2019/05/24 14:20:28
#1

7 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/27 04:42:03 (permalink)
    0
    I use the FSYS Callback to flag when connected/disconnected (USB MSD somewhat similar to SDCARD, sLogU/sLogD/sCfgM are files on my USB Stick).
     
    =============
     
    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;
        }
    }

    ==============
    void vFilesInit( void )// Initialize Log USB Flashdrive
    {
        //SYS_DEBUG_ErrorLevelSet(SYS_ERROR_FATAL);
        //SYS_DEBUG_ErrorLevelSet(SYS_ERROR_DEBUG);
        //SYS_DEBUG_ErrorLevelSet(SYS_ERROR_ERROR);

        vUSB_EnableH(0 /*Port0*/, true);//Force Enable Power to USB (If using default USBHSInit then the pointer to this function isn't included)
        D_PRINTF_Init("Init:USB Power Enabled\n");
        
        //FileSystem:
        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()
        sFiles.eState = EFSys_InitOnce;
        D_PRINTF_Init("Init:Filesystem = OK\n");
        
        //LogD: Diagnostic Log
        sFiles.sLogD.eFile = ELogD;
        sFiles.sLogD.eStateW = EFileW_InitOnce; //Initial State
        sFiles.sLogD.cID = 'd';
        sFiles.sLogD.pcName = pcName_LogD; //File's Short Name (for Diag)
        sFiles.sLogD.pcPath = pcPath_LogD; //File's Path
        D_vRingBufA8b_init(sRingLogD); sFiles.sLogD.psRing = (TRINGBUFA*)&sRingLogD; //Prepare Ring Buffer for Writes
        sFiles.sLogD.uRingIndex=0; //Index for lines written to ring, so can see where any lines missed (i.e. when log removed/forceclosed/etc.)
        sFiles.sLogD.bRingInit = true;
        D_PRINTF_Init("Init:LogD = OK, Buf:%u, Path(%s)\n", uRingBufA8_GetMaxItems(sFiles.sLogD.psRing), sFiles.sLogD.pcPath);
        
        //LogU: User Log
        sFiles.sLogU.eFile = ELogU;
        sFiles.sLogU.eStateW = EFileW_InitOnce; //Initial State
        sFiles.sLogU.cID = 'u';
        sFiles.sLogU.pcName = pcName_LogU; //File's Short Name (for Diag)
        sFiles.sLogU.pcPath = pcPath_LogU; //File's Path
        D_vRingBufA8b_init(sRingLogU); sFiles.sLogU.psRing = (TRINGBUFA*)&sRingLogU; //Prepare Ring Buffer for Writes
        sFiles.sLogU.uRingIndex=0; //Index for lines written to ring, so can see where any lines missed (i.e. when log removed/forceclosed/etc.)
        sFiles.sLogU.bRingInit = true;
        D_PRINTF_Init("Init:LogU = OK, Buf:%u, Path(%s)\n", uRingBufA8_GetMaxItems(sFiles.sLogU.psRing), sFiles.sLogU.pcPath);
        
        //CfgM: Main Configuration File
        sFiles.sCfgM.eFile = ECfgM;
        sFiles.sCfgM.eStateW = EFileW_InitOnce; //Initial State
        sFiles.sCfgM.cID = 'm';
        sFiles.sCfgM.pcName = pcName_CfgM; //File's Short Name (for Diag)
        sFiles.sCfgM.pcPath = pcPath_CfgM; //File's Path
        sFiles.sCfgM.psRing = (TRINGBUFA*)NULL; //No Writes == No Ringbuffer
        sFiles.sCfgM.uRingIndex=-1; //Index for lines written to ring, so can see where any lines missed (i.e. when log removed/forceclosed/etc.)
        sFiles.sCfgM.bRingInit = false;
        D_PRINTF_Init("Init:CfgM = OK, Path(%s)\n", sFiles.sCfgM.pcPath);
        //Cfg Read after USB Mounted

        //Done:
        sFiles.bInit = true;
    }

    ==============
    typedef struct //Data for All Files
    {
        EFSys_States eState;
        uint32_t uBusChecks; //Count of Bus Checks
        uint32_t uConnectChecks; //Count of Connect Checks
        USB_HOST_RESULT eBusResult; //Result of Bus Check
        bool bUnmountRequest; //Request: Unmount FlashDrive
        bool bRemountRequest; //Request: Re-mount Flashdrive
        T_MSEC tSyncChecked; //Time of Last Sync Check

        bool bFsConnected; //Callback: true == USB Device Connected
        uint32_t uFsCallbackError; //Callback: Count Errors
        SYS_FS_EVENT eFsCallbackUnknown; //Callback: USB MSD Unknown Event
        uint32_t uFsCallbackUnknown; //Callback: count of USB MSD Unknown Events
        uint32_t uFsCallbacks; //Callback: count of USB MSD Events

        bool bInit; //Has FileSystem been properly initialized?
        char pcBuf[DFileBufLen+1]; //Buffer for File Reads/Writes, +Space for NULL

        uint32_t uFsTestError; //Error Count
        uint32_t uFilePtrNulls; //Error Count
        uint32_t uFileNotReady; //Error Count
        uint32_t uPrintRecursion; //Error Count
        
        SFileRW sLogU; //ReadWrite - User Log
        SFileRW sLogD; //Write - Diagnostic Log (includes all writes to User Log)
        SFileRW sCfgM; //Read - ConfigFile
    } SFiles;
    D_Declare_Files SFiles sFiles;

    ==============
     
    #2
    TS9
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/27 05:24:49 (permalink)
    0
    Thanks for update Paul...
     
    As In demo , I am using flags..as below 

    appDataSd.deviceIsConnected = true;
    appDataSd.deviceIsConnected = false;
    appDataMsd.deviceIsConnected = true;
    appDataMSd.deviceIsConnected = false;

     
    But in demo SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);  in called 
    inside APP_USBMasks() ;
    According to my requirement, I want to run application on sdcard (only) without USB .
    Means  If USB is not present Just create .txt file in sdcard [] .
    and Once USB is connected ,I have perform copy task Only .
     
    How I can do that ?
     
    --
    TS9
     
     
    #3
    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/27 06:24:23 (permalink)
    0
    Not sure I understand
    - SD Card = Hardware Interface (and low level interface code)
    - USB = Hardware Interface (and low level interface code)
     
    - MSD = Filesystem level, operates on top of USB/SDCARD. Without MSD you won't have files. Now there might be some historic mis-named items "USB" in filesystem/MSD, but unless if you included USB Filesystem in MHC then there shouldn't be USB interface. (Careful not to use any BSP as that can bring in lots of stuff).
     
    There was another user in past month or two who got SDCARD files working, scan for their thread. Maybe something there can help as they resolved some issues.
     
    Paul
    Just a user.
     
     
     
    #4
    TS9
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/27 11:21:50 (permalink)
    0
    Paul PortSol
    Not sure I understand
    - SD Card = Hardware Interface (and low level interface code)
    - USB = Hardware Interface (and low level interface code)

    Hi  again,
    Let me explain more . I Just want to mount
    1) SD Card with File System 
    2) USB with File System 
    One by one .
    SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL); 
    mount both in APP_MSDTasks() .
     
    According to my requirement, I want to access on sdcard (only) without USB .
    and Once USB is connected ,I have access both.
    If disconnect again use sdcard (only) 
     
    TS9
    #5
    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/27 11:27:58 (permalink)
    0
    Have never tried that, maybe someone else.
     
    Should be able to just setup so files on both devices are available, and then track which is currently connected using the callbacks (Separate callbacks, or same callback with different flag set according to USB/SDCARD).
    The in your own code you decide which to access:
    - if USB then use USB, else use SDCARD.
     
    The choice of SDCARD versus USB isn't handled by Harmony, you'll have to handle that yourself.
     
    I suspect you'll have to handle the copy yourself as well (Open Source, Open Target, Read some source, Write to target, repeat, close both). I don't remember seeing commands for "file copy" within Harmony (though they could be there).
     
    If you are looking for something higher level you may have to try the OS option mentioned in Harmony.
     
    Paul 
     
    #6
    TS9
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/28 10:49:57 (permalink)
    0
    Paul PortSol
    Should be able to just setup so files on both devices are available, and then track which is currently connected using the callbacks (Separate callbacks, or same callback with different flag set according to USB/SDCARD).
    The in your own code you decide which to access:
    - if USB then use USB, else use SDCARD.
    The choice of SDCARD versus USB isn't handled by Harmony, you'll have to handle that yourself.
     

     
    Thanks.. Paul PortSol
     
    The demo which I am referring using AutoMount feature for both USB and SDCard together (Not one  by one ).  
    C:\microchip\harmony\v2_06\apps\fs\sdcard_msd_fat_multi_disk
    "- if USB then use USB, else use SDCARD." 
    As per your suggestion , I am unable to manage this either USB or SDCard  as in below:

     
     
     
    void APP_SYSFSEventHandler(SYS_FS_EVENT event, void * eventData, uintptr_t context)
    {
    switch(event)
    {
    /* If the event is mount then check which media has been mounted */
    case SYS_FS_EVENT_MOUNT:
    if(0 == strcmp((const char *)eventData,"/mnt/sdDrive"))
    {
    appDataSd.deviceIsConnected = true;
    }
    else if(0 == strcmp((const char *)eventData,"/mnt/msdDrive/"))
    {
    appDataMsd.deviceIsConnected = true;
    }
    break;
    /* If the event is unmount then check which media has been unmount */
    case SYS_FS_EVENT_UNMOUNT:
    if(0 == strcmp((const char *)eventData,"/mnt/sdDrive"))
    {
    appDataSd.deviceIsConnected = false;
    }
    else if(0 == strcmp((const char *)eventData,"/mnt/msdDrive/"))
    {
    appDataMsd.deviceIsConnected = false;
    }
    break;
    case SYS_FS_EVENT_ERROR:
    break;
    }
    }
     
     
     
    }
    void APP_USB_MSDTasks (void)
    {
    SYS_FS_RESULT result = SYS_FS_RES_FAILURE;
    /* The application task state machine */
     
     
     
    switch(appDataMsd.state)
    {
    case APP_STATE_BUS_ENABLE:
    PrintString("APP_STATE_BUS_ENABLE\r\n") ;
    /* Set the event handler and enable the bus */
    SYS_FS_EventHandlerSet(APP_SYSFSEventHandler, (uintptr_t)NULL);
    USB_HOST_EventHandlerSet(APP_USBHostEventHandler, 0);
    USB_HOST_BusEnable(0);
    appDataMsd.state = APP_STATE_WAIT_FOR_BUS_ENABLE_COMPLETE;
    break;
     
     
     

     
    Paul PortSol
    I suspect you'll have to handle the copy yourself as well (Open Source, Open Target, Read some source, Write to target, repeat, close both). I don't remember seeing commands for "file copy" within Harmony (though they could be there).
     
    If you are looking for something higher level you may have to try the OS option mentioned in Harmony.
    Paul 

    Copy I have already managed from demo without OS .
     
    --
    TS9
     
    post edited by TS9 - 2019/05/28 10:51:30

    Attached Image(s)

    #7
    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: sdcard_msd_fat_multi_disk : SYS_FS_EventHandlerSet Problem 2019/05/28 12:12:18 (permalink)
    0
    You are right, I never noticed before but the callback is for the filesystem, not for USB or SDCARD.
     
    If you really need to separate them then you could try:
     
    1) Create 3 separate projects
    - One with USB only, one with SDCARD only, and one with both.
     
    2) MHC to create separate example code in each:
    • MHC - Application Configuration - Application 0 Configuration - Generate Application Code. I've found "Generate Application Code" often creates code better matched to the Harmony version than some of the demonstrations and samples elsewhere. I do it in a dummy project as it can change settings elsewhere in MHC-Options, and it is easier to see those changes when not in your full project. i.e. I've had a BSP randomly enabled by this process and there isn't one for my PCB. Selecting a different PIC may generate different code (i.e. PIC32MX vs PIC32MZ differs in generated Interrupt code, ADC code, and more).
    3) use a tool like "beyond compare" to compare the generated code and files for the different projects. Maybe it'll help with understanding the low level USB/SDCARD code versus the shared FSYS code.
     
    *) ref attached:    MHC_CreatingProjectWithoutBSP_v00PR.txt
     
    Good luck. Never having used SDCARD on PIC that's the limit of my offering.
     
    Paul 
     
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5