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

Access to SD-card from µController AND from USB possible?

Hello,

I use the Evalboard MCB4300 and µVision 5.14 MDK-ARM Professional.
Is it possible to initialize MCI0 to read/write to an SD-Card using fopen()..fwrite()..fclose(),
AND also allow the user to use the SD-card as a mass storage device via USB? (access not at the same time, user selects when the USB-connection is alive) ?

I'm trying to do this, but currently it does not work, but I also do not get any errors from the functions I call.
I call fopen(), fwrite() fputc(), fclose() without errors, but afterwards the file on the sdcard has not changed.
All function calls return without an error (fwrite(), USBD_Initialize(0),USBD_Connect(0),...)
Access to the card from USB works fine.

Am I doing something wrong, or is this basically not supported?

What's wrong with this:

finit("M0:");
fmount("M0:");
f=fopen("M0:test1.txt","a");
fputs("Hello!", f);
fclose (f);
funmount ("M0:");
funinit("M0:"); => file is correct on SDCard

stat=finit ("M0:"); // init again
=> stat=7(fsDriverError) : why?

Later in the code there would follow calls to
ustat=USBD_Initialize (0); /* USB Device 0 Initialization */
ustat=USBD_Connect (0);

Thank you.

Parents
  • Hello,
    I tried this in a slightly different way, still without success.
    Access to the SD-Card via USB works as expected.

    I took the example "USB device Mass Storage (MBC4300)" and modified the mail loop:

    finit              ("M0:");           /* Initialize SD Card 0               */
    fmount             ("M0:");           /* Mount SD Card 0                    */
    USBD_Initialize    (0);               /* USB Device 0 Initialization        */
    USBD_Connect       (0);               /* USB Device 0 Connect               */
    while (1) {
      osDelay(10);
    
      // added code start:
      if(button_pressed() ) {
        USBD_Disconnect (0);
        USBD_Uninitialize(0); // this fails, stays in an endless loop, see below
        f=fopen("M0:test4.txt","a");
        fprintf(f,"data written\n");
        fclose (f);
        USBD_Initialize(0);
        USBD_Connect(0);
      }
      // added code end
    }
    

    USBD_Uninitialize(0) never returns:
    in file USBD0_LPC43xx.c:

     // Disable USB0 register interface clock
     LPC_CCU1->CLK_M4_USB1_CFG &= ~1;
     while (LPC_CCU1->CLK_M4_USB0_STAT & 1); // endless loop here
    

    If USBD_Uninitialize(0) would not fail:
    Could this method (disconnect/disable USB to allow write access to SD-Card from firmware) work?

    Any idea why USBD_Uninitialize() fails?

    Without the surrounding USBD_Uninitialize()/USBD_Initialize() the code is executed, fopen() and fprintf() and fclose() do not return any errors, but the file on the SD-card is not modified.

Reply
  • Hello,
    I tried this in a slightly different way, still without success.
    Access to the SD-Card via USB works as expected.

    I took the example "USB device Mass Storage (MBC4300)" and modified the mail loop:

    finit              ("M0:");           /* Initialize SD Card 0               */
    fmount             ("M0:");           /* Mount SD Card 0                    */
    USBD_Initialize    (0);               /* USB Device 0 Initialization        */
    USBD_Connect       (0);               /* USB Device 0 Connect               */
    while (1) {
      osDelay(10);
    
      // added code start:
      if(button_pressed() ) {
        USBD_Disconnect (0);
        USBD_Uninitialize(0); // this fails, stays in an endless loop, see below
        f=fopen("M0:test4.txt","a");
        fprintf(f,"data written\n");
        fclose (f);
        USBD_Initialize(0);
        USBD_Connect(0);
      }
      // added code end
    }
    

    USBD_Uninitialize(0) never returns:
    in file USBD0_LPC43xx.c:

     // Disable USB0 register interface clock
     LPC_CCU1->CLK_M4_USB1_CFG &= ~1;
     while (LPC_CCU1->CLK_M4_USB0_STAT & 1); // endless loop here
    

    If USBD_Uninitialize(0) would not fail:
    Could this method (disconnect/disable USB to allow write access to SD-Card from firmware) work?

    Any idea why USBD_Uninitialize() fails?

    Without the surrounding USBD_Uninitialize()/USBD_Initialize() the code is executed, fopen() and fprintf() and fclose() do not return any errors, but the file on the SD-card is not modified.

Children