2025-11-27 12:13 AM
Hello!
i'm developing a firmware that use an SD card connected to USBX MSC, and i have a couple of question
i want to understand better the ULONG *media_status value returned in the function :
UINT USBD_STORAGE_Status(VOID *storage_instance, ULONG lun,
ULONG media_id,ULONG *media_status)
UINT USBD_STORAGE_Flush(VOID *storage_instance, ULONG lun, ULONG number_blocks,
ULONG lba, ULONG *media_status)
UINT USBD_STORAGE_Write(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status)
UINT USBD_STORAGE_Read(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status) i'm hoping that value is related to the SCSI code value that windows need from a USB MSC
is it true? beyond UX_SUCCESS which value can i use? for example to indicate the media as changed or is readonly?
how can the functions ULONG USBD_STORAGE_GetMediaLastLba(VOID) and ULONG USBD_STORAGE_GetMediaBlocklength(VOID) can be fired againafter initialization? (maybe i have changed the SD card)
whats the meaning of this function?
UINT USBD_STORAGE_Notification(VOID *storage_instance, ULONG lun, ULONG media_id,
ULONG notification_class, UCHAR **media_notification,
ULONG *media_notification_length)
thank you!
best reguards
2025-11-27 1:58 AM
Hi @ABasi.2
Checking USBX documentation I found : media_status should be filled out exactly like the media status callback return value. Check here for further details.
The return value of your read/write/flush functions is only UX_SUCCESS or UX_ERROR. It could be UX_STATE_NEXT in standalone applications.
About USBD_STORAGE_Notification is not commonly used in simple applications. Its purpose to provide a buffer with notification data to the host.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-11-27 2:11 AM
HELLO @FBL
media_status should be filled out exactly like the media status callback return value and what does it mean? if i want to tell windows the media as changed? or if is now read only?
how to do that?
where the SCSI code are used?
The return value of your read/write/flush functions is only UX_SUCCESS or UX_ERROR. It could be UX_STATE_NEXT in standalone applications. ok for that, is the only "OK or error" return
About USBD_STORAGE_Notification is not commonly used in simple applications. Its purpose to provide a buffer with notification data to the host.
my isn't a "simple application" there is documentation about that?
i need to make a professional use of USBX msc , with using changed media , media in read only, ability to disconnect and reconnect the SD card , use of SCSI code ecc
there is a complex example or at least documentation about that?
thank you
2025-11-27 8:15 AM
hello @FBL
i'm trying to follow the USBX code because the documentation you send me in the link said:
ULONG media_status(
VOID *storage,
ULONG lun,
ULONG media_id,
ULONG *media_status);
```
The calling parameter media_id is not currently used and should always be 0. In the future it may be used to distinguish multiple storage devices or storage devices with multiple SCSI LUNs. This version of the storage class does not support multiple instances of the storage class or storage devices with multiple SCSI LUNs.
The return value is a SCSI error code that can have the following format.
- **Bits 0-7** Sense_key
- **Bits 8-15** Additional Sense Code
- **Bits 16-23** Additional Sense Code Qualifier
The following table provides the possible Sense/ASC/ASCQ combinations.
| Sense Key | ASC | ASCQ | Description |
| --------- | --- | ---- | ------------------------------------------------- |
| 00 | 00 | 00 | NO SENSE |
| 01 | 17 | 01 | RECOVERED DATA WITH RETRIES |
| 01 | 18 | 00 | RECOVERED DATA WITH ECC |
| 02 | 04 | 01 | LOGICAL DRIVE NOT READY - BECOMING READY |
| 02 | 04 | 02 | LOGICAL DRIVE NOT READY - INITIALIZATION REQUIRED |
| 02 | 04 | 04 | LOGICAL UNIT NOT READY - FORMAT IN PROGRESS |
| 02 | 04 | FF | LOGICAL DRIVE NOT READY - DEVICE IS BUSY |
| 02 | 06 | 00 | NO REFERENCE POSITION FOUND |
| 02 | 08 | 00 | LOGICAL UNIT COMMUNICATION FAILURE |
| 02 | 08 | 01 | LOGICAL UNIT COMMUNICATION TIME-OUT |
| 02 | 08 | 80 | LOGICAL UNIT COMMUNICATION OVERRUN |
| 02 | 3A | 00 | MEDIUM NOT PRESENT |
| 02 | 54 | 00 | USB TO HOST SYSTEM INTERFACE FAILURE |
| 02 | 80 | 00 | INSUFFICIENT RESOURCES |
| 02 | FF | FF | UNKNOWN ERROR |
| 03 | 02 | 00 | NO SEEK COMPLETE |
| 03 | 03 | 00 | WRITE FAULT |
| 03 | 10 | 00 | ID CRC ERROR |
| 03 | 11 | 00 | UNRECOVERED READ ERROR |
| 03 | 12 | 00 | ADDRESS MARK NOT FOUND FOR ID FIELD |
| 03 | 13 | 00 | ADDRESS MARK NOT FOUND FOR DATA FIELD |
| 03 | 14 | 00 | RECORDED ENTITY NOT FOUND |
| 03 | 30 | 01 | CANNOT READ MEDIUM - UNKNOWN FORMAT |
| 03 | 31 | 01 | FORMAT COMMAND FAILED |
| 04 | 40 | NN | DIAGNOSTIC FAILURE ON COMPONENT NN (80H-FFH) |
| 05 | 1A | 00 | PARAMETER LIST LENGTH ERROR |
| 05 | 20 | 00 | INVALID COMMAND OPERATION CODE |
| 05 | 21 | 00 | LOGICAL BLOCK ADDRESS OUT OF RANGE |
| 05 | 24 | 00 | INVALID FIELD IN COMMAND PACKET |
| 05 | 25 | 00 | LOGICAL UNIT NOT SUPPORTED |
| 05 | 26 | 00 | INVALID FIELD IN PARAMETER LIST |
| 05 | 26 | 01 | PARAMETER NOT SUPPORTED |
| 05 | 26 | 02 | PARAMETER VALUE INVALID |
| 05 | 39 | 00 | SAVING PARAMETERS NOT SUPPORT |
| 06 | 28 | 00 | NOT READY TO READY TRANSITION – MEDIA CHANGED |
| 06 | 29 | 00 | POWER ON RESET OR BUS DEVICE RESET OCCURRED |
| 06 | 2F | 00 | COMMANDS CLEARED BY ANOTHER INITIATOR |
| 07 | 27 | 00 | WRITE PROTECTED MEDIA |
| 0B | 4E | 00 | OVERLAPPED COMMAND ATTEMPTED |so i have tried to follow the return of the UINT USBD_STORAGE_Status
so:
storage_parameter.ux_slave_class_storage_parameter_lun[0].
ux_slave_class_storage_media_status = USBD_STORAGE_Status;
in app_usbx_device.c
then:
/* Obtain the status of the device. */
status = storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_status(storage,
lun, storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_id, &media_status);in a bunch of function like read,write ecc
it seems the code check the status before doing any operation and thats great
but this status variable seems to me to be always rewritten, sure i'mmissing something
can you point me where if i use the return as SCSI sense key/ASC/ASCQ code like the documentations said is used?
thank you in advance
best reguards
2025-11-27 8:43 AM - edited 2025-11-27 8:45 AM
Unfortunately all examples provided are typical and not complex @ABasi.2
You've found the same reference !
I'm not the expert in USBX maybe someone else can help on this!
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-11-27 11:07 AM
Hello @FBL
i thank you for your effort to give me information, is very appreciated
but maybe a ST Employee expert in USBX can give us some more precise answer
best reguards
2025-11-28 9:12 AM
Hi @ABasi.2
It should be interesting in case implementing device msc with multiple LUNs; So far, I don't see any example supporting it.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-12-03 1:24 AM
Hello @FBL
it will be interesting for sure
but for me it's also interesting to have a project in which i can change the file on the media (i'm using SD card) and tell to the PC in wich the MSC is connected that the media in changed
also for this there is no example
i'm still hoping for a good hint about that..
maybe one of your collegue at ST expert in USBX can answer?
best reguards
2025-12-03 2:30 AM
Hi @ABasi.2
An internal ticket 223015 is submitted to USB experts to check if possible to provide any reference example.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.