Skip to main content
Stephan Scherer
Associate III
Apr 12, 2013 5:58 AM UTC
Question

Writing on USB-Memory

Posted on April 12, 2013 at 07:58

Hello,

i have a little problem. I have adaptet the stm_Host_MSC example on my board.

I use the USB_HS_Core with the internal FS-phy.

I can communicate and wirte on my usb-stick.

my question mow is: What i have to do, that i can wite additional data in an existing file??

Thanks for your help.

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    Apr 12, 2013 6:02 AM UTC
    Posted on April 12, 2013 at 08:02

    You'll likely need to layer on a file system, like FatFs, and access/modify the files that way.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Stephan Scherer
    Associate III
    Apr 12, 2013 7:05 AM UTC
    Posted on April 12, 2013 at 09:05

    I have added the files for the file-system to my project, but i'm confused where I have to modify.

    Can you give me an example or something like that?
    Tesla DeLorean
    Guru
    Apr 12, 2013 1:41 PM UTC
    Posted on April 12, 2013 at 15:41

    Can I send you a bill for my time?

    The sector reading and writing routines for FatFs are abstracted in diskio.c

    FRESULT res;
    FIL fil;
    FATFS fs32;
    ..
    memset(&fs32, 0, sizeof(FATFS));
    res = f_mount(0, &fs32);
    if (res != FR_OK)
    printf(''res = %d f_mount
    '', res);
    ..
    // Incremental write test
    if (f_open(&fil, ''LOG.TXT'', FA_OPEN_ALWAYS | FA_WRITE) == FR_OK)
    {
    UINT BytesWritten;
    const char string[] = ''Another line gets added
    
    '';
    f_lseek(&fil, fil.fsize); // Seek to tail
    
    f_write(&fil, string, strlen(string), &BytesWritten); // Add new data
    
    f_close(&fil);
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Stephan Scherer
    Associate III
    Apr 15, 2013 5:13 AM UTC
    Posted on April 15, 2013 at 07:13

    THX clive.

    Fanally it works. :)
    prynk27
    Visitor II
    Aug 28, 2013 7:28 PM UTC
    Posted on August 28, 2013 at 21:28

    Hello Stephan,

    I am new in USB interfacing can you help me how i can interface USB for transferring File in .txt format from STM32F303 to USB stick by giving an example.

    Thanks in advance