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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,033 次查看
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

标签 (1)
0 项奖励
回复
1 解答
1,726 次查看
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 项奖励
回复
6 回复数
1,726 次查看
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 项奖励
回复
1,726 次查看
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 项奖励
回复
1,726 次查看
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 项奖励
回复
1,727 次查看
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 项奖励
回复
1,726 次查看
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 项奖励
回复
1,726 次查看
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 项奖励
回复