简单测试程序如下:
__NO_RETURN void app_main (void *arg) {
usbStatus usb_status; // USB status
int32_t msc_status; // MSC status
FILE *f; // Pointer to stream object
uint8_t con = 0U; // Connection status of MSC(s)
(void)arg;
printf("这是一个演示!\r\n");
usb_status = USBH_Initialize (0U); // Initialize USB Host 0
if (usb_status != usbOK) {
for (;;) {} // Handle USB Host 0 init failure
}
for (;;) {
msc_status = USBH_MSC_DriveGetMediaStatus ("U0:"); // Get MSC device status
if (msc_status == USBH_MSC_OK) {
if (con == 0U) { // If stick was not connected previously
con = 1U; // Stick got connected
msc_status = USBH_MSC_DriveMount ("U0:");
if (msc_status != USBH_MSC_OK) {
continue; // Handle U0: mount failure
}
f = fopen ("Test.txt", "w"); // Open/create file for writing
if (f == NULL) {
continue; // Handle file opening/creation failure
}
fprintf (f, "USB Host Mass Storage!中文测试!\n");
fclose (f); // Close file
msc_status = USBH_MSC_DriveUnmount ("U0:");
if (msc_status != USBH_MSC_OK) {
continue; // Handle U0: dismount failure
}
}
} else {
if (con == 1U) { // If stick was connected previously
con = 0U; // Stick got disconnected
}
}
osDelay(100U);
}
}