Hey all, I'm using the freescale freedom development board with the KL25 MCU. I'm also using CW10.4 & "Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx" example project.
My end goal is to have a tiny formatible drive for users to place a small configuration .txt file. The example projects use 1kb(i upped to 2kb..) of ram as the USB MSD device capacity. When compiling in CW10.4/Windows 7 the device successfully enumerates as a mass storage device. However, W7 says the drive needs to be formatted and any of the default tools results in failure.
My question is, is the failure to format the disk a result of the example code being incomplete or is 2kb simply too small for a filesystem like fat12?
FYI here are some format attempts I tried via command line /DISKPART:
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D DVD-ROM 0 B No Media
Volume 1 I DVD-ROM 0 B No Media
Volume 2 H DVD-ROM 0 B No Media
Volume 3 E System Rese NTFS Partition 100 MB Healthy
Volume 4 G NTFS Partition 465 GB Healthy
Volume 5 C NTFS Partition 111 GB Healthy System
Volume 6 F NTFS Partition 465 GB Healthy
Volume 7 J RAW Removable 2048 B Healthy
DISKPART> select volume 7
Volume 7 is the selected volume.
DISKPART> clean
DiskPart has encountered an error: The parameter is incorrect.
See the System Event Log for more information.
ISKPART> create partition primary
No usable free extent could be found. It may be that there is insufficient
free space to create a partition at the specified size and offset. Specify
different size and offset values or don't specify either to create the
maximum sized partition. It may be that the disk is partitioned using the MBR di
sk
partitioning format and the disk contains either 4 primary partitions, (no
more partitions may be created), or 3 primary partitions and one extended
partition, (only logical drives may be created).
DISKPART> format fs=fat12
0 percent completed
Virtual Disk Service error:
The file system is incompatible.
I'm seeing exactly the same issue as Nathan.
@Administrator Could we reclassify this thread as "UNANSWERED" - not sure that "ASSUMED ANSWERED" is the best assumption here.
1. Environmental Info:
Win7
Freescale USB stack 4.1.1
CW-for-MCU 10.5
Example C:\Freescale\Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx
2. Repeat of Nathan's Linux experiment:
[user@math2 nick]# dmesg
[328041] usb 4-2: New USB device found, idVendor=15a2, idProduct=0200
[328050] usb 4-2: Product: USB MSD DEVICE PEx DEMO
[328053] usb 4-2: Manufacturer: FREESCALE SEMICONDUCTOR INC.
[331099] usb-storage 4-2:1.0: USB Mass Storage device detected
[338060] scsi 10:0:0:0: Direct-Access FSL FREESCALE MSD 0001 PQ: 0 ANSI: 4
[338438] sd 10:0:0:0: Attached scsi generic sg4 type 0
[343051] sd 10:0:0:0: [sdd] 2 512-byte logical blocks: (1.02 kB/1.00 KiB)
[346046] sd 10:0:0:0: [sdd] Write Protect is off
[346051] sd 10:0:0:0: [sdd] Mode Sense: 00 00 00 00
[349045] sd 10:0:0:0: [sdd] Asking for cache data failed
[349049] sd 10:0:0:0: [sdd] Assuming drive cache: write through
[367044] sd 10:0:0:0: [sdd] Asking for cache data failed
[367048] sd 10:0:0:0: [sdd] Assuming drive cache: write through
[372063] Dev sdd: unable to read RDB block 2
[372073] sdd: unable to read partition table
[372084] sdd: partition table beyond EOD, enabling native capacity
[407076] sd 10:0:0:0: [sdd] Attached SCSI removable disk
# First, hexdump to show device sdd is empty
[user@math2 nick]# hexdump -C /dev/sdd
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000400
# Second, write two 512-byte blocks of random bytes to device sdd
[user@math2 nick]# dd if=/dev/urandom of=/dev/sdd bs=512 count=2
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0881834 s, 11.6 kB/s
# Third, hexdump again to check contents after write
[user@math2 nick]# hexdump -C /dev/sdd
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000400
# FAIL - /dev/sdd is still all zeros
So, looking forward to inputs from anyone who has successfully used "C:\Freescale\Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx" on the FRDM-KL25Z board.
Note: Also tried this with similar results: C:\Freescale\Freescale USB Stack v4.1.1\Source\Device\app\msd\cw10\kinetis_l2k\
Hi ,in this days i have work for find a solution with the freescale stack library. A fist solution, that i find, is to increase the buffer length in the file usb_msc.h changing:
#define MSC_RECV_DATA_BUFF_SIZE (512)
#define MSC_SEND_DATA_BUFF_SIZE (512)
in :
#define MSC_RECV_DATA_BUFF_SIZE (8192)
#define MSC_SEND_DATA_BUFF_SIZE (512)
now i can copy files in the sdcard with dimension up to 8192byte but they aren't sync on the sdcard, the problem with the MSD seem to be that the recieve buffer will not be emptied, writing the data, when it's reaches the maximal content of data. The file send to the device is not splitted in more small packages with the dimension of the buffer
Daniele,
Your're onto something...
Hi all, Did any one got solution for the above problem of MSD Device Disk Format Issue. Now I am facing the same issue when i tried to use the "C:\Freescale\Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx" on the FRDM-KL25Z board.
Regards,
charan
See here USB_ MSD_CLASS
Hi Daniele,
Thanks for your replay. The link which you asked me to refer was useful bit i was not able to resolve my problem. You posted some changes regarding BUFF_SIZE which need to be changed. i changed those values but i am getting error as m_data overflowed by 2740 bytes and i did the other change also but i am not able resolve my problem. Actually i am implementing USB_MSD_DEVICE to store data in RAM. when I tried to open Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx project i able to debug it and when connected to host PC it is asking to format the disk so when i tried to do that i am getting error as windows unable to format the disk.
Regards,
Charan
Hi All
As far as I have understood the demo that is being discussed is not actually usable to do much more than show the enumeration - although some changes have allowed more operation in SRAM.
Note that PCs will format with FAT12 and this has a certain amount of overhead for the FAT12 sector (usually 2 will be used for redundancy), boot sector, some spare sectors and it even wastes 16k for the fixed root cluster (this is due to the rather stupid FAT12 operation in this respect). Therefore at least about 20k is needed to get things working to save a rather small file.
If anyone needs real functionality it is available at this link http://www.utasker.com/kinetis/FRDM-KL25Z.html
- there is a binary that can be loaded to the FRDM-KL25Z and allows internal Flash to be use as the storage medium for FAT.
The board will thus appear as a 74k external hard drive and, when fomatted, it then allows 56k of FAT12 cluster storage space. The OpenSDA virtual COM port has a command line shell interface (115'200 Baud) with a "Disk Interface" sub-menu that also allows working with the FAT. Formatting as FAT16 or FAT32 is also possible and there are various tools for analysing files and directories on the disk as well as viewing hidden or deleted files, undelete function, etc.
If an SD card is connected to the KL25 via SPI an SD card drive can also be used in parallel with the internal Flash drive. Another option is to use an SPI Flash connected via SPI as further drive.
Regards
Mark
Kinetis: µTasker Kinetis support
K25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi Mark,
Thank you very much for your replay. I have downloaded the binary file and it works fine. But what are the changes that i need to make to the USB_MSD_DEVICE_MKL25Z128_PEx project to work as a USB_MSD_DEVICE which uses its internal flash.
Regards,
charan
Hi Charan
I don't think that PE can generate projects to do this (at the moment) but only examples of parts of it.
The uTasker project, used for the KL25Z USB-MSD configuration and supporting internal Flash, SD cards and SPI Flash at the same time - as well as other composite devices like 3 CDCs together with the MSD on the KL25, doesn't use PE and has many more advanced features.
If you can ony use PE projects it will be necessary to wait until there is one available (making a service request may promote a development) or take the existing parts and add your own solution to it - I believe that you can then submit it back to PE so that it could be included in the furture.
Regards
Mark
Kinetis: µTasker Kinetis support
K25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi Mark,
Thanks for your replay. I am trying to do with the existing components available and if i am successful i will post it here.
Regards,
charan
Charan
If you can use the FSL USB 5.0 stack rather than PE there is a project to do this that was adapted by dshimizu
Kinetis K64F - USB FLASH Drive using Internal FLASH and USB MSD device class
It is not for the KL25, but the K64F but may be less work for you. It is specifically for IAR according to the thread but again with some effort should be portable to whatever you use.
Note that the uTasker solution works on all KL and K parts as it adapt itself to the part in question without needing porting. It also builds using KDS, CW, IAR, Keil, Crossworks, CooCox, Green Hills, Atollic, GCC or VisualStudio and so is designed for use in professional/industrial projects where develpment time is to be spend on the application rather than on the framework.
Regards
Mark
Kinetis: µTasker Kinetis support
K25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
I found a similar question about FAT12/16 formatting using a K20 series micro and MQX (check it here: https://community.freescale.com/thread/309279).
About FAT12, it has a capacity of 4096 clusters with sizes from 512b up to 4Kb, so, i believe you shouldn't have any problem formatting it.
After unpacking the 700mb worth of files in the link in that post I discovered there wasn't anything for the KL micro series i'm working on. Thanks for the attempt but i'm pretty sure starting with Freescale USB Stack v4.1.1\ProcessorExpert\Examples\Device\MSD\USB_MSD_DEVICE_MKL25Z128_PEx , will get me slightly closer since what i'm going for it is exactly what that example is supposed to do. If only it worked....
I gave up on windows and started using linux for debug. Using "lsusb" I received the following:
Bus 001 Device 018: ID 15a2:0200 Freescale Semiconductor, Inc.
So the device successfully enumerates.
Next I did "cat /dev/sda | hexdump -C" and received the following
00000000 eb 3c 90 4d 53 44 4f 53 35 2e 30 00 02 01 01 00 |.<.MSDOS5.0.....|
00000010 01 10 00 20 00 f8 02 00 01 00 01 00 00 00 00 00 |... ............|
00000020 00 00 00 00 00 00 29 74 19 02 27 4c 50 43 32 33 |......)t..'LPC23|
00000030 36 38 20 55 53 42 46 41 54 31 32 20 20 20 33 c9 |68 USBFAT12 3.|00
... aka it read worked (I put a nxp ram disk image into the example so it wouldn't enumerate as a blank image).
Next I tried a basic write operation with dd, "dd if=/dev/urandom of=/dev/sda bs=512"
This is where things fell apart. Linux appeared as if it successfully wrote the data however when I re-read my image no change would occur. If it can't complete a basic write operation I can't expect it to be able to format. I looked in the code and the correct USB op code is generated for a write operation. It receives WRITE_12_COMMAND /*opcode : 0xAA */ and attempts to execute the function "msc_write_command(controller_ID, cbw_ptr,csw_residue_ptr,csw_status_ptr);" in "usb_msc.c" .
In this function there is a segment of code
if(_usb_device_get_transfer_status(&controller_ID, | |
BULK_OUT_ENDPOINT, USB_RECV) != USB_STATUS_IDLE) | |
{ | |
(void)_usb_device_cancel_transfer(&controller_ID,BULK_OUT_ENDPOINT, | |
USB_RECV); | |
} |
This if statement returns true which I believe cancels or blocks the write attempts.
it returns hex 11 as opposed to the 0 its looking for which is defined as USB_STATUS_IDLE. Issue is, theres no way for that function to return 0 so the usb device cancel transfer is always called... Currently it receives a "bus idle error"... I've tried disabling this error but it still failed to complete the action somewhere in the USB stack...
Hi Nathan
have you resolved this issue? I have same problem implementing MSD Bootloader for K20... Problems implementing USB MSD bootloader on K20
Best,
Primoz