<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Writing_PHAT_Files</id>
		<title>Writing PHAT Files - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Writing_PHAT_Files"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Writing_PHAT_Files&amp;action=history"/>
		<updated>2026-04-18T22:58:31Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Writing_PHAT_Files&amp;diff=298&amp;oldid=prev</id>
		<title>Harald: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Writing_PHAT_Files&amp;diff=298&amp;oldid=prev"/>
				<updated>2016-10-27T16:03:02Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 16:03, 27 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Writing_PHAT_Files&amp;diff=297&amp;oldid=prev</id>
		<title>Daniel: /* Test Environments */</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Writing_PHAT_Files&amp;diff=297&amp;oldid=prev"/>
				<updated>2009-03-10T17:42:08Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Test Environments&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Test Environments ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;smalldiv&amp;quot;&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; |&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | Hardware&amp;lt;br&amp;gt;Comments&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.6.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.7.4'''&lt;br /&gt;
| style=&amp;quot;background-color:#F6F9ED&amp;quot; | '''Nut/OS&amp;lt;br&amp;gt;4.8.0'''&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;Ethernut 3.0 E&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| Compiler&amp;lt;br&amp;gt;Error&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/write-phat-enut30E-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| NO&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;EIR 1.0 C&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| Compiler&amp;lt;br&amp;gt;Error&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/write-phat-EIR1C-nutos-4.7.4.zip '''Binaries''']&lt;br /&gt;
| OK &amp;lt;br&amp;gt; [http://ethernut.de/arc/WIKI_BINARIES_ZIPPED/write-phat-EIR1C-nutos-4.8.0.zip '''Binaries''']&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:gray&amp;quot;&amp;gt;AT91SAM7X-EK&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| NT&lt;br /&gt;
| NT&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span style=&amp;quot;color:gray&amp;quot;&amp;gt;AT91SAM9260-EK&amp;lt;/span&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
| NT&lt;br /&gt;
| NT&lt;br /&gt;
|-&lt;br /&gt;
| id=&amp;quot;compilertd&amp;quot; colspan=&amp;quot;5&amp;quot; |'''Compiler:''' ARM-GCC 4.2.2 ; AVR-GCC 4.3.0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
This example demonstrates how to write a file with the PHAT file system to a MMC (SD) card.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Eir10c-mmc-config.png|thumb|right|EIR 1.0 MMC configuration]]&lt;br /&gt;
&lt;br /&gt;
When using the EIR 1.0 board, make sure, that the option of the ''MMC Software SPI 0 Driver'' are configured as shown in the screen shot.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;dev/board.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fs/phatfs.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;io.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main (void)&lt;br /&gt;
{&lt;br /&gt;
    int hvol;&lt;br /&gt;
    FILE *fp;&lt;br /&gt;
 &lt;br /&gt;
    NutRegisterDevice(&amp;amp;devPhat0, 0, 0);&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_MMCARD, 0, 0);&lt;br /&gt;
 &lt;br /&gt;
    hvol = _open(DEV_MMCARD_NAME &amp;quot;:1/PHAT0&amp;quot;, _O_RDWR | _O_BINARY);&lt;br /&gt;
    &lt;br /&gt;
    fp = fopen(&amp;quot;PHAT0:/TEST.TXT&amp;quot;, &amp;quot;w&amp;quot;);&lt;br /&gt;
    fprintf(fp, &amp;quot;HelloFile&amp;quot;);&lt;br /&gt;
    fclose(fp);&lt;br /&gt;
&lt;br /&gt;
    _close(hvol);&lt;br /&gt;
 &lt;br /&gt;
    for(;;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int hvol;&lt;br /&gt;
FILE *fp;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variable &amp;lt;code&amp;gt;hvol&amp;lt;/code&amp;gt; is used for the volume handle and variable &amp;lt;code&amp;gt;fp&amp;lt;/code&amp;gt; will contain the file pointer.&lt;br /&gt;
&lt;br /&gt;
We must register all devices that we will use. Here it's &amp;lt;code&amp;gt;DEV_MMCARD&amp;lt;/code&amp;gt; for the MultiMedia Card device and &amp;lt;code&amp;gt;devPhat0&amp;lt;/code&amp;gt; for the file system driver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
NutRegisterDevice(&amp;amp;DEV_MMCARD, 0, 0);&lt;br /&gt;
NutRegisterDevice(&amp;amp;devPhat0, 0, 0);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To mount the volume, we open the MMC device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
hvol = _open(DEV_MMCARD_NAME &amp;quot;:1/PHAT0&amp;quot;, _O_RDWR | _O_BINARY);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, that the name contains the device name, followed by a colon, followed by the number of the partition, followed by a slash, followed by the name of the file system driver.&lt;br /&gt;
&lt;br /&gt;
The name of the MMC driver may differ among target boards. &amp;lt;code&amp;gt;DEV_MMCARD_NAME&amp;lt;/code&amp;gt; is defined in &amp;lt;code&amp;gt;board.h&amp;lt;/code&amp;gt; and represents the standard name of the specific target board.&lt;br /&gt;
&lt;br /&gt;
Now we can open a file for writing, write some text into the file and close the file, using the standard C stream functions &amp;lt;code&amp;gt;fopen&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fprintf&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;fclose&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fp = fopen(&amp;quot;PHAT0:/TEST.TXT&amp;quot;, &amp;quot;w&amp;quot;);&lt;br /&gt;
fprintf(fp, &amp;quot;HelloFile&amp;quot;);&lt;br /&gt;
fclose(fp);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, the partition gets unmounted by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
_close(hvol);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Reading PHAT Files]]&lt;br /&gt;
* [[Reading PHAT Directories]]&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Fopen C file input/output] The C programming language provides many standard library functions for file input and output.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/File_Allocation_Table File Allocation Table] A computer file system architecture originally developed by Bill Gates and Marc McDonald.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>Daniel</name></author>	</entry>

	</feed>