AnsweredAssumed Answered

Writing to USB Thumb Drive

Question asked by wesley cheng on Feb 21, 2010
Latest reply on Apr 14, 2010 by Cutworth Wang

Hi Everyone,

    I'm pretty new to MQX, so I'm having difficulty getting the MCU to write to a USB.  I took the USB intialization files from the web_hvac demo, and it seems to be intializing the USB drive when I plug it in.  When I call my write function, however, nothing gets written to the flash drive, and whenever I plug the drive into my machine to check if the data was written onto the file, it has me reformat the drive, which causes me to erase all the file on the USB.  Is this normal?



//TEST WRITING CODEvoid usb_file_write(){    FILE_PTR usb_fs_file;    char data[6] = "testme";    FILE_PTR usb_file;    usb_fs_file = fopen("USB:",NULL);    if(usb_fs_file==NULL){        printf("Error opening the MFS Device Driver.");        _mqx_exit(1);    }    usb_file=fopen("USB:\\data.text","a+");    if(usb_file==NULL){        printf("Error opening the file.");        _mqx_exit(1);    }    write(usb_file,data,strlen(data));    fclose(usb_file);}


Any help is appreciated, thanks!