I'm trying to get the example from USB stack for USB Host Mass Storage Device to work on the FRDM-K64F board in Keil. I tried following the instructions and created a multi project workspace which includes:
As per instruction, first I complied the first project and then the second. Both of them compile without errors and I can download it to the eval board. I am using the CMSIS-DAP as a debugger for FRDM-K64F. Once I run the code it stops in the HardFault_Handler. The system gets the fault in the Reset Handler right after it starts and the fault flag that is set is the NOCP - "No coprocessor Usage Fault".
I also tried running another example for a Device CDC and the same error is happening. The Target options are set for the correct microcontroller and I even tried running different scatter file (from a project that works) but the same error is happening.
Is there anything that needs to be changed in code or setting?
Also has anyone got it to work? v5.0?
Also is there any other drivers/applications to use for usb? I need host for MSD and device for CDC.
Any help is appreciated.
I finally got it to work, and I was able to run the example. One of the issues was the heap size was too small. Now I want to use the example code (if possible) to develop the application that I'm working which requires usb msd host. The example looks like its working fine, but it does not write/store anything on the usb stick. How do I write/store data onto the usb stick, using the USB Stack commands etc. In the final applications it will be used to store data from the measurements.
I switched the startup files and used one from a working project and the I was able to run the example but it fails during initialization. The error that I getting is a USBERR_ALLOC, which I think means that it could not allocate the memory for the USB. I increased the stack size but it did not solve the problem. Any ideas what else should I try?
You can check that your FRDM-K64F is working correctly first. Make sure that J21 is set so that it can supply power to the host.
Attached is a binary that you can load to the board that does USB-MSD host. Just connect any memory stick and use the OpenSDA VCOM connection at 115'200 Baud to see the operation. Below is what it looks like when a memory stick is connected (or when one is inserted when the board starts). The command line interface has a DOS like menu so you can then view files, create directories, navigate, rename, etc. and there are some disk-analysis functions for people who want to learn the low level details of FAT on the memory stick. USB-MSD host also require a FAT file system, whereby here utFAT is used.
If you need a working solution it is available in the uTasker K64 OpenSource project at http://www.utasker.com/forum/index.php?topic=1721.msg7086#msg7086
If your main interest is in porting or fixing the examples you may still be able to benefit from it because it contains a complete K64 simulation, including USB host mode and memory sticks so that you can study the operation and work out how to solve your issues.
Hello, world... KINETIS
OS Heap use = 0x0441 from 0xc000
USB FS device detected
USB device information ready:
USB2.0 device with 64 byte pipe
Vendor/Product = 0xcd12/0xef18
Manufacturer = "USB "
Product = "DISK "
Serial Number = "0482DE22941182E"
Bus-powered device (max. 100mA) with 1 interface(s)
Mass Storage Class : Sub-class = 0x06 interface protocol = 0x50
2 = BULK OUT with size 64
2 = BULK IN with size 64
LUN = 1
UFI INQUIRY -> Status transport - Passed
UFI REQUEST SENSE -> Status transport - Passed
UFI FORMAT CAP. -> (2:512:511744) Status transport - Passed
UFI READ CAP. -> (512:511743) Status transport - Passed
Disk E mounted
Serial number: 00
Software version V1.4.012
Device identification: KINETIS
1 Configure LAN interface
2 Configure serial interface
3 Go to I/O menu
4 Go to administration menu
5 Go to overview/statistics menu
6 Go to USB menu
7 Go to I2C menu
8 Go to utFAT disk interface
9 FTP/TELNET client commands
a CAN commands
b Advanced commands
help Display menu specific help
quit Leave command mode
up go to main menu
info utFAT/card info
dir [path] show directory content
dird [path] show deleted directory content
dirh [path] show hidden content
infof [path] show file info
infod [path] show deleted info
cd [path] change dir. (.. for up)
file [path] new empty file
write [path] test write to file
mkdir new empty dir
rename [from] [to] rename
trunc truncate to [length] [path]
hide [path] file/dir to hide
unhide [path] file/dir to un-hide
prot [path] file/dir to write-protect
unprot [path] file/dir to un-protet
print [path] print file content
del [path] delete file or dir.
undel undelete [name]
format [-16/12] [label] format (unformatted) disk
fformat [-16/12] [label] full format (unformatted) disk
re-format [-16/12] [label] reformat disk!!!!!
re-fformat [-16/12] [label] full reformat disk!!!!!
sect [hex no.] display sector
help Display menu specific help
quit Leave command mode
---- 05.11.2012 17:13 <DIR> CCA_Design_Rec_C
---A 22.01.2017 19:29 209396 software.bin
---- 11.02.2016 02:51 <DIR> 10.2.2016
---- 16.02.2016 00:56 <DIR> 15.2.2016
---- 22.02.2016 03:04 <DIR> storage_22.2.2016
---- 20.12.2014 22:02 <DIR> USBPlay
---A 27.02.2016 14:26 54790 memo.txt
---- 08.03.2016 03:45 <DIR> 7.3.2016
---- 09.03.2016 02:36 <DIR> 8.3.2016
---- 10.03.2016 03:43 <DIR> 9.3.2016
---- 14.03.2016 04:10 <DIR> 14.03.2016
---- 15.03.2016 19:44 <DIR> 15.3.2016
---- 22.03.2016 22:00 <DIR> 22.3.2016_database
---- 24.03.2016 04:24 <DIR> 23.03.2016
2 files with 72843790 bytes
12 directories, 83726336 bytes free
Thanks Mark for you answer.
I did like you asked and checked the memory, but it is not 0xffffffff nor 0x00000000. It has different values as well as other addresses in the memory.
It sounds as though the code is not correct for the board/device. You need to debug where the hard fault is coming from and possibly port the USB stacks to your chip.
The hard fault comes from the first Reset Handler after loading the program.
EXPORT Reset_Handler [WEAK]
LDR R0, =SystemInit
LDR R0, =__main
BX R0 <-- executing this line causes hard fault
The program does not even enter main. I did select the projects for FRDM-K64F from the USB Stack examples.
This is something very basic so it may be best to start with a very simple working project so that you can compare it and identify the problem.
It sounds as though the Flash is not being programmed (do a memory view of the memory at 0x00000000 and if it is all 0xffffffff you have a programming problem).
If you experience difficulties with the stack there is also USB-MSD host and CDC class device at the following links, where you can also simulate the operation to simplify development (including emulating the memory stick) and including a Keil project to do it.
Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts