Developing a USB memory stick Data Logger with Processor Expert and USB baremetal stack v. 4.1

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

Developing a USB memory stick Data Logger with Processor Expert and USB baremetal stack v. 4.1

1,308 Views
MAPC
Senior Contributor I

Hello,

I need a Data Logger in a USB memory stick in my application using MK70. As my project was initialized with Processor Expert in CodeWarrior  and I didn't find a reference example with Processor Expert in Freescale USB Baremetal Stack, I tried to copy the files from K70 MSD-FAT example located at "C:\Freescale\Freescale USB Stack v4.1.1\Source \Host\ examples\ msd_mfs_generic\ cw10\ kinetis_k70", except for vectors.c and K70 registers initialization files, since Processor Expert already initializes interrupt vectors and includes "IO_Map.h" file, which defines the addresing and macros of all the registers in the MCU.

After a lot of work, copying all the files and include their respective paths into Compiler Settings, I got some build errors. In the beggining, those errors were due to the lack of some header files. But now, I got some errors that I don't understand the cause:

pastedImage_1.png

Maybe somebody can give me an idea of how to do it in a easier way with less work and avoiding these conflicts and errors. Or if I don't find another way, I will have to create a new project based on that demo (without PE) (following the instructions from USBHOSTUG.pdf) and copy what it is already initialized and done with Processor Expert.

Thanks,

Marco Coelho

Labels (1)
0 Kudos
9 Replies

831 Views
BlackNight
NXP Employee
NXP Employee

Hi Marco,

I have transformed the USB 4.1 stack into Processor Expert components (CDC, HID and MSD) and use it sucessfully in several projects.

Typically my MSD projects use FreeRTOS (so are not bare metal), but the components can be used in bare metal mode.

I don't have an example project for K70, but I do  have one for K60. As you are familiar with Processor Expert, it should be fairly easy for you to get it running on the K70. The critical part is to get proper 48 MHz for the USB block.

The CodeWarrior k60 project is on GitHub here:

mcuoneclipse/Examples/TRW-K60N512/TWR-MK60_USB_MSD_Host at master · ErichStyger/mcuoneclipse · GitHu...

Let me know what you think. Maybe I have a TWR-K70 board somewhere, but would need to find some time first.

But I have created articles here which should be able to help you:

and about USB (CDC in this case) in general for Kinetis:

As for K70, I have CodeWarrior USB Projects with Processor Expert here: mcuoneclipse/Examples/TWR-K70F120M at master · ErichStyger/mcuoneclipse · GitHub

Have a read here: USB with the TWR-K60F120M and TWR-K70F120M | MCU on Eclipse

As for these Processor Expert USB components used: they are available on SourceForge:

McuOnEclipse Releases on SourceForge | MCU on Eclipse

And finally one word about using memory sticks with the USB 4.x stack: I have found out that not every stick works, and some are working half-half. At least in my experience smaller (less than 4 GB) devices worked better).

I hope this helps,

Erich

0 Kudos

831 Views
MAPC
Senior Contributor I

Hello, Erich

Thank you for the demos. They are very helpful. I just downloaded your examples and, among them, there are some for TWR-K60N512. One of them is named "TWR-K60N512_FatFS_BM" and it is a baremetal demo that I'm looking for. Probably I can use it as a reference and export the PE settings related to USB and FATFS to my K70 project. Coincidently, I still have this kit here and I can make a test.

But, this demo considers a SD card. How can I change it to work with a USB memory stick?

Regarding the issue with sticks with more than 4GB, that is so strange! As far as I know, this stack supports FAT 32, which should be able to handle any stick with up to 32GB...

Thanks and best regards,

Marco Coelho

0 Kudos

831 Views
MAPC
Senior Contributor I

Hello, Erich

I just tested the "benchmark" application in your FRDM-K20_MSD_Host, but it didn't work. I used in your demo the same USB memory stick with 4GB that I used in Freescale's msd_mfs_generic demo and it worked fine there.

Have a look at the screenshot of the test in Tera Term:

pastedImage_0.png

Do you have any idea on what could be causing this issue?

Thanks and best regards,

Marco Coelho

0 Kudos

831 Views
BlackNight
NXP Employee
NXP Employee

It looks to me that the device/volume has not been mounted?

Erich

0 Kudos

831 Views
BlackNight
NXP Employee
NXP Employee

Inserting a memory stick should auto-mount the device (see message below).

if not, then the device somehow is not recognized.

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

FRDM-K20D50M

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

CLS1                      ; Group of CLS1 commands

  help|status             ; Print help or status information

FRTOS1                    ; Group of FRTOS1 commands

  help|status             ; Print help or status information

FAT1                      ; Group of FAT1 commands

  help|status             ; Print help or status information

  cd [<directoryName>]    ; Change the current directory or display the name of the current directory

  dir [<directoryName>]   ; Prints a directory

  copy <src> <dst>        ; Copy a file

  delete <filename>       ; Delete a file

  mkdir <directory>       ; Create a directory

  rename <src> <dst>      ; Rename a file

  print <filename>        ; Print a file

  sector <number>         ; Print disk sector

  diskinfo                ; Print disk information

  benchmark               ; Run disk benchmark

run benchmark             ; Run FatFS benchmark

CMD> Mass Storage Device Attached

File System mounted

FAT1 dir

Directory of /

----A 2014-08-21 08:56  524907424 KDS-V1~1.EXE

D-HS- 2014-09-18 13:48          0 SYSTEM~1

D---- 2014-09-13 18:18          0 OPENSDA

D---- 2014-10-22 12:46          0 10.6

----A 2015-06-21 17:07    3337502 FTF-DE~1.PDF

D---- 2015-06-21 17:08          0 LAB_KS~1

2 File(s), 528244926 bytes total

4 Dir(s), 130416 KBytes free

0 Kudos

831 Views
MAPC
Senior Contributor I

Hello, Erich

Running the same demo for TWR-K60N512, I got a different result:

pastedImage_0.png

The "bench.txt" file is created and a lot of "benchmarks" are printed in the file. The "copy.txt" file is also created. But, the copying hangs eternally.

I tested both demos with a 2GB USB memory stick and the same problem ocurrs.

I'm really confused about that.

0 Kudos

830 Views
BlackNight
NXP Employee
NXP Employee

I have seen something like this sometimes too, that the USB stack waits for an answer (but does not receive one somehow).

I don't know yet what is causing this.

Good news is that it is working to some extend. But not reliable (yet).

Maybe it is something about timing, but not sure yet.

0 Kudos

830 Views
MAPC
Senior Contributor I

Hello, Erich

I can't believed! That's really embarrassing! I forgot to mount and shorten J21 jumper on FRDM-K20D50M kit. That connects 5V power to the USB connector.

Well, we can consider it is working now. I only thought strange that some strange messages were printed on the screen. But, "BENCH.txt" and "COPY.txt" files were created and the string "BENCHMARK" was written several times in "BENCH.txt" and this same content copied to "COPY.txt". As you can see bellow, the other messages weren't printed on the Terminal, but it works! More tests will be necessary to prove it really is 100% functional for our application and hardware here.

As a second test, I changed the string "BENCHMARK" to "BANANA" and ran again. It worked fine, other files with the same names were created in the USB memory stick and over-rode the old ones with the new content, as expected. See the screenshots bellow:

What we need now is turning this into a baremetal demo to add it to our project in which other peripherals were also intialized and handled by Processor Expert. I think a good way to do it is refering to your "TWR-K60N512_FatFS_BM" demo present at "...\ mcuoneclipse-master\Examples\TRW-K60N512".

pastedImage_0.png

pastedImage_1.png

pastedImage_3.png

pastedImage_2.png

Thank you very much, Erich!

Best regards,

Marco Coelho

0 Kudos

830 Views
BlackNight
NXP Employee
NXP Employee

Hi Marco,

The difference between the normal FatFS and the MSD ones are that the first uses SD card, the USB MSD ones the USB stack. I have not had any problems with SD cards > 4 GB (my largest one is 32 GB). I think it is not a problem of the FatFS, but of the USB stack. I can tell that the USB stack worked fine for smaller/older sticks, but had problems somehow with larger/newer sticks. The FSL 4.x stack is not maintained any more by Freescale, and there is a newer stack in the Kinetis SDK. But that stack is completely different, and won't support CodeWarrior.

Erich

0 Kudos