We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
USBHostLite includes just FAT16 file system library. Replace it to another one, such as FatFs (FAT12, FAT16 and FAT32) elm-chan.org/.../00index_e.html
Here is an example of FatFs over USBHostLite (LPC17xx).
Interfacing ARM controllers with Memory-Cards www.siwawi.arubi.uni-kl.de/.../index.html Find "ChaN's FAT-Module with LPC17xx SPI/SSP and USB-MSD" paragraph near the bottom.
The host stack interface of LPC17xx USBHostLite (usbhost_lpc17xx.h) is common with LPC2468 (usbhost_lpc2468.h) except for Host_Isr(). Just minor change of above example will run it on LPC2468.
Tsuneo
Hi Tsuneo! I am doing the same project of making LPC2468 a USB Host. I downloaded the Library from the link elm-chan.org/.../00index_e.html which you gave in your reply. But what changes I have to make to Hostlite so that it works with Fatfs module..? Where should I attach the FatFs library in the HostLite?
> Where should I attach the FatFs library in the HostLite?
Did you download the FatFs / USBHostLite (LPC17xx) example on above Martin THOMAS's web page? www.siwawi.arubi.uni-kl.de/.../lpc17xx_chanfat_mthomas_20100715c_pub.zip
He've already done it for you :-)
FatFs accesses to physical media using these routines in diskio.c disk_initialize(), disk_status(), disk_read(), disk_write(), disk_ioctl()
Fill the contents of these routines using, MS_Init(), usb_status, MS_BulkRecv(), MS_BulkSend(), blkSize/numBlks of usbhost_ms.c, respectively.
THOMAS's implementation is, lpc17xx_chanfat_mthomas 2\project\Libraries\fat_sd\diskio.c Look in "case USB:" of each routine.
Thank you very much for your kind gesture..Tsuneo...
Sir, I have added the fatfs module to the Hostlite for LPC24xx to convert the code to fat32. I have replaced disk_initialize(), disk_status(), disk_read(), disk_write(), disk_ioctl() with MS_Init(), usb_status, MS_BulkRecv(), MS_BulkSend(), blkSize/numBlks of usbhost_ms.c, respectively But while simulating I get the following errors :
.\Obj\UsbHostLite.axf: Error: L6218E: Undefined symbol numBlks (referred from ff.o). .\Obj\UsbHostLite.axf: Error: L6218E: Undefined symbol usb_status (referred from ff.o).
Kindly help us find solution to these errors.
> I have replaced disk_initialize(), disk_status(), disk_read(), disk_write(), disk_ioctl() with MS_Init(), usb_status, MS_BulkRecv(), MS_BulkSend(), blkSize/numBlks of usbhost_ms.c, respectively
Sound like you've directly replaced above routines in ff.c. I meant, you have to provide your custom diskio.c, without touching to ff.c
Your diskio.c should be a simplified version of THOMAS's diskio.c, just for USB support.
Hi Tsuneo! I tried a lot to make changes to Hostlite.. But didn't get success.. So I request you to tell me the precise steps which I should follow in order to modify the USB Hostlite for LPC2468 to support FAT32 File System... Regards, Rahul.
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
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