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
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
Tsuneo
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