<?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=Reading_UROM_Files</id>
		<title>Reading UROM 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=Reading_UROM_Files"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Reading_UROM_Files&amp;action=history"/>
		<updated>2026-05-10T01:23:40Z</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=Reading_UROM_Files&amp;diff=240&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=Reading_UROM_Files&amp;diff=240&amp;oldid=prev"/>
				<updated>2016-10-27T16:03:00Z</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=Reading_UROM_Files&amp;diff=239&amp;oldid=prev</id>
		<title>Newacct at 20:08, 11 February 2010</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Reading_UROM_Files&amp;diff=239&amp;oldid=prev"/>
				<updated>2010-02-11T20:08:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Description ==&lt;br /&gt;
&lt;br /&gt;
This example demonstrates how to read a file from the Micro-ROM (uROM) file system.&lt;br /&gt;
&lt;br /&gt;
For the example to work, you'll need a sub-directory called data, containing the example.txt&lt;br /&gt;
example.txt should contain some text to be displayed, for example &amp;quot;Hello world!&amp;quot; or &amp;quot;Geez, it works!&amp;quot;.&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;dev/urom.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fs/uromfs.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;
&lt;br /&gt;
/*&lt;br /&gt;
     Include our uROM file&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;quot;urom_data.c&amp;quot;&lt;br /&gt;
&lt;br /&gt;
static char buff[256];&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    FILE *fp;&lt;br /&gt;
&lt;br /&gt;
    unsigned long baud = 115200;&lt;br /&gt;
&lt;br /&gt;
    NutRegisterDevice(&amp;amp;DEV_DEBUG, 0, 0);&lt;br /&gt;
&lt;br /&gt;
    freopen(DEV_DEBUG_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
    _ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
    puts(&amp;quot;File read test\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    if (NutRegisterDevice(&amp;amp;devUrom, 0, 0)) {&lt;br /&gt;
        printf(&amp;quot;UROM error\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    fp = fopen(&amp;quot;UROM:example.txt&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while (!feof(fp)) {&lt;br /&gt;
        fgets(buff, sizeof(buff), fp);&lt;br /&gt;
        puts(buff);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    fclose(fp);&lt;br /&gt;
&lt;br /&gt;
    for (;;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You'll also need a slightly altered Makefile that creates your urom_data.c for you.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROJ = urom_ex&lt;br /&gt;
DATADIR = data&lt;br /&gt;
DATAFILE = urom_data.c&lt;br /&gt;
 &lt;br /&gt;
include ../Makedefs&lt;br /&gt;
 &lt;br /&gt;
SRCS =  $(PROJ).c&lt;br /&gt;
OBJS =  $(SRCS:.c=.o)&lt;br /&gt;
LIBS =  $(LIBDIR)/nutinit.o -lnutpro -lnutos -lnutnet -lnutfs -lnutcrt -lnutdev -lnutarch&lt;br /&gt;
TARG =  $(PROJ).hex&lt;br /&gt;
 &lt;br /&gt;
all: $(DATAFILE) $(OBJS) $(TARG) $(ITARG) $(DTARG)&lt;br /&gt;
&lt;br /&gt;
$(DATAFILE): $(DATADIR)/example.txt&lt;br /&gt;
	$(CRUROM) -r -o$(DATAFILE) $(DATADIR)&lt;br /&gt;
 &lt;br /&gt;
include ../Makerules&lt;br /&gt;
 &lt;br /&gt;
clean:&lt;br /&gt;
	-rm -f $(OBJS)&lt;br /&gt;
	-rm -f $(TARG) $(ITARG) $(DTARG)&lt;br /&gt;
	-rm -f $(DATAFILE)	&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;
char buff[256];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
defines an array of the type char of 256 bytes. A char array is also called string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
unsigned long baud = 115200;&lt;br /&gt;
&lt;br /&gt;
NutRegisterDevice(&amp;amp;DEV_DEBUG, 0, 0);&lt;br /&gt;
&lt;br /&gt;
freopen(DEV_DEBUG_NAME, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
_ioctl(_fileno(stdout), UART_SETSPEED, &amp;amp;baud);&lt;br /&gt;
&lt;br /&gt;
puts(&amp;quot;File read test\n&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First, we set up our stdout device so we can print things to the terminal and output a line with &amp;quot;File read test!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (NutRegisterDevice(&amp;amp;devUrom, 0, 0)) {&lt;br /&gt;
    printf(&amp;quot;UROM error\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we register the device driver for the uROM. Notice the difference in naming and capitalization between &amp;quot;DEV_DEBUG&amp;quot; and &amp;quot;devUrom&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fp = fopen(&amp;quot;UROM:example.txt&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can open files from the uROM like any other files. Just prefix the filename with UROM: to tell Nut/OS that we're opening a file from uROM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while (!feof(fp)) {&lt;br /&gt;
    fgets(buff, sizeof(buff), fp);&lt;br /&gt;
    puts(buff);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While we haven't reached the end of the file, we read a string into our buffer and print it to the terminal.&lt;br /&gt;
&amp;quot;fgets&amp;quot; reads a string from a file (strings end at the end of a line so we read the file one line at a time.) The &amp;quot;sizeof(buff)&amp;quot; restricts the amount of characters read to the length of our buffer. We don't want to read more than we can store.&lt;br /&gt;
&amp;quot;puts&amp;quot; then outputs the buffer to the terminal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fclose(fp);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Don't forget to close the file after you're done with it.&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
 File read test&amp;lt;br&amp;gt;&lt;br /&gt;
 Hello world!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Writing PHAT Files]]&lt;br /&gt;
* [[Reading PHAT Directories]]&lt;br /&gt;
* [[MMC MP3 Player]]&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>Newacct</name></author>	</entry>

	</feed>