Hello, I would like to configure my STM32F769 so that the connected USB stick can be used by windows explorer as a mass data storage device.
I have already tried it with the example programs. So it is possible to display an SD card or a memory area in the explorer. But a USB stick does not work. The function fs_ioc_get_id ("U0:") always returns an error 0xFFFFFFFD. It seems that the I/O control interface routines do not support a USB stick.
It is not the hardware, in other programs I can write to the USB stick normally when it is connected to the device. Only that forwarding as MSC is not possible.
Has anyone here ever done this before and could help?
My Code looks like this:
#define MEDIA_DRIVE "U0:" any_Thread() { USBD_Initialize(0U); USBD_Connect(0U); ... } void USBD_MSC0_Initialize (void) { uint32_t param_status; usbd_msc0_media_own = MEDIA_OWN_USB; // Initially media is owned by USB media_ok = false; // Current media status (not initialized = not ok) if (finit (MEDIA_DRIVE) != fsOK) { // Initialize File System return; // Exit if failed } drv_id = fs_ioc_get_id (MEDIA_DRIVE); // Get ID of media drive if (drv_id < 0) { return; } // If ID is invalid exit param_status = 0U; // Parameter for function call is 0 // Initialize media if (fs_ioc_device_ctrl (drv_id, fsDevCtrlCodeControlMedia, ¶m_status) != fsOK) { return; // Exit if failed } if (fs_ioc_lock (drv_id)) { // Lock media for USB usage return; // Exit if failed } media_ok = true; // Media was initialized and is ok }
Currently IOC is not allowed for USB Host Mass Storage.What would be the usage case of your setup?
Best regards, Milorad
Thanks Milorad.
At the moment, all data recorded by the device are stored on a USB stick. We would like to offer the possibility to access the data directly when the device is controlled remotely without always having to connect the stick to the PC.
Since the whole thing is based on the file system I would have thought that this would also be possible for USB. As this is not the case I will not pursue this approach any further at the moment.
Hi Alexander.
You could implement this functionality by changing the USBD_User_MSC.c template and calling USB Host MSC functions directly from USB Device MSC callbacks instead of calling IOC as currently is done in the template.
The USB Host MSC functions are:
void USBH_MSC_Initialize (uint8_t instance); void USBH_MSC_Uninitialize (uint8_t instance); usbStatus USBH_MSC_GetStatus (uint8_t instance); usbStatus USBH_MSC_Read (uint8_t instance, uint32_t lba, uint32_t cnt, uint8_t *buf); usbStatus USBH_MSC_Write (uint8_t instance, uint32_t lba, uint32_t cnt, const uint8_t *buf); usbStatus USBH_MSC_ReadCapacity (uint8_t instance, uint32_t *block_count, uint32_t *block_size);
Of course you need to handle ownership also.
So, when PC is accessing the USB Stick then file system from the MCU cannot access it and vice versa.