i am currently using lpc2468 usbhostlite code and getting the required results. can anyone please help me make the necessary changes in the code to use it with fat32 formatted pendrives also
I'm surprised you don't get it yet :-) Maybe, my explanation was not so clear for you..
> I tried a lot to make changes to Hostlite..
You don't need to change so much.
1) Download THOMAS's FatFs/USBHostLite (LPC17xx) example, first. www.siwawi.arubi.uni-kl.de/.../lpc17xx_chanfat_mthomas_20100715c_pub.zip
2) Copy diskio.c, fattime.c (under \lpc17xx_chanfat_mthomas 2\project\Libraries\fat_sd\) from THOMAS's to your project.
3) Modify this diskio.c I'll show you the first part of modification. Like this disk_initialize(), modify disk_status(), disk_read(), disk_write() and disk_ioctl(), too That is, strip down the routines, so that the code in "case USB:" is left.
/*-----------------------------------------------------------------------*/ /* Low level disk I/O module skeleton for FatFs */ /* (C)ChaN, 2007 */ /* Copyright (c) 2010, Martin Thomas */ /*-----------------------------------------------------------------------*/ /* This is a stub disk I/O module that acts as front end of the existing */ /* disk I/O modules and attach it to FatFs module with common interface. */ /*-----------------------------------------------------------------------*/ #include "diskio.h" // #include "spi_sd_lpc17xx.h" // <---- delete this line // in makefile #define WITH_USB_MS 1 // #if ( WITH_USB_MS == 1 ) // <---- delete this line #include "usbhost_lpc2468.h" // <---- add this line #include "usbhost_ms.h" USB_INT32U numBlks, blkSize; USB_INT08U inquiryResult[INQUIRY_LENGTH]; DSTATUS usb_status = STA_NOINIT; // #endif // <---- delete this line /*-----------------------------------------------------------------------*/ /* Correspondence between physical drive number and physical drive. */ /*-----------------------------------------------------------------------*/ /* // <---- delete these lines #define MMC 0 #define USB 1 #define ATA 2 */ /*-----------------------------------------------------------------------*/ /* disk-timer - forwarded to low-level drivers */ /*-----------------------------------------------------------------------*/ /* // <---- delete these lines void disk_timerproc(void) { MMC_disk_timerproc(); } */ /*-----------------------------------------------------------------------*/ /* Initialize a Drive */ /*-----------------------------------------------------------------------*/ DSTATUS disk_initialize(BYTE drv /* Physical drive nmuber (0..) */ ) { /* // <---- delete these lines DSTATUS stat; int result; (void) result; switch (drv) { case ATA: // result = ATA_disk_initialize(); stat = STA_NOINIT; // translate the result code here return stat; case MMC: stat = MMC_disk_initialize(); return stat; case USB: #if WITH_USB_MS */ if ( drv != 0) return STA_NOINIT; // <---- add this line /* USB host init and enumeration */ if ( usb_status & STA_NOINIT ) { Host_Init(); if ( Host_EnumDev() == OK ) { /* mass-storage init */ if ( MS_Init(&blkSize, &numBlks, inquiryResult) == OK ) { usb_status &= ~STA_NOINIT; return usb_status; // <---- add this line } else { /* MS init fail */ } } else { /* host init and/or enum fail */ } } /* // <---- delete these lines return usb_status; #else stat = STA_NOINIT; return stat; #endif } */ return STA_NOINIT; }
4) Copy diskio.h, ff.c, ff.h, ffconf.h, integer.h from ChaN's FatFs to your project elm-chan.org/.../ff9.zip
5) In your source code, - include integer.h, ff.h - replace USBHostLite's FAT/Filesystem routines (FILE_Open(), etc) into FatFs's Application Interface (f_open(), etc) elm-chan.org/.../00index_e.html
That's all
Tsuneo
Sir,
I read your reply to rahul regarding fat32 implementation using hostlite code for lpc2468. I have made the required alterations in diskio.c and have stripped it down quite a bit.I have also added the required header files as mentioned by you in my project.But I have a bit of doubt in the last step... i.e.
-
replace USBHostLite's FAT/Filesystem routines (FILE_Open(), etc) into FatFs's Application Interface (f_open(), etc)
The main.c function in the hostlite has got a Fat_Init() function that initializes the FAT16 system. Should i keep both the usbhost_fat.c and ff.c files in my project. Because my main function after enumerating the device calls the Fat_Init() routine which is not to be found in ff.c
It would be of great help to me if you could kindly elaborate on how to merge the ff.c file to the Hostlite code...
Fat_Init() is replaced with f_mount() After replacing routines from usbhost_fat.c, you should remove usbhost_fat.c from compile/link chain (ie. workspace).
usbhost_fat.c is completely replaced with ff.c and diskio.c, as follows
Application code Application code | | | usbhost_fat.h | ff.h FAT File system usbhost_fat.c ff.c | | diskio.h | diskio.c (glue routines) | | | usbhost_ms.h | usbhost_ms.h USB MassStorage usbhost_ms.c usbhost_ms.c | | | usbhost_lpc2468.h | usbhost_lpc2468.h USB host stack usbhost_lpc2468.c usbhost_lpc2468.c | | USB host hardware USB host hardware
Dear Tsuneo Chinzei
I have already done the FAT32 implementation of NXP USBhostlite source code .
but i am facing Problem
1 i am able to create a TXT file but not able to write in it that is when i try to write on this file using LPC2468 host it makes a file of 0 KB when i check it on to PC .
2 when i create a TXT file using PC on to Pen drive and try to copy this file data to newly create file by LPC2468 USB host it copies data to file.
I have found Same problem in USBhostlite example for FAT16
What,s the reason behind it.
2nd Question is that
F_mount and FAT_init are slightly different function in FAT_init we read the boot sector to determine all the necessary information about disk.
In f_mount function there is nothing like that. What ,s the role of disk_initailise function. I am confused .PLease elaborate it.
> 1 i am able to create a TXT file but not able to write in it that is when i try to write on this file using LPC2468 host it makes a file of 0 KB when i check it on to PC .
Did you close the file (FatFs: f_close() / HostLite: FILE_Close()), before plugging off the pen drive? f_open() / FILE_Open creat a file entry of size zero on the directory of the pen drive, if the file is a new one. f_close() / FILE_Close() refresh the file size on the directory. > F_mount and FAT_init are slightly different function... What ,s the role of disk_initailise function.
Surely, f_mount() initializes just the file system object (persistent context for each drive). disk_initialize() is called from most of FatFs routines, indirectly. For example, f_open() -> chk_mounted -> disk_initialize()
I believe it's the author's policy, to confirm if the target media is still mounted or not, at every chance.
Thanks Sir for your kind support
YES i close that file my code is like that
void Main_Write (void) { SWORD32 fdw; SWORD32 fdr; UWORD32 tot_bytes_written; UWORD32 bytes_written; UserBuffer = &tmp_buf[0]; fdw = FILE_Open(FILENAME_W, RDWR); if (fdw > 0) { tot_bytes_written = 0; do { bytes_written = FILE_Write(fdw, UserBuffer, 1024); tot_bytes_written += bytes_written; } while (tot_bytes_written < 1024); FILE_Close(fdw); } }
Does the file name includes small letter? If a file name with small letter is given, the file is not read out, and its size is shown as zero, though the file name appears on Windows. File name and extension should be all in capital.
yes,File name is in capital letter .but sir i solved that problem using following change in main_write function
void Main_Write (void) { SWORD32 fdw; SWORD32 fdr; UWORD32 tot_bytes_written; UWORD32 bytes_written; UWORD8 tmp_buf[64]="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNO"; UserBuffer = &tmp_buf[0]; fdw = FILE_Open(FILENAME_W, RDWR); if (fdw > 0) { tot_bytes_written = 0; do { // bytes_written = FILE_Write(fdw, UserBuffer, 1024);//earlier bytes_written = FILE_Write(fdw, UserBuffer , 64);//now tot_bytes_written += bytes_written; } while (tot_bytes_written < 1024); FILE_Close(fdw); } }
Now i am able to create the file.but a new problem is that when i create file of size upto 0 - 5kb everything is ok.but when I create file of size greater than 8 KB and try to open it on PC.It gives an error
could n,t open L:\MSWRITE.TXT Make sure a drive in the disk is specified or not
What,s the reason behind it?
Thanks Rohit
Is the buffer passed to FILE_Write() / FILE_Read() placed on the USB RAM (HOST_BASE_ADDR)?
This buffer is directly put into the Transfer Descriptor for DMA by the host controller. It means the buffer should be placed on the USB RAM. LPC23xx/24xx families have this restriction on DMA by USB controller.
In the USB host lite example, it manages buffer assignment as follows.
usbhost_lpc2468.c volatile HCED *EDCtrl; /* Control endpoint descriptor structure */ volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */ volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */ volatile HCTD *TDHead; /* Head transfer descriptor structure */ volatile HCTD *TDTail; /* Tail transfer descriptor structure */ volatile HCCA *Hcca; /* Host Controller Communications Area structure */ USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */ volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */ volatile USB_INT08U *FATBuffer; /* Buffer used by FAT file system */ volatile USB_INT08U *UserBuffer; /* Buffer used by application */ void Host_Init (void) { ... Hcca = (volatile HCCA *)(HOST_BASE_ADDR+0x000); TDHead = (volatile HCTD *)(HOST_BASE_ADDR+0x100); TDTail = (volatile HCTD *)(HOST_BASE_ADDR+0x110); EDCtrl = (volatile HCED *)(HOST_BASE_ADDR+0x120); EDBulkIn = (volatile HCED *)(HOST_BASE_ADDR+0x130); EDBulkOut = (volatile HCED *)(HOST_BASE_ADDR+0x140); TDBuffer = (volatile USB_INT08U *)(HOST_BASE_ADDR+0x150); FATBuffer = (volatile USB_INT08U *)(HOST_BASE_ADDR+0x1D0); UserBuffer = (volatile USB_INT08U *)(HOST_BASE_ADDR+0x1000);
If the buffer would be placed on the USB RAM, you don't need abuve repeated FILE_Write(). Single FILE_Write() call with whole buffer will do.
Thanks Sir
No, Sir buffer was not placed on USB RAM.
Thank You so much Sir you solved my problem
you are genuinely a master.
Hello Tsuneo,
Could you tell me why the file name must be capital letters? How can we make it support small letters? Thanks a lot.
Ran