Can't open a file in a USB memory stick using MQX 4.2 MFS_USB_twrk70f120m demo as reference

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't open a file in a USB memory stick using MQX 4.2 MFS_USB_twrk70f120m demo as reference

Jump to solution
795 Views
MAPC
Senior Contributor I

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:

pastedImage_0.png

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.

pastedImage_1.png

Where did I go wrong?

Can anybody help me on this, please?

Thanks and best regards,

Marco Coelho

Labels (1)
0 Kudos
1 Solution
488 Views
isaacavila
NXP Employee
NXP Employee

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

View solution in original post

0 Kudos
6 Replies
488 Views
MAPC
Senior Contributor I

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:

pastedImage_0.png

0 Kudos
488 Views
isaacavila
NXP Employee
NXP Employee

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:

Absolute path.jpgHere is the shell view:

Write and Read to USB stick.jpg

Could you please validate this path?

Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos
488 Views
MAPC
Senior Contributor I

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

0 Kudos
489 Views
isaacavila
NXP Employee
NXP Employee

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

0 Kudos
488 Views
MAPC
Senior Contributor I

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

0 Kudos
488 Views
isaacavila
NXP Employee
NXP Employee

Hi Marco,

You are welcome. It is a pleasure to help you on this.

Have a nice day

Regards,

Isaac

0 Kudos