This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Bugs in USB Developers Package: Write Protection

Problem: once the write protection is set during the program execution via setting writeProtected flag in USBMSC_mediaInfoStr structure and calling USBMSC_updateMediaInfo(), it can not be reset back.

There is a bug in USB Developers Package, at least at revision 4.10.00 (the one I work with). To fix it go to UsbMscScsi.c file.

Scsi_Mode_Sense6() function: Replace

Scsi_Mode_Sense_6[2] |= (MscControl[McsCbw.bCBWLUN].bWriteProtected << 0x7);

with

Scsi_Mode_Sense_6[2] = (MscControl[McsCbw.bCBWLUN].bWriteProtected << 0x7);


Scsi_Mode_Sense10() function: Replace

Scsi_Mode_Sense_10[4] |= (MscControl[McsCbw.bCBWLUN].bWriteProtected << 0x7);

with

Scsi_Mode_Sense_10[4] = (MscControl[McsCbw.bCBWLUN].bWriteProtected << 0x7);

It fixes the bug.

  • Hi Serge,

    Thank you so much for reporting this - I'll notify the developers to make sure that this gets fixed.

    Regards,

    Katie

  • Hello,

    I am looking into this issue.  Can you tell me what type of error you get when you try and reset the write protection flag?

    Aslo are you setting the write protection when MSC is being initialized and then resetting the flag in the main program?

     

    Regards,

    Arthi Bhat

  • Hello,

    If the write protection is set during execution time then it can be reset back during execution time by doing the following:

    USB_disconnect();

    USB_disable();

    mediaInfo.writeProtected = 0x00;

    USBMSC_updateMediaInfo(0, &mediaInfo);

    USB_enable();

    USB_reset();

    USB_connect();

     

    Regards,

    Arthi

     

  • Arthi Bhat1 said:

    Hello,

    I am looking into this issue.  Can you tell me what type of error you get when you try and reset the write protection flag?

    Aslo are you setting the write protection when MSC is being initialized and then resetting the flag in the main program?

     

    Regards,

    Arthi Bhat

    Hi Arthi,

    There is no error generated while calling USBMSC_updateMediaInfo() for resetting write protection flag. It just does not perform actual reset of this flag. The host connected to this USB device still shows the volume as 'read only'. And the reason why it happens is shown and fixed in code that I included. Corresponding bit can not be reset by bitwise OR operation. I did consider it as a bug, fixed it and it seems to work since then without any problem. The workaround you've suggested may work as well, though it is not always desirable or possible to perform full USB stack re-initialisation.

     

    Best regards,

    Serge

**Attention** This is a public forum