cancel
Showing results for 
Search instead for 
Did you mean: 

Read-Only MMC with USB-FS-Device_Lib for STM32F1xx

alexanderpolleti9
Associate II
Posted on October 28, 2014 at 16:47

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 #mmc
4 REPLIES 4
Posted on October 28, 2014 at 18:38

\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;
}
...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
alexanderpolleti9
Associate II
Posted on October 30, 2014 at 15:18

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 find

IsWriteProtected

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.
Posted on October 30, 2014 at 17:02

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
alexanderpolleti9
Associate II
Posted on October 30, 2014 at 18:00

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 changed

uint8_t Mode_Sense10_data[] =

{ 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; to

uint8_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?