Hello,
I'm need to do a USB stick Data Logger.
I'm using MQX 4.2 and CodeWarrior 10.6 for that. The MCU used here is a MK70FN1M0. And I'm using TWR-K70 for development.
Initially, I'm trying to mount a FAT file system, open a pre-created .txt file and write a string to it every second just as a test.
I took the mfs_usb_twrk70f120m demo from MQX 4.2. In USB_task, I set a lw_event after the interface is detected the file system is mounted:
I also cleared the same event if the USB memory stick is dettached, as well.
I created a new task to wait for this event, open a pre-created .txt file, and write a string to it, and close the file, every second.
As you can see in the image bellow, the event is set, but it looks like the file cannot be opened in the USB memory stick for a reason that I don't know yet.
Where did I go wrong?
Can anybody help me on this, please?
Thanks and best regards,
Marco Coelho
Solved! Go to Solution.
Hi Marco
It is assigned in usb_file.c file, in msd_assing_driver_letter function when calling mfs_mount function. (line 146 from usb_file.c).
Could you please validate which letter is assigned to your USB drive?
Regards,
Isaac
I just found out the point where the problem is at. It looks like it has to do with the file name, but I can't undertand why:
Hi Marco Aurelio,
Are you sure your USB stick is mounted as c: ? I have tested this example, inserted an USB stick, open a pre-created file (also named as MARCO.TXT) wrote some characters and then read them back, everything worked well. In my case, USB stick was mountes as a:, please check the image below:
Here is the shell view:
Could you please validate this path?
Regards,
Isaac
----------------------------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
----------------------------------------------------------------------------------------------------------------------------------------
Hi, Isaac
Thanks for your response.
In my application, I don't use shell task. I just left it commented and called fopen, fputc and fclose functions.
Where can I see in the code which unit my USB stick was mounted at? I'm not experienced at FATfs.
Thanks and best regards,
Marco Aurelio Coelho
Hi Marco
It is assigned in usb_file.c file, in msd_assing_driver_letter function when calling mfs_mount function. (line 146 from usb_file.c).
Could you please validate which letter is assigned to your USB drive?
Regards,
Isaac
Hello, Isaac
I saw that my USB drive was assigned letter a:. I just had to add a:\\ to the file path at fopen call and now it's working fine.
I have no words to thank you for the patience with a beginner at FATfs like me. I really appreciated it!
Best regards,
Marco Coelho
Hi Marco,
You are welcome. It is a pleasure to help you on this.
Have a nice day
Regards,
Isaac