1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/doc/pt/fatfs.html
2010-01-25 23:43:05 +00:00

21 lines
2.5 KiB
HTML

$$HEADER$$
<h3>The FAT file system</h3>
<p>The FAT file system implementation in <b>eLua</b> uses Elm Chan's excellent FatFS package, available <a href="http://elm-chan.org/fsw/ff/00index_e.html">here</a>. It can handle FAT12, FAT16
and FAT32 file systems in read/write mode, and it packs a lot of functionality in a low footprint. Like the ROM filesystem it is integrated with the C library, so similar POSIX file manipulation will work in addition to accessing the filesystem via the Lua <b>io</b> module. <b>eLua</b> adds a platform abstraction layer on top of FatFS which makes it very easy to
port the FAT file system implementation between different <b>eLua</b> targets. Since most SD/MMC cards can be accessed using the very common SPI interface, and since <b>eLua</b> already provides
a <a href="arch_platform_spi.html">SPI platform interface</a>, porting the FAT file system to an <b>eLua</b> board is a fairly simple process.</p>
<p>To use the FAT file system on your <b>elua</b> board (that has the proper hardware to access SD/MMC cards), first make sure that there is a working implementation of the
<a href="arch_platform_spi.html">eLua SPI platform interface</a> on your platform (as currently <b>eLua</b> can access SD/MMC cards only via SPI). Then you need to enable the FAT file system module (MMCFS)
in your <b>eLua</b> binary image, as described on the <a href="building.html">building page</a>.</p>
<h2>Using the FAT file system</h2>
<p>To use the FAT filesystem with an SD or MMC card, first ensure that the card has been properly formatted as a FAT filesystem (many come preformatted with this file system).</p>
<p>Next, connect the card to your board such that the SD card's DAT3/CS PIN is connected to the CS pin you selected in the building section. In addition, for the selected SPI port, the controller's SPI DO pin should be connected the the card's CMD/DI pin, the SPI DI pin should be connected to the card's DAT0/DO pin, and the SPI SCLK should connect to the cards CLK pin. For more more information, see Elm Chan's page on <a href="http://elm-chan.org/docs/mmc/mmc_e.html">SD/MMC with SPI</a>.</p>
<p>Once configured, connected, and <b>eLua</b> has started up, you are ready to work with the files on your card. To open a file on the SD/MMC card, all you need to do is to prefix its name with <i>/mmc/</i>, like this:</p>
<p><pre><code># lua /mmc/info.lua </code></pre></p>
<p>Similarly, if you wanted to access a text file <b>a.txt</b> from your card, you could use fopen like this:</p>
<p><pre><code>f = fopen( "/mmc/a.txt", "rb" )</code></pre></p>
$$FOOTER$$