Using %x in printf() doesn't work

cancel
Showing results for 
Search instead for 
Did you mean: 

Using %x in printf() doesn't work

Jump to solution
5,353 Views
Contributor I
I am using the command line compiler in CodeWarrior V6.1 for a ColdFire MCF51QE128 processor.
I am linking with the C_2i_CF_RegABI_MSL.a and C_2i_CF_RegABI_Runtime.a libraries.

I have found that using the %X specifier in a printf() call does not produce any output. %d works fine. It's as if the %X format is disabled in the library. Am I using the wrong library or can I change some definition in one of the existing library source files and recompile it? If so, how do I go about recompiling a library source?

Thanks


Labels (1)
0 Kudos
1 Solution
213 Views
Specialist III
Hello
 
CodeWarrior for MCU is  delivered with reduce working set MSL libraries.
In this library, printf does not support all format modifiers. This allows us to reduce the footprint of function printf.
 
You can activate support for display of Hexadecimal number in the following way:
  - Start the IDE
  - Open the project {Install}\ColdFire_Support\msl\MSL_C\MSL_ColdFire\Project\MSL_C.CF.v1.word.mcp (where {Install} refers to your CodeWarrior installation directory)
  - Activate target "2i ColdFire RegABI"
  - Open the target settings dialog (press ALT+F7)
  - Switch to the "C/C++ Preprocessor" panel
  - Add following line in there:
        #define LIBDEF_PRINTF_ALLOW_HEXINT 1
  - Close the Target Settings dialog pressing OK
  - Press the Make button to rebuild the library
  - rebuild your project.
 
printf should support %X from now on.
 
CrasyCat

View solution in original post

0 Kudos
13 Replies
214 Views
Specialist III
Hello
 
CodeWarrior for MCU is  delivered with reduce working set MSL libraries.
In this library, printf does not support all format modifiers. This allows us to reduce the footprint of function printf.
 
You can activate support for display of Hexadecimal number in the following way:
  - Start the IDE
  - Open the project {Install}\ColdFire_Support\msl\MSL_C\MSL_ColdFire\Project\MSL_C.CF.v1.word.mcp (where {Install} refers to your CodeWarrior installation directory)
  - Activate target "2i ColdFire RegABI"
  - Open the target settings dialog (press ALT+F7)
  - Switch to the "C/C++ Preprocessor" panel
  - Add following line in there:
        #define LIBDEF_PRINTF_ALLOW_HEXINT 1
  - Close the Target Settings dialog pressing OK
  - Press the Make button to rebuild the library
  - rebuild your project.
 
printf should support %X from now on.
 
CrasyCat

View solution in original post

0 Kudos
213 Views
Contributor I

I've run into the same problem with being unable to use the %x format specifier in printf() calls (results: no output of the hexadecimal numbers I am expecting). However my development is for Coldfire V1 architecture using the C_4i_CF_RegABI_MSL.a and the C_4i_CF_RegABI_Runtime.a libraries in a product currently in production. I'm inexperienced at recompiling the libraries, and I'm worried that I may FUBAR the whole thing. Can anyone provide me guidance on the matter? Thanks.

0 Kudos
213 Views
Specialist III

Hello

 

Did you look at following post

  https://community.freescale.com/message/59470#59470

 

CrasyCat

0 Kudos
213 Views
Contributor III

Similiar problem:  %f in printf() doesn't work. 

 

I've got this version of CodeWarriors installed:  "CW MCU v10.0"

 

Could somebody update the instructions to enable %f (there is no *.mcp file in the installation directory).


Thanks

Dogbert256

0 Kudos
213 Views
Specialist III

Hello

 

Which MCU are you targeting (HC08, Coldfire V1, ....)?

 

CrasyCat

0 Kudos
213 Views
Contributor III

 

My target is the Coldfire V2 processor MCF5232.  It has EMAC, and I'm able to use floating point variables.

 

But no go on %f in printf().


Thanks bunch!

 

Dogbert256 

 

P.S. - I'm thinking of just writing my own print_float() function for this, unless there is an easy fix.

0 Kudos
213 Views
Contributor III

Thought I'd go back and give the solutions to these old posts.

 

%f in printf(); will work if you do the following in your project and CodeWarriors:

 

Include the following libraries in your .c code (maybe some are not needed)

 

#include <cstring>

#include <stdio.h>

#include <stdarg.h>

 

Highlight your configuration -> right click Properties/C/C++ Build/Settings/Tool/Settings/Librarian/Model = C9x

Print format = int_LL_FP

 

%f specifier in printf(); and the various other string functions should work.

0 Kudos
213 Views
Contributor II

I had the same problem using sprintf with %f.

 

On CW10.2, all you have to do is to include stdio.h and then go to Project > Properties > Settings. Under the Tool Settings tab, click on Librarian. On the right, in Print formats, select int_LL_FP. Leave the option above it as ewl.

213 Views
Contributor I

CrasyCat,

 

Is this fix still applicable to CodeWarrior Dev Studio v. 7.1? 

 

If so, can you update the project path and filename of the library project that needs to be modified?  They appear to have been changed since you first posted the fix. 

 

Thanks.

 

0 Kudos
213 Views
Contributor I
Hello.

I have followed your instructions exactly and it now works perfectly.

Thanks for your help.

jmv
0 Kudos
213 Views
Senior Contributor II
For platforms with limited memory, the "tiny I/O" subsystem of MSL (_MSL_C_TINY_IO) includes a very limited printf(), with most features turned off by default.
 
If you search your ColdFire_Support directory for LIBDEF_PRINTF_ALLOW_HEXINT you'll find the printf() you are using, and why %x is not working.  You need to define this flag, as well as a slew of other flags, to have a fully working printf().
 
If you are only using small pieces of MSL, I have found it is easier to just include the specific source files in the project, rather than the libraries -- this has the advantage that you can also freely change calling conventions without having to figure out the new library name you need to use.  I have avoided needing to rebuild the library that way (the source files just get recompiled in my project, as needed).
 
I have also built my own printf(), which interfaces with the debugger, but it is for the V2 cores, so I don't know how different the debugger interaction is for V1.  The original thread that prompted me to do this is here: http://forums.freescale.com/freescale/board/message?board.id=CWCFCOMM&thread.id=1769&view=by_date_as...
 
At the end of that thread, Tudor S tells how to revert to the "pre-tiny I/O" behavior.  If you want a new printf.c, it is attached.  You'd have to hook the bottom of it into the V1 debugger interface (which I assume is totally different than V2, since they use a different toolchain).
0 Kudos
213 Views
Contributor III

I tryed your printf files, but I have some problem. I'm using C_4i_CF_SZ.a for a mcf52221.

 

When I compile your files the linker gives me errors:

- undefined MIN

- undefined terminal_print

 

where can I find this code or how can I  implement them?

 

Thanks

0 Kudos
213 Views
Contributor I
Im new on this, sorry for this answer but, what is MSL? Im working with the MCF51QE128, i have the evaluation board for this MCU. I already downloaded this files:

CodeWarrior Development Studio 8_16bitIDE_UserGuide.pdf
CodeWarrior Development Studio ColdFire Assembler Manual for Microcontrollers.pdf
CodeWarrior Development Tools MSL Reference.pdf
CodeWarrior Development Tools MSL C++ Reference.pdf

The CodeWarrior that i have it is the 5.9. I looked the "CodeWarrior Development Tools MSL Reference.pdf" file but that's a kind of C manual, but only for instructions not for programming the MCU's. Where can i get a manual that teachs or ilustrates how to program a MCU in C language?

Thanks for your help...and sorry, im new on this and i will appreciate your help.

Thanks again! and I'll wait for your answer..
0 Kudos