Reply by franciscocantero1●August 26, 20092009-08-26
Hello,
I forgot to add something.
The uprintf function wont work when it is on its own (in uprintf.c file) I had
to move the function inside the code (where i have the specific function to
write the characters to port o to buffer) and then is when it works.
If the uprintf is on its own is when it doesnt allocate the va_list.
Thanks
--- In m..., "franciscocantero1" wrote: >
> Hello
> I was on holidays,
> Thank you very much for your help.
> I discovered that the code works.
>
> > > I just set up the compiler from the project options.
> > > Language C
> > > Allow IAR extensions
> > > char is unsigned
> > > R4 normal use
> > > R5 normal use
> > > reduce stack usage
> > > No optimizations
> There were optimizations at the project options, it was set for speed, once i
removed the optimizations the code start working.
> Thanks Anders.
>
> Francisco
>
Reply by franciscocantero1●August 17, 20092009-08-17
Hello
I was on holidays,
Thank you very much for your help.
I discovered that the code works.
> > I just set up the compiler from the project
options.
> > Language C
> > Allow IAR extensions
> > char is unsigned
> > R4 normal use
> > R5 normal use
> > reduce stack usage
> > No optimizations There were optimizations at the project options, it was set for speed,
once i removed the optimizations the code start working.
Thanks Anders.
Francisco
Reply by Anders Lindgren●August 7, 20092009-08-07
franciscocantero1 wrote: > > What compiler settings do you use? (If possible,
please send me the
> > entire command line.)
>
> I just set up the compiler from the project options.
> Language C
> Allow IAR extensions
> char is unsigned
> R4 normal use
> R5 normal use
> reduce stack usage
> No optimizations
>
> > Just one final thing, what HEAP size do you use? (The default is 50
> > bytes, if I recall correctly, so malloc(70) might return 0).
>
> My stack was 350 and heap 1200. When I reduced the them both to 100,
> then i got this print
> hello hello , times 1
> insted of "francisco" i got "hello".
> And if i modify:
> uprintf(PrintTo_Buf,"how u doing %s, times %d\r\n","francisco",i);
> i get:
> how u doing how u doing , times 1
>
> but at least the integer is printing properly
Strange, it seems to be working here...
If you like you can send me the list file, so that I can compare
instruction for instruction what happened.
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Reply by franciscocantero1●August 6, 20092009-08-06
> What compiler settings do you use? (If possible,
please send me the
> entire command line.)
I just set up the compiler from the project options.
Language C
Allow IAR extensions
char is unsigned
R4 normal use
R5 normal use
reduce stack usage
No optimizations
> Just one final thing, what HEAP size do you use? (The
default is 50
> bytes, if I recall correctly, so malloc(70) might return 0).
My stack was 350 and heap 1200. When I reduced the them both to 100, then i got
this print
hello hello , times 1
insted of "francisco" i got "hello".
And if i modify:
uprintf(PrintTo_Buf,"how u doing %s, times %d\r\n","francisco",i);
i get:
how u doing how u doing , times 1
but at least the integer is printing properly
Reply by Anders Lindgren●August 6, 20092009-08-06
franciscocantero1 wrote: > This code should put hello Francisco, times 1\r\n
> but the buffer has "hello 0P!R>@F, times 4430
Strange, I get:
"hello francisco, times 1
hello francisco, times 2
hello francisco, times 3
..."
I made two minor changes, just so that I would be able to see the result:
1) I moved the "memset" call to before the call to uprintf (so that the
resulting string would be properly zero-terminated).
2) Added a "puts(temp)" after the call to uprintf.
What compiler settings do you use? (If possible, please send me the
entire command line.)
Just one final thing, what HEAP size do you use? (The default is 50
bytes, if I recall correctly, so malloc(70) might return 0).
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Reply by franciscocantero1●August 6, 20092009-08-06
int uprintf(void (*func)(char ,void*), const char *format, ...);
int main(void)
{
int i;
char *temp;
buffer = (char *) malloc(70);
temp=buffer;
i=0;
while(i<50)
{
i++;
uprintf(PrintTo_Buf,"hello %s, times %d\r\n","francisco",i);
memset(temp, 0x00, 70);
buffer=temp;
WDTCTL = WDT_ARST_1000;
}
return 0;
}
void PrintTo_Buf(char c,void *dummy)
{
*buffer = c;
buffer++;
(void)dummy; /* Warning on this line OK (Optimized Away) */
}
int uprintf(void (*func)(char ,void*), const char *format, ...)
{
va_list ap;
int nr_of_chars;
va_start(ap, format); /* Variable argument begin */
nr_of_chars = _formatted_write(format, (void(*)(char,void*))func, (void *)
&format, ap);
va_end(ap); /* Variable argument end */
return nr_of_chars; /* According to ANSI */
}
This code should put hello Francisco, times 1\r\n
but the buffer has "hello 0P!R>@F, times 4430
"
Thanks for your help,
Francisco
Reply by Anders Lindgren●August 5, 20092009-08-05
franciscocantero1 wrote: > this is a test that im doing:
>
> [...] > > What i notice is that inside formatted write
(frmwri.c) at line 477
> if( !(buff_pointer= VAPTR(char))) this buff_pointer is not pointing to
> the string that i want to print. So I believe this is happening because
> va_start(ap,format) is not starting the ap properlly.
It looks as though it should work -- even though there are some strange
details in your code. (It is not kosher cast between function pointer
types, instead you should ensure that your serial out function should
take two parameters. Also, the third parameter to _formatted_write
should should be '0', unless you plan to use it in your output
function.)
If you put together something I can compile and run (with some kind of
dummy variant for 'serial_out', e.g. something that puts the
characters
in an array), I could take a look at it.
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Reply by franciscocantero1●August 5, 20092009-08-05
sprintf(buffer,"hello time is: %d:%d:%d\r\n",hours,minutes,seconds);
}
buffers has: hello time is: 10:20:22\r\n
Sprintf is working in my code, but the function that you help me with uprintf
(message 37845) (that was working in 3.41) is not working in this new
version.
my uprintf is as follows
#include "stdarg.h"
#include "stdio.h"
#include
//printing function
extern void (*serial_out)(char c);
int uprintf(void (*func)(char c), const char *format, ...)
{
va_list ap;
int nr_of_chars;
va_start(ap, format); /* Variable argument begin */
nr_of_chars = _formatted_write(format, (void(*)(char,void*))func, (void *)
&format, ap);
va_end(ap); /* Variable argument end */
return nr_of_chars; /* According to ANSI */
}
What i notice is that inside formatted write (frmwri.c) at line 477
if( !(buff_pointer= VAPTR(char))) this buff_pointer is not pointing to the
string that i want to print. So I believe this is happening because
va_start(ap,format) is not starting the ap properlly.
Reply by Anders Lindgren●August 4, 20092009-08-04
> I could take a look at it, but I would need a small
but complete example > > that demonstrates the problem.
> >
> > Also, I would need to know if you are using DLib or the legacy CLib
> library.
>
> I used CLib but for trying to get it to work I used both of them with
> the same result.
> I modified one of the printf functions to uprintf, by the way thanks to
> your help.
> an example of the code is:
>
> uprintf(serial_out,"\r\n time %d:%d:%d\r\n",hours,minutes,seconds);
>
> where serial_out is a function that send bytes to the serial.
>
> this uprintf when is ran we can see nothing on the console just:
> time (various strange carachters corresponding to the portion of memory
> that va_list has):(same as previous place):(same)
Hi!
Unfortunately, it's still not enough information for me to investigate.
I would need a small complete example that I could compile.
By "complete", I mean that I should be able to place a piece of code in
a source file, compile, link, and run without having to modify the
program in any way. By "small" means that I do not want a large
application (most issues can be distilled into a handful of lines).
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Reply by franciscocantero1●August 4, 20092009-08-04
>
> Hi!
>
> I could take a look at it, but I would need a small but complete example
> that demonstrates the problem.
>
> Also, I would need to know if you are using DLib or the legacy CLib
library.
>
> -- Anders Lindgren, IAR Systems
> --
> Disclaimer: Opinions expressed in this posting are strictly my own and
> not necessarily those of my employer.
>
Hello;
I used CLib but for trying to get it to work I used both of them with the same
result.
I modified one of the printf functions to uprintf, by the way thanks to your
help.
an example of the code is:
uprintf(serial_out,"\r\n time %d:%d:%d\r\n",hours,minutes,seconds);
where serial_out is a function that send bytes to the serial.
this uprintf when is ran we can see nothing on the console just:
time (various strange carachters corresponding to the portion of memory that
va_list has):(same as previous place):(same)