• AVR Freaks

Hot!USB MSD event handler issue

Author
SScheiff
Junior Member
  • Total Posts : 52
  • Reward points : 0
  • Joined: 2017/10/14 10:55:10
  • Location: 0
  • Status: offline
2020/05/15 13:46:14 (permalink)
0

USB MSD event handler issue

I am using the USB MSD libraries in Harmony 2.06 for a data logging application. It is based on the msd_basic example. I am having a strange issue with the USB_MSD_SYSFSEventHandler function that detects when a stick drive is attached. When I first power on the board and run the code for the first time, it detects a USB stick drive even though there isn't one in the port. It tries to open a file and errors out. It gets stuck running SYS_FS_Unmount and repeatedly failing. However, if I just do a reset through the debugger, keep power on and run the code again, it does not detect the non-existing drive in the port. It will work after that just fine. It detects when I attach a stick every time. This only happens when I remove power from the board and re-apply it.
 
Anyone have any ideas?
 
Regards,
 
Sebastian
 
Update:
I ran the demo on my hardware and it is not exhibiting the same behavior. I checked the settings in the Configurator and they seem to be correct. The difference though is that I have 2 file systems. One for the SD card and one for the USB MSD. Auto Mount Feature is turned on and set to two clients. I also checked again the demo app against my app and it seems to be the same.
post edited by SScheiff - 2020/05/15 15:27:54
#1

3 Replies Related Threads

    SScheiff
    Junior Member
    • Total Posts : 52
    • Reward points : 0
    • Joined: 2017/10/14 10:55:10
    • Location: 0
    • Status: offline
    Re: USB MSD event handler issue 2020/05/15 17:41:08 (permalink)
    0
    Some more troubleshooting seems to indicate the issue is with having two sets of media declared. It appears that the event handler for the USB stick drive is being called for the SD card as well. So if I unplug the SD card before I power up and run the board, it works as expected. I don't know why that is only the case on a power cycle, but apparently it is. I have no idea how to differentiate what media is calling the Callback function.
    #2
    Vincent44
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2014/09/19 03:41:47
    • Location: France
    • Status: offline
    Re: USB MSD event handler issue 2020/07/01 01:04:35 (permalink)
    0
    In a project where I have both SD and USB, I coded the Callback like so :
     
      
    SYS_FS_EventHandlerSet(myMediaMountEvent, (uintptr_t)NULL) ;     
     
    { ... }
     
    void myMediaMountEvent( SYS_FS_EVENT event, void* eventData, uintptr_t context)
      {
          switch(event)
          {
              //-------------------------------
              // A media has been mounted !
              case SYS_FS_EVENT_MOUNT:
                  // Check if it's USB Stick or SD Card
                  if(strcmp((const char *)eventData, SDCARD_MOUNT_NAME) == 0){
                      sdDetected = true;
                  }
                  else if(strcmp((const char *)eventData,USB_MOUNT_NAME) == 0)
                  {
                      usbDetected = true;
                  }
                  break;

              //-------------------------------
              // A media has been unmounted !
              case SYS_FS_EVENT_UNMOUNT:
                  // Check if it's USB Stick or SD Card
                  if(strcmp((const char *)eventData, SDCARD_MOUNT_NAME) == 0){
                      sdDetected = false;
                  }
                  else if(strcmp((const char *)eventData, USB_MOUNT_NAME) == 0){
                      usbDetected = false;
                  }
                  break;

              case SYS_FS_EVENT_ERROR:
                  break;
          }
      }

     
    Where the MOUNT_NAME is directly taken from the generated code by Harmony.

    #define SDCARD_MOUNT_NAME SYS_FS_MEDIA_IDX0_MOUNT_NAME_VOLUME_IDX0 // "/mnt/mySD"
    #define SDCARD_DEV_NAME SYS_FS_MEDIA_IDX0_DEVICE_NAME_VOLUME_IDX0 // "/dev/mmcblka1"

    #define USB_MOUNT_NAME SYS_FS_MEDIA_IDX1_MOUNT_NAME_VOLUME_IDX0
    #define USB_DEV_NAME SYS_FS_MEDIA_IDX1_DEVICE_NAME_VOLUME_IDX0

     
    Hope this helps.
    #3
    Paul PortSol
    Super Member
    • Total Posts : 630
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: USB MSD event handler issue 2020/07/02 07:23:06 (permalink)
    5 (1)
    Also ensure:
    - Big Heap (10K+)
    - Big Capacitor on USB when sourcing power to USB sticks (150uF 6V ceramic)
     
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5