Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

FAT on Compact Flash

Altera_Forum
Honored Contributor II
1,219 Views

Hello, 

 

I just found how to implement FAT file System on my Compact Flash  

without any OS, on the 1C20 Evaluation Kit  

and I think anybody is interresed by this subject. 

 

Sorry for my english, I&#39;m french.... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

You need to download: 

* compact flash hardware & software examples for nios ii 5.0 (http://forum.niosforum.com/downloads/cflash/cf5_0.zip) from Jesse in Tested IP from this forum. 

* (the dosfs distribution archive (http://www.zws.com/products/dosfs/index.html)) 

 

You need to modify the DOSFS distribution archive: 

delete "dosemu.h" and "dosemu.c". 

in "dosfs.h" add an include to "cddiskutils.h" 

add : 

#define dfs_readsector(unit,buffer,sector,count) readlogicalsector(( unsigned long) sector, (unsigned long) count,  

(unsigned short *)buffer);# define dfs_writesector(unit,buffer,sector,count) writelogicalsector(( unsigned long) sector, (unsigned long) count,  

(unsigned short *)buffer); 

compile and look at the error : 

Replace all type define in DOSFS distribution archive by the equivalent alt_u8, alt_u16 and alt_u32, for all the type. 

 

It&#39;s ok for me, fat 12, fat 16 and fat 32 in CHS and LBA. 

 

If anybody want some details, you can contact me.... 

 

@+ 

 

Olivier http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
511 Views

Hi Olivier, I did what you suggest. The result is that FAT16 with 32Mbyte card works but 128Mbyte or 1Gbyte cards don&#39;t work at all! 

 

Did you succeed in using big CF cards? 

In particular with 128Mbyte card, I get an error in getting volume information (but device parameters are read correctly). 

With 1Gbyte card, device parameters are not read correctly at all. 

 

Do you have any idea? 

 

Thank you, 

Davide 

 

 

 

--- Quote Start ---  

originally posted by odespont@Jun 29 2006, 02:49 PM 

hello, 

 

i just found how to implement fat file system on my compact flash  

without any os, on the 1c20 evaluation kit  

and i think anybody is interresed by this subject. 

 

sorry for my english, i&#39;m french.... http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/biggrin.gif  

 

you need to download: 

* compact flash hardware & software examples for nios ii 5.0 (http://forum.niosforum.com/downloads/cflash/cf5_0.zip) from jesse in tested ip from this forum. 

* (the dosfs distribution archive (http://www.zws.com/products/dosfs/index.html)) 

 

you need to modify the dosfs distribution archive: 

delete "dosemu.h" and "dosemu.c". 

in "dosfs.h" add an include to "cddiskutils.h" 

add : 

#define dfs_readsector(unit,buffer,sector,count) readlogicalsector(( unsigned long) sector, (unsigned long) count,  

                        (unsigned short *)buffer);# define dfs_writesector(unit,buffer,sector,count) writelogicalsector(( unsigned long) sector, (unsigned long) count,  

                        (unsigned short *)buffer); 

compile and look at the error : 

replace all type define in dosfs distribution archive by the equivalent alt_u8, alt_u16 and alt_u32, for all the type. 

 

it&#39;s ok for me, fat 12, fat 16 and fat 32 in chs and lba. 

 

if anybody want some details, you can contact me.... 

 

@+ 

 

olivier http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/blink.gif  

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16526) 

--- quote end ---  

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
511 Views

 

--- Quote Start ---  

originally posted by odespont@Jun 29 2006, 07:49 AM 

hello, 

 

i just found how to implement fat file system on my compact flash  

without any os, on the 1c20 evaluation kit  

and i think anybody is interresed by this subject. 

 

sorry for my english, i&#39;m french.... http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/biggrin.gif  

 

you need to download: 

* compact flash hardware & software examples for nios ii 5.0 (http://forum.niosforum.com/downloads/cflash/cf5_0.zip) from jesse in tested ip from this forum. 

* (the dosfs distribution archive (http://www.zws.com/products/dosfs/index.html)) 

 

you need to modify the dosfs distribution archive: 

delete "dosemu.h" and "dosemu.c". 

in "dosfs.h" add an include to "cddiskutils.h" 

add : 

#define dfs_readsector(unit,buffer,sector,count) readlogicalsector(( unsigned long) sector, (unsigned long) count,  

                        (unsigned short *)buffer);# define dfs_writesector(unit,buffer,sector,count) writelogicalsector(( unsigned long) sector, (unsigned long) count,  

                        (unsigned short *)buffer); 

compile and look at the error : 

replace all type define in dosfs distribution archive by the equivalent alt_u8, alt_u16 and alt_u32, for all the type. 

 

it&#39;s ok for me, fat 12, fat 16 and fat 32 in chs and lba. 

 

if anybody want some details, you can contact me.... 

 

@+ 

 

olivier http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/blink.gif  

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16526) 

--- quote end ---  

 

--- Quote End ---  

 

Hi Olivier, 

nice job http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

I&#39;m a french guy too, so if you want to discuss about Nios II, just drop me a message (french will be appreciated of course). I&#39;m a Nios beginner, so it is always interesting for me to know what the others do with Nios. 

 

Regards.
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

 

--- Quote Start ---  

 

Hi Olivier, I did what you suggest. The result is that FAT16 with 32Mbyte card works but 128Mbyte or 1Gbyte cards don&#39;t work at all! 

 

 

Hi dmerlani, 

 

It might have something to do with FAT16 only goes to about 32Mbyte, from there FAT32 takes over. Do a Google on Jack Dobiash, he has a great page on FAT and some useful links to other sites. 

 

Banx.
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

I found that DOSFS was really slow. I am trying to get this working: 

 

http://elm-chan.org/fsw/ff/00index_e.html (http://elm-chan.org/fsw/ff/00index_e.html

 

which supports all of the FATs. I think it would be faster because of how it is written. The hooks to make it work are similar in nature. However I am having problems reading sector 0 right now to get the FAT descriptor... this problem has nothing to do with the FAT file system reading code. 

 

Let me know how it goes. 

 

Thanks, 

Chris F.
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

Hi to all, 

 

i&#39;ve no problem with Compact flash (sandisk) 16 Mo, 32 Mo,128 Mo and 256 Mo. 

But with an 2 Go there is somme problem, but i&#39;ve some problem on another application 

with this 2Go card, i think the card is bad perhaps. 

 

If Dosfs is too slow, ok if there is a better idea... 

http://elm-chan.org/fsw/ff/00index_e.html (http://elm-chan.org/fsw/ff/00index_e.html) is good...and there is a subjet on mmc/sd card. 

For me, i&#39;ve no time at this moment to continue this projet, 

actually i work to implement an pci bridge in vhdl (from opencore) in a nios project. 

 

Normally in 2007, i&#39;ve to do a new projet to implement Dos File System, with an SD/MMC card in SPI mode, i think i will see a better solution. 

 

Thank you to continue this project.... 

 

O DESPONT 

 

NB: the page on jack Dobiash is good too : http://home.teleport.com/~brainy/fat16.htm (http://home.teleport.com/~brainy/fat16.htm)
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

Hi to all, 

I discovered the effect but not the cause for the 1GB memory. When using the reading command IORD_ALTERA_AVALON_CF_IDE_DATA, only odd registers are read!!! So all the informations (sectors, cylinders, etc...) are completly wrong and nothing works. Maybe this is due to the use of CS1 and CS2 (chip select). Reading at http://www.freeweb.hu/vfx/avr/download/cf.asm (http://www.freeweb.hu/vfx/avr/download/cf.asm) I found out the CS1 should stay low and CS2 high in order to read even and odd bytes serially; but this is exactly what the NIOS2 board outputs...  

 

Please let me know if you have some ideas! 

 

Thank you, 

Davide
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

Another question. For the 128MB problem, I would like to solve it trying to use FF instead of DOSFS. 

Can you tell me which are the changes to apply to the source code in order to make it work with avalon_cf? 

 

Thank you
0 Kudos
Altera_Forum
Honored Contributor II
511 Views

I SOLVED ALL THE ISSUES!!! 

 

In particular: for the 128MB card, I just used FATFS and everything works fine 

For the 1GB card: I was using an old NIOS2 EPC2C35 board (2004). I just received the new one today (2006) and it&#39;s capable of reading the 1GB card. 

The new board has 32MB of RAM and other stuff; maybe some chips in the old board were too slow and gave the problem. Anyway now everything works!!! 

 

GREAT!
0 Kudos
Reply