Skip to main content
Visitor II
Oct 2, 2026 12:10 PM UTC
Solved

found USB MSC library bug

in “usbd_msc_scsi.c” at function “SCSI_ModeSense6”
/* Check If media is write-protected */

  if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)

  {

    MSC_Mode_Sense6_data[2] |= (0x1U << 7); /* Set the WP (write protection) bit */

  }

  else

  {

    MSC_Mode_Sense10_data[2] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */

  }


is writing to the wrong place !!!   
Change it to:
MSC_Mode_Sense6_data[2] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */

Note:
The wrong write mainly cause the write protection to stay on if its once set and never be able to unset without reseting the scsi device.

Took me days to track down this bug !!

 
best regards,
Labmaster
 
Pavel A.
Pavel A.Best answer
Oct 2, 2026 7:24 PM UTC

3 replies

Pavel A.
Pavel A.Best answer
Oct 2, 2026 7:24 PM UTC
TDK
Oct 3, 2026 3:36 PM UTC

And was updated 6 months ago. No doubt you just need to update. Good spot, but it was already fixed it seems.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."