EmbeddedRelated.com
Forums

LPC2468. Writing to a file with fopen

Started by sns22 April 10, 2015
Hi all,

I am working with LPC2468 board from embeddedartists using the IAR
Embedded Workbench 7.3 

I want to write my results read from a double variable into a txt file
created on the PC. I read on the forums and already set the library
settings to FULL to read the Dlib_Config files. 
[code]
     #include <nxp/iolpc2468.h>
     #include <stdio.h>
      #include <string.h>
      
      FILE* file;
      file = fopen("H:\test.txt","rw+");
      fprintf(file,"%An",max_temperature_DegC);      
      fclose(file);
[/code]

I used this standard code. Although I have no compiler warning/errors.
But when I debug; the code it gets stuck in the undefined handler (abort
handler) as I can see it in the disassembly. The output file is not
created and has no output. I am not using UART or any I2C to write to
the file.
Is it possible to write to a file on a PC directly or one has to use
UART/I2C 

Thanks


---------------------------------------
Posted through http://www.EmbeddedRelated.com
Op Fri, 10 Apr 2015 13:54:41 +0200 schreef sns22 <93914@embeddedrelated>:
> I am working with LPC2468 board from embeddedartists using the IAR > Embedded Workbench 7.3 > > I want to write my results read from a double variable into a txt file > created on the PC. I read on the forums and already set the library > settings to FULL to read the Dlib_Config files. > [code] > #include <nxp/iolpc2468.h> > #include <stdio.h> > #include <string.h> > FILE* file; > file = fopen("H:\test.txt","rw+");
Note that "\t" is a tab character.
> fprintf(file,"%An",max_temperature_DegC); > fclose(file); > [/code] > > I used this standard code. Although I have no compiler warning/errors. > But when I debug; the code it gets stuck in the undefined handler (abort > handler) as I can see it in the disassembly. The output file is not > created and has no output. I am not using UART or any I2C to write to > the file. > Is it possible to write to a file on a PC directly or one has to use > UART/I2C
Easy solution: use semihosting. Probably impractically hard solution: use C-SPY macros. Definitely insanely hard solution: write a plug-in. -- (Remove the obvious prefix to reply privately.) Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/
sns22 wrote:

> Hi all, > > I am working with LPC2468 board from embeddedartists using the IAR > Embedded Workbench 7.3 > > I want to write my results read from a double variable into a txt file > created on the PC. I read on the forums and already set the library > settings to FULL to read the Dlib_Config files. > [code] > #include <nxp/iolpc2468.h> > #include <stdio.h> > #include <string.h> > > FILE* file; > file = fopen("H:\test.txt","rw+"); > fprintf(file,"%An",max_temperature_DegC); > fclose(file); > [/code] > > I used this standard code. Although I have no compiler warning/errors. > But when I debug; the code it gets stuck in the undefined handler (abort > handler) as I can see it in the disassembly. The output file is not > created and has no output. I am not using UART or any I2C to write to > the file. > Is it possible to write to a file on a PC directly or one has to use > UART/I2C > > Thanks > > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
Imaging if you cold create a simple device connect it to any PC and being able to write or delete data on any PC without the PC having any control. This is what you are trying to do. How do you think your LPC board can physically access data on your PC? You have to create some kind of "agent" on your PC that receives data and commands from your board via some kind of communication channel (i.e. UART) and does the real writing to files on the PC. -- Reinhardt
Hi Sns,

What kind of connection do you have to the board? As it was already mentioned, you have to have some kind of interface between the board and the pc. Of course the dev board is probably used with some kind of debugging interface (JTAG probably, even if the physical connection on the board is USB), but of course the embedded system is designed with with standalone operation in mind as well. So if you want to keep the JTAG connection, you could use semihosting for this purpose. It works in a way that a minimal support for system functions is kept on the embedded system. Calls to this "system support" layer result in an exception, which is caught by debugger (still remember that it's connected with JTAG). Debugger figures out what the system was trying to do and processes it on PC. This way you can open a file from PC and write to it - the write is processed by the PC. 
This obviously will only work with PC connected. 

If you would like to write to a PC file without the JTAG, you need some kind of agent on the PC. For example embedded board sends data over UART and on pc there is an application that listens on UART and writes received data to a file. This seems like a simpler solution (I don't have experience with semihosting so maybe I'm overestimating the effort needed).

Btw. UART may be easier to use for PC communication. PCs don't have usually hw needed for I2C/SPI communication. USB also is a possibility, but it requires more work on embedded side.

See: http://www.lpcware.com/content/faq/lpcxpresso/semihosting

On Friday, April 10, 2015 at 2:22:57 PM UTC+2, Boudewijn Dijkstra wrote:
> Op Fri, 10 Apr 2015 13:54:41 +0200 schreef sns22 <93914@embeddedrelated>: > > I am working with LPC2468 board from embeddedartists using the IAR > > Embedded Workbench 7.3 > > > > I want to write my results read from a double variable into a txt file > > created on the PC. I read on the forums and already set the library > > settings to FULL to read the Dlib_Config files. > > [code] > > #include <nxp/iolpc2468.h> > > #include <stdio.h> > > #include <string.h> > > FILE* file; > > file = fopen("H:\test.txt","rw+"); > > Note that "\t" is a tab character. > > > fprintf(file,"%An",max_temperature_DegC); > > fclose(file); > > [/code] > > > > I used this standard code. Although I have no compiler warning/errors. > > But when I debug; the code it gets stuck in the undefined handler (abort > > handler) as I can see it in the disassembly. The output file is not > > created and has no output. I am not using UART or any I2C to write to > > the file. > > Is it possible to write to a file on a PC directly or one has to use > > UART/I2C > > Easy solution: use semihosting. > Probably impractically hard solution: use C-SPY macros. > Definitely insanely hard solution: write a plug-in. > > > -- > (Remove the obvious prefix to reply privately.) > Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/
On 4/10/2015 4:54 AM, sns22 wrote:
> Hi all, > > I am working with LPC2468 board from embeddedartists using the IAR > Embedded Workbench 7.3 > > I want to write my results read from a double variable into a txt file > created on the PC. I read on the forums and already set the library > settings to FULL to read the Dlib_Config files. > [code] > #include <nxp/iolpc2468.h> > #include <stdio.h> > #include <string.h> > > FILE* file; > file = fopen("H:\test.txt","rw+"); > fprintf(file,"%An",max_temperature_DegC); > fclose(file); > [/code] > > I used this standard code. Although I have no compiler warning/errors. > But when I debug; the code it gets stuck in the undefined handler (abort > handler) as I can see it in the disassembly. The output file is not > created and has no output. I am not using UART or any I2C to write to > the file. > Is it possible to write to a file on a PC directly or one has to use > UART/I2C
Are you sure that you've specified the correct *library* (RTFM -- there are different library "flavors" depending on the sorts of support you expect from your debug host). [Sorry, I'm traveling and can't provide an explicit pointer to *which* library you should be using...] Also beware multithreading issues. E.g., I typically spawn processes with stderr mapped to the "console". This allows me to watch the progress of each process along the lines of: task1: initializing task1: awaiting producer task3: initializing task2: initializing task3: driver on-line task3: awaiting command task2: out of memory Note that each "fprintf(stderr, ...)" appears as an atomic operation; the characters from task1's fprintf(3c) are not interspersed among the characters of task2's fprintf(3c) invocations, etc. Likewise, task1 doesn't have to explicitly fopen(3c)/fclose(3c) the "console device" one-line-at-a-time (i.e., as if it was holding a lock for the duration of the fopen(3c).) In production code, all of these function invocations just turn into (expensive) no-ops.
In article <nvOdnSWIMNKcJ7rInZ2dnUU7-b2dnZ2d@giganews.com>,
sns}22 <93914@EmbeddedRelated> wrote:
..
}      file = fopen("H:\test.txt","rw+");
}      fprintf(file,"%An",max_temperature_DegC);      
..
}I used this standard code. Although I have no compiler warning/errors.
}But when I debug; the code it gets stuck in the undefined handler (abort
}handler) as I can see it in the disassembly. The output file is not
}created and has no output.

As someone has pointed out "\t" is a tab character. But a more
important point is that your code is wrong because it does not check
for fopen() failing. When you use any library function that is documented
to report a failure, you should check that it succeeded and report if
not. The error codes are there for a good reason. Maybe H: doesn't
exist, or it's a physical drive with no medium, or the medium is
write-protected, or the file name is illegal, or there's already a
file of that name which you don't have permission to overwrite, or
there is no space to create a new file, or ... lots of things.
On Friday, April 10, 2015 at 1:54:54 PM UTC+2, sns22 wrote:
> Hi all, > > I am working with LPC2468 board from embeddedartists using the IAR > Embedded Workbench 7.3 > > I want to write my results read from a double variable into a txt file > created on the PC. I read on the forums and already set the library > settings to FULL to read the Dlib_Config files. > [code] > #include <nxp/iolpc2468.h> > #include <stdio.h> > #include <string.h> > > FILE* file; > file = fopen("H:\test.txt","rw+"); > fprintf(file,"%An",max_temperature_DegC); > fclose(file); > [/code] > > I used this standard code. Although I have no compiler warning/errors. > But when I debug; the code it gets stuck in the undefined handler (abort > handler) as I can see it in the disassembly. The output file is not > created and has no output. I am not using UART or any I2C to write to > the file. > Is it possible to write to a file on a PC directly or one has to use > UART/I2C > > Thanks > > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
Hi Sorry for late reply. Somehow I did not get an email notification for the answer. I have come back to the situation again. Thanks I also figured out the SDcard possibility in the development board. I am using UART to read the data from controller and I store it in a buffer. I can see this data on putty serial connection window. I am using JTAG for communication. And I have the PC connected via serial cable to the board. I am using the semi-hosting in IAR. Now I just want to write to a file on the PC stored on the PC. Thanks sns