2014-10-28 08:47 AM
Hello Everybody,
is it possible to crate an application as a read-only device with the USB-FS-Device_Lib for STM32F1xx? When I crate an application with CubeMX for STM32F4, I can edit a function ''STORAGE_IsWriteProtected_FS'', but I can't find anything similar for the library with the STM32F1 from the page (not CubeMX). Thanks for you Help Alex #usb #stm32f1 #mmc2014-10-28 10:38 AM
\STM32_USB-Host-Device_Lib_V2.1.0\Project\USB_Device_Examples\MSC\src\usbd_storage_msd.c
int8_t STORAGE_IsWriteProtected (uint8_t lun); Basically all it's going to do is throw a WRITE PROTECTED sense code as it errors out of the SCSI WRITE command.static int8_t SCSI_Write10 (uint8_t lun , uint8_t *params)
{
if (MSC_BOT_State == BOT_IDLE) /* Idle */
{
...
/* Check If media is write-protected */
if(USBD_STORAGE_fops->IsWriteProtected(lun) !=0 )
{
SCSI_SenseCode(lun,
NOT_READY,
WRITE_PROTECTED);
return -1;
}
...
2014-10-30 07:18 AM
Thank you for your reply.
I am using the STM32_USB-FS-Device_Lib in Version 3.xx (I don't know where to search for the exact version) Even with the New Version 4.0.0 (from http://www.st.com/web/en/catalog/tools/PF258157# ) I cannot findIsWriteProtected
anywhere.
I tried the following:
void
SCSI_Write10_Cmd(uint8_t lun , uint32_t LBA , uint32_t BlockNbr)
{
if
(CBW.dDataLength == 0)
{
Bot_Abort(DIR_IN);
}
else
{
if
((CBW.bmFlags & 0x80) != 0)
{
Bot_Abort(DIR_IN);
}
else
{
Bot_Abort(BOTH_DIR);
}
}
Set_Scsi_Sense_Data(lun, 7, WRITE_PROTECTED);
Set_CSW (CSW_CMD_FAILED, SEND_CSW_DISABLE);
return
;
}
with defining WRITE_PROTECTED as 0x27 (like in the Library from CubeMX for the STM32F4)
But when I insert the USB-Plug to the PC the media is still not write protected.
2014-10-30 09:02 AM
Well the code protects you from actually writing, if you want the DEVICE to report as read only in the OS, then the WP (Write Protect) bit of the Mode Parameter Header returned by MODE SENSE needs to reflect this.
2014-10-30 10:00 AM
This should be the Mode_Sense10_data, isn't it? After reading
http://www.usb.org/developers/docs/devclass_docs/usbmass-ufipdf
(Page 24) I changeduint8_t Mode_Sense10_data[] =
{ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; touint8_t Mode_Sense10_data[] =
{
0x00,
0x06,
0x00,
0x80, /* Write protection bit */
0x00,
0x00,
0x00,
0x00
};
But Windows still doesn't recognize it as a write protected media. Is there anything else (ore somewhere els) to change?