mc9s12dt256b reentrant sprintf issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mc9s12dt256b reentrant sprintf issue

3,155 Views
Franklin
Contributor I
Hi,
 
I am using sprintf to write a 68 char array, and have a 10ms timer interrupt running. I believe the interrupt is interrupting sprintf, and beacuse its not reentrant, crashing. (illegal bp)

I read that there's a way to use a reentrant version of sprintf here:  http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&message.id=1824&query.id=1006...
 
but couldn't make it work. When I add PRINTF.c to the linker files, and -DLIBDEF_REENTRANT_PRINTF to the compiler directives, I get a lot of compiler errors complaining about problems in stdio, and PRINTF.c, starting at the #if reentrant part. I am lost, but hope the solution is simple...
Labels (1)
0 Kudos
6 Replies

589 Views
Franklin
Contributor I
I don't know. How do you increase stack space?

making sprintf reentrant, solved the issue i was having, but now I am having other problems with functions being interrupted, and my program crashing.
0 Kudos

589 Views
Franklin
Contributor I
HAh1!!! it works! I can't believe it. I didn't thin it would actually work. Thank yoou.
0 Kudos

589 Views
CompilerGuru
NXP Employee
NXP Employee
And what was the actual issue? Stackspace?

Daniel
0 Kudos

589 Views
Franklin
Contributor I
how do I assign more stack space?
0 Kudos

589 Views
CompilerGuru
NXP Employee
NXP Employee
Did you define a value for LIBDEF_REENTRANT_PRINTF?
E.g. Did you use:
-dLIBDEF_REENTRANT_PRINTF=1

Just defining the macro with no value does not build.

Also make sure to move printf.c in the link order before the ansi library (and ignore the warnings about the second printf implementation in the ansi library)

Daiel
0 Kudos

589 Views
CompilerGuru
NXP Employee
NXP Employee
And BTW. As long as your interrupt handler is not using any of the printf like functions there should be no problem. Printf is using a lot of stack, I would suggest that you are checking that not experiencing a stack overflow.
Using printf functions in interrupt handlers is possible if you recompile it to be reentrant and if you allocate enough stack space, but even then the execution may just take to long to be acceptable.

Daniel
0 Kudos