• AVR Freaks

How to eject properly the MDD -SD Card Reader example under MAC OSX

Author
reversale
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2010/10/09 23:43:17
  • Location: 0
  • Status: offline
2010/12/22 03:23:18 (permalink)
0

How to eject properly the MDD -SD Card Reader example under MAC OSX

Dear,    

I currently use the library USB V2.8 and the example  USB "Mass Storage Device / SD card", on a board with a PIC32MX440F512H.
When I eject the SD card under Windows XP, I have no problem.
But under Mac OSX 10.6, SD card appears again after 10 seconds after ejecting... I can't eject the SD card. It disappears, then reappears.
I do not understand why, and I don't find where I can get the information request disconnection from the Mac.

Thank you in advance for your help and sorry for bad english (I'm french;-(

Best regards

Nicolas
post edited by reversale - 2010/12/23 15:21:50
#1

10 Replies Related Threads

    reversale
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2010/10/09 23:43:17
    • Location: 0
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/24 03:10:26 (permalink)
    0
    Help....
    Anyone uses mass storage card on  USB on mac osx?
    #2
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/25 10:19:19 (permalink)
    0

    Last week, I was too busy to set up test bench for this problem.
    Finally, I've finished (most of) my job of this year.

    The problem was reproduced on my Mac (MacOSX 10.6.5)
    I took a trace on a hardware bus analyzer for the Microchip example.
    And now I'm comparing the trace with those of a commercial card reader, which doesn't have this problem.
    Please wait for a while.

    Tsuneo
    #3
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/25 12:51:35 (permalink)
    +2 (1)
    Problem: MSC drive re-appears after drag-to-trash eject on MacOSX (10.6.5)
    Microchip example: "USB Device - Mass Storage - SD Card reader" v2.8, v2010-10-19

    A bus analyzer trace of Microchip example was compared with those of an existing card reader (MCR-C7/U2).
    The result is as follows.

    The major difference is the response to PREVENT ALLOW MEDIUM REMOVAL
    Microchip's succeeds on this command, but the other failed.

    Microchip
    [25.781,000] FS: Data Transfer (Bulk-OUT) Addr:04 Endp:1 - CBW: PREVENT ALLOW MEDIUM REMOVAL
                 55 53 42 43 24 00 00 00 00 00 00 00 00 00 06 1E
                 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
    [25.781,240] FS: Data Transfer (Bulk-IN) Addr:04 Endp:1 - CSW - Status:Passed
                 55 53 42 53 24 00 00 00 00 00 00 00 00

    MCR-C7/U2
    [38.347,101] HS: Data Transfer (Bulk-OUT) Addr:04 Endp:2 - CBW: PREVENT ALLOW MEDIUM REMOVAL
                 55 53 42 43 B8 00 00 00 00 00 00 00 00 03 06 1E
                 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
    [38.348,765] HS: Data Transfer (Bulk-IN) Addr:04 Endp:2 - CSW - Status:Failed
                 55 53 42 53 B8 00 00 00 00 00 00 00 01
    [38.349,053] HS: Data Transfer (Bulk-OUT) Addr:04 Endp:2 - CBW: REQUEST SENSE
                 55 53 42 43 B9 00 00 00 12 00 00 00 80 03 06 03
                 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00
    [38.350,369] HS: Data Transfer (Bulk-IN) Addr:04 Endp:2 - MSC Data In
                 70 00 05 00 00 00 00 0A 00 00 00 00 24 00 00 00
                 00 00
    [38.351,187] HS: Data Transfer (Bulk-IN) Addr:04 Endp:2 - CSW - Status:Passed
                 55 53 42 53 B9 00 00 00 00 00 00 00 00


    Other than this difference, these difference may affect to this problem.

    INQUIRY
    Microchip             00 80 04 02 20 00 00 00 4D 69 63 72 6F 63 68 70
                          4D 61 73 73 20 53 74 6F 72 61 67 65 20 20 20 20
                          30 30 30 31

    MCR-C7/U2             00 80 00 02 1F 00 00 00 42 55 46 46 41 4C 4F 20
                          53 44 20 43 41 52 44 20 52 65 61 64 65 72 20 20
                          33 2E 31 37

    MODE SENSE(6)
    Microchip             02 00 00 00

    MODE SENSE(10)
    MCR-C7/U2             00 26 00 00 00 00 00 00


    I'll post more detailed analysis on these results, tomorrow.
    It's too late here, good night!

    Tsuneo
    #4
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/26 06:35:37 (permalink)
    +2 (1)
    At the mount of SD card, MacOSX puts PREVENT ALLOW MEDIUM REMOVAL(PREVENT:01b - prohibit removal), to know the auto-eject capability of the card reader.

    a) Auto eject
    If the device succeeds on this command, OS assumes auto-eject capability of the reader.
    On drag-to-trash eject, MacOSX writes the write cache to the SD card. And then, it puts this command sequence, to eject the SD card by command.

    - PREVENT ALLOW MEDIUM REMOVAL(PREVENT:00b - allow removal)
    - START STOP UNIT

    After START STOP UNIT, the device should fail TEST UNIT READY and other commands, because of no media.


    b) Manual eject
    Manual eject reader should fail PREVENT ALLOW MEDIUM REMOVAL(PREVENT:01b) at the mount of SD card.
    The Sense Data for this fail is,
    - Sense Key: ILLEGAL REQUEST (0x05)
    - ASC/ASCQ : INVALID FIELD IN CDB (0x24/0x00)

    On eject, MacOSX writes the write cache to the SD card.
    And then, it polls manual eject using TEST UNIT READY


    The problem on Microchip example is caused by the response that it succeeds PREVENT ALLOW MEDIUM REMOVAL(PREVENT:01b) at mount of SD card, though the SD Card PICTail Plus board doesn't have auto-eject capability. It should fail this SCSI command.

    Here is a fix for this problem.
     
    C:\Microchip Solutions v2010-10-19\Microchip\USB\MSD Device Driver\usb_function_msd.c

    void MSDProcessCommandMediaPresent(void)
    {
        BYTE i;

        switch(MSDCommandState)
        {
            ...
            ...
                          // <--- comment MSD_PREVENT_ALLOW_MEDIUM_REMOVAL handler,
                          //      so that this command fails with S_ILLEGAL_REQUEST Sense data
    /*             
            case MSD_PREVENT_ALLOW_MEDIUM_REMOVAL:
                if(LUNMediaDetect())
                {
                    msd_csw.bCSWStatus=0x00;
                    msd_csw.dCSWDataResidue=0x00;
                }
                else
                {
                    gblSenseData[LUN_INDEX].SenseKey=S_NOT_READY;
                    gblSenseData[LUN_INDEX].ASC=ASC_MEDIUM_NOT_PRESENT;
                    gblSenseData[LUN_INDEX].ASCQ=ASCQ_MEDIUM_NOT_PRESENT;
                    msd_csw.bCSWStatus=0x01;
                }
                MSDCommandState = MSD_COMMAND_WAIT;
                break;
    */


    Tsuneo
    post edited by chinzei - 2010/12/26 06:37:18
    #5
    reversale
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2010/10/09 23:43:17
    • Location: 0
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/27 09:43:55 (permalink)
    +2 (1)

    Dear,

    I have found my savior :-)
    [font="arial, sans-serif; line-height: normal; font-size: 16px; "]

    But when I comment this parts :
    /*               
             case MSD_PREVENT_ALLOW_MEDIUM_REMOVAL: 
                 if(LUNMediaDetect()) 
                 { 
                     msd_csw.bCSWStatus=0x00; 
                     msd_csw.dCSWDataResidue=0x00; 
                 } 
                 else 
                 { 
                     gblSenseData[LUN_INDEX].SenseKey=S_NOT_READY; 
                     gblSenseData[LUN_INDEX].ASC=ASC_MEDIUM_NOT_PRESENT; 
                     gblSenseData[LUN_INDEX].ASCQ=ASCQ_MEDIUM_NOT_PRESENT; 
                     msd_csw.bCSWStatus=0x01; 
                 } 
                 MSDCommandState = MSD_COMMAND_WAIT; 
                 break; 
     */

    The removable disk no longer appears, and when I remove the comment all work normally...

    Thanks lot for your help !!!!

    Best regards

    Nicolas
     






    #6
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2010/12/27 18:09:05 (permalink)
    +2 (1)
    Ah, sorry.
    I missed to pick up another fix portion.
    In addition to above fix, the default case of the same subroutine should be fixed as follows.

    C:\Microchip Solutions v2010-10-19\Microchip\USB\MSD Device Driver\usb_function_msd.c

    void MSDProcessCommandMediaPresent(void)
    {
        BYTE i;

        switch(MSDCommandState)
        {
            ...
            ...
            default:
                ResetSenseData();
                gblSenseData[LUN_INDEX].SenseKey=S_ILLEGAL_REQUEST;
                gblSenseData[LUN_INDEX].ASC=ASC_INVALID_COMMAND_OPCODE;
                gblSenseData[LUN_INDEX].ASCQ=ASCQ_INVALID_COMMAND_OPCODE;
                msd_csw.bCSWStatus=0x01;
                msd_csw.dCSWDataResidue=0x00;
    //          MSDCommandState = MSD_COMMAND_RESPONSE;         // <------------
                MSDCommandState = MSD_COMMAND_WAIT;
                break;


    Tsuneo

    post edited by chinzei - 2010/12/27 18:10:35
    #7
    reversale
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2010/10/09 23:43:17
    • Location: 0
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2011/04/18 06:57:34 (permalink)
    0
    Hi Tsuneo,

    First, I thank you for your help and sorry for the lack of thanks.

    I'll re-contact you because I have now a problem on windows xp and windows 7 with your modification

    Now put the removable disk take very long time to appear on windows xp and windows 7.

    It takes about 1min to 1min30 see the removable disk recognized.

    Would you have any idea what's going on?

    Thank you in advance for help.

    Best regards

    Nicolas
    #8
    govind_mukundan
    Super Member
    • Total Posts : 188
    • Reward points : 0
    • Joined: 2009/05/12 23:50:07
    • Location: singapore/india
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2011/04/21 03:44:39 (permalink)
    0
    Hi Reversale,

    I have the same problem when I connect my device to a Mac. Our device is supposed to act as a MSD USB device on connecting to a Mac, and we have an internal NAND flash. 

    We've had this bug for a while, and no one has looked into it. I tried Tsueno's solution now and it works perfectly. However, instead of commenting out the switch case MSD_PREVENT_ALLOW_MEDIUM_REMOVAL, I modified the existing code in the case and left the default case untouched.

    Now it works fine with Mac and Windows XP SP3. Have not tested on windows 7 yet. Perhaps your problem is related to something else or you could try not modifying the "default" case?

    Further according to Jan Axelson's USB MSD book page 146, in the "PREVENT ALLOW MEDIUM REMOVAL" section  - 
    "Flash drives that fail this command when PREVENT = 01 have improved performance. When the command fails, Windows doesn’t enable write caching. Write caching causes Windows to launch multiple threads that cause random writes, which result in slow write performance on flash media."

    So Windows performance should actually be better now..

    Govind
    #9
    reversale
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2010/10/09 23:43:17
    • Location: 0
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2011/04/21 08:25:46 (permalink)
    0
    Hello Govind,

    Your solution interests me :-)
    I seek the solution for 2 months ...
    Could you give me the changes you made in the
    MSD_PREVENT_ALLOW_MEDIUM_REMOVAL box?
    Because I really starting to depress ...

    Thank you in advance

    Nicolas
    #10
    govind_mukundan
    Super Member
    • Total Posts : 188
    • Reward points : 0
    • Joined: 2009/05/12 23:50:07
    • Location: singapore/india
    • Status: offline
    Re:How to eject properly the MDD -SD Card Reader example under MAC OSX 2011/04/24 19:24:07 (permalink)
    0
    Hi Nicholas,

    Sorry I was off work for the weekend. My change is basically the same as already suggested except for where I'm handling the event, you can see it below.




    case MSD_PREVENT_ALLOW_MEDIUM_REMOVAL:
               /* if(LUNMediaDetect())
                {
             msd_csw.bCSWStatus=0x00;
             msd_csw.dCSWDataResidue=0x00;
             }
                else
                {
             gblSenseData[LUN_INDEX].SenseKey=S_NOT_READY;
             gblSenseData[LUN_INDEX].ASC=ASC_MEDIUM_NOT_PRESENT;
             gblSenseData[LUN_INDEX].ASCQ=ASCQ_MEDIUM_NOT_PRESENT;
             msd_csw.bCSWStatus=0x01;
             }
    MSDCommandState = MSD_COMMAND_WAIT; */

    /* Govind - Fix for Mac OS 
          Refer: http://www.microchip.com/forums/tm.aspx?m=544989 */
         ResetSenseData();
                 gblSenseData[LUN_INDEX].SenseKey=S_ILLEGAL_REQUEST;
                 gblSenseData[LUN_INDEX].ASC=ASC_INVALID_COMMAND_OPCODE;
                 gblSenseData[LUN_INDEX].ASCQ=ASCQ_INVALID_COMMAND_OPCODE;
                 msd_csw.bCSWStatus=0x01;
                 msd_csw.dCSWDataResidue=0x00;
         MSDCommandState = MSD_COMMAND_WAIT;
                break;


    The "default" case is unchanged.



    default:
             ResetSenseData();
    gblSenseData[LUN_INDEX].SenseKey=S_ILLEGAL_REQUEST;
    gblSenseData[LUN_INDEX].ASC=ASC_INVALID_COMMAND_OPCODE;
    gblSenseData[LUN_INDEX].ASCQ=ASCQ_INVALID_COMMAND_OPCODE;
    msd_csw.bCSWStatus=0x01;
    msd_csw.dCSWDataResidue=0x00;
    MSDCommandState = MSD_COMMAND_RESPONSE;
         break;





    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5