This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Usage of function "USBD_MSC0_SetMediaOwnerFS()"

Hello,

I've ported an example for an Infineon Evalboard to the MBC4300 Evalboard. The example shows how to access the SD-Card file system either via USB host or from the uController.

http://www.keil.com/appnotes/docs/apnt_273.asp

This example seems to work as expected on my MBC4300, I can access the SD-Card from PC Host and the uController can write files onto the SD-Card.
I want to use a similar case in my application, but something does not work as expexted, so I went back to the example code to look at some details using the debugger.

// original code from the example:
case DEV_START_RECORD:
        // hide logical unit
/*B1*/     USBD_MSC0_SetMediaOwnerFS();
        finit("M0:");
        fmount("M0:");
        f_but = fopen("ButtonsLog.txt","a");
        f_adc = fopen("AdcLog.txt","a");
        ADC_StartConversion();
        gState = DEV_RECORDING;
        break;

This code should change the ownership to the uController and create two files.

Condition 1: NO USB-Cable is attached
When I set a breakpoint at B1 and step over the function "USBD_MSC0_SetMediaOwnerFS()" it takes ~3 seconds (timeout defined inside the function)
After the call the Variable "usbd_msc0_media_own" is 2 which means a change is requested (and still pending).
Function returns USBD_MSC0_ERROR.
The following functions (finit, fmount, fopen) do NOT fail although the ownership is not granted.

Condition 2: USB-Cable IS attached
Function returns "USBD_MSC0_OK" after <1sec.
After the call the Variable "usbd_msc0_media_own" is 0

I would expect the opposite behavior.

I don't have the Infineon Evalboard so I cannot test the original unmodified example.
Is it possible that I made a mistake when I ported the example?

Is there a more detailed documentation available about the functions USBD_MSC0_SetMediaOwnerFS() and USBD_MSC0_SetMediaOwnerUSB()

e.g.:
Does it automatically close open files when ownership is changed from FS to USB?
Would it reject a change from USB to FS when the USB-host accesses the SD-Card?
Would it allow a change from USB to FS when the USB-cable is plugged in but USB-host does NOT access athe SD-card?
Thank you.

Parents
  • Well, you are correct, if cable is disconnected, function to switch ownership will timeout, and it is best then that you manually mount SD Card for usage with File System.

    You will probably be able to figure out the details on how to do that by analyzing source file responsible for executing the switch (the mechanics) which is in USBD_User_MSC_0.c file most important part is in function uint32_t USBD_MSC0_CheckMedia (void).

    BTW there is an official MassStorage example for Keil's MCB4300 eval board in LPC4300_DFP pack in a path similar to this:
    C:\Keil\ARM\Pack\Keil\LPC4300_DFP\2.4.0\Boards\Keil\MCB4300\Middleware\USB\Device\MassStorage

Reply
  • Well, you are correct, if cable is disconnected, function to switch ownership will timeout, and it is best then that you manually mount SD Card for usage with File System.

    You will probably be able to figure out the details on how to do that by analyzing source file responsible for executing the switch (the mechanics) which is in USBD_User_MSC_0.c file most important part is in function uint32_t USBD_MSC0_CheckMedia (void).

    BTW there is an official MassStorage example for Keil's MCB4300 eval board in LPC4300_DFP pack in a path similar to this:
    C:\Keil\ARM\Pack\Keil\LPC4300_DFP\2.4.0\Boards\Keil\MCB4300\Middleware\USB\Device\MassStorage

Children
No data