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

fopen cannot write memroy card

I use lpc4357, and config file system & usb0 following the demo code of MCB4300.
The usb seems work, for I can read/write file via the usb interface.
When I create file failed by calling

fopen("TEXT.txt","w")

, it failed;
but, calling

fopen("TEXT.txt","rb")

seems ok (the return file handler not null if the file exist).
I just wander, what went wrong? Any idea is welcome!

  • Did you check the status of Write Protect switch?

  • Thanks for your reply, Vladimir Umek!
    You mentioned about "write protect switch"?
    It's hardware, or software?

    Oops, there's additional info updated:
    I cann't handle file with any of the options (read/write/...).
    Yes, I can get the file handler by calling

    fp = fopen ("TEXT.txt", "r")
    


    And It's not null, but I can do nothing to it, even calling

    num = fread(buff, 1, 10, fp)
    


    The num is 0, the buff is empty...
    But, I can read/write the sdcard via usb0...

    Just keep confusing...

  • Ok, the last info updated:
    If comment the code of usb0 (init, connect), then I can handle the file with these functions (open/read/write).

    Then, the question is: how to make these two work at the same time? I use the code all from MDK-Middleware 7.0.0.

  • If you can use Middleware then i assume you have a valid MDK PRO license.

    In that case, contact keil support directly

  • Note that for a USB file system, the PC assumes it owns the file system which allows it to cache data from the memory.

    How often have you seen a USB thumb drive that suddenly modifies files or adds files without the PC you connected it to actually accessing the drive?

    The way to allow multiple sources to perform updates to the same file system would basically be to implement a networked server. A computer that accesses a server knows that the information is shared, so any information not explicitly locked may be changed by someone else at any time.

  • Thanks for your reply, Per Westermark!

    The device we are developing, will power up when plugging into usb port.
    And, it allows user to enter mass storage mode manually.

    So, the user may do some options (create/delete/rename/...) during the usb0 is on.
    If, I say if, the file system in the MDK does not allow to do that, then we will try to add some prompt to tell the user avoid a try.

  • Thanks for your reply, Sankalp Agarwal!

    Yes, I have. But, I like collecting info from forum before turning to the tech support.
    I always think that there're lots of people who know a lot & are pleased to help others. Sometimes, the problem comes out when I missing something important. So, anyone's thought is helpful at some point. And I can learn a lot from them.