Printf() in Banked Memory Model (HCS12)

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

Printf() in Banked Memory Model (HCS12)

Jump to solution
4,016 Views
vectorio
Contributor II
I am facing some problems using printf(). It works nicely in large memory model, but in banked memory model, I am forced to allocate STRINGS in the nonbanked section, which isn't very nice because we don't have a lot of unbanked space. Is it possible to make printf() work in banked memory model with arguments in banked ROM/RAM? If so, how? The code I get seems to hand over 16bit pointers only.

I tried recompiling the lib, and the code I got actually handed over 3 bytes, but the page part was always 0.
Labels (1)
Tags (1)
0 Kudos
1 Solution
783 Views
CrasyCat
Specialist III
Hello
 
In banked memory model, the predefined section STRINGS contains per definition objects accessed with 16-bit address.
If you wish to get some string constants allocated in banked memory you have to define them in a user defined string section defined with qualifier _PPAGE_SEG.
 
For example
#pragma STRING_SEG __PPAGE_SEG MyFarString
/* Define your strings here */
#pragma STRING_SEG DEFAULT
 
Also make sure to build your application with -CpPPAGE=RUNTIME to let the compiler know it should use a run time function to access banked strings.
Also make sure that you activate that option when you rebuild the ANSI libraries.
 
I assume you have redefined the macro LIBDEF_FAR_CONST_STRINGS, LIBDEF_FAR_STRINGS when building the libraries. 
 
CrasyCat

View solution in original post

0 Kudos
6 Replies
784 Views
CrasyCat
Specialist III
Hello
 
In banked memory model, the predefined section STRINGS contains per definition objects accessed with 16-bit address.
If you wish to get some string constants allocated in banked memory you have to define them in a user defined string section defined with qualifier _PPAGE_SEG.
 
For example
#pragma STRING_SEG __PPAGE_SEG MyFarString
/* Define your strings here */
#pragma STRING_SEG DEFAULT
 
Also make sure to build your application with -CpPPAGE=RUNTIME to let the compiler know it should use a run time function to access banked strings.
Also make sure that you activate that option when you rebuild the ANSI libraries.
 
I assume you have redefined the macro LIBDEF_FAR_CONST_STRINGS, LIBDEF_FAR_STRINGS when building the libraries. 
 
CrasyCat
0 Kudos
783 Views
Sector
Contributor I
CrasyCat,

I ran into the same problem with printf. I am following all the tricks you listed in this thread but it is still not quite right. Even I use the vprintf in printf.c

After inspecting the assembly listing, the caller pushes the 16-bit address as well as the page number of the string onto the stack (note the page number used to be always zero, but not anymore after I applied the trick). I think this is correct and expected behavior.

But I get garbage output. I noticed that if the string and vprintf() are in the same flash page then it prints correctly. Otherwise I get garbage. This suggests that vprintf() ignores the page number.

 I currently do not have LIBDEF_FAR_CONST_STRINGS, LIBDEF_FAR_STRINGS and place MyFarString in non-paged memory (small data, banked function) and it works fine. This method is suggested in this thread:

http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&message.id=240&query.id=22084...

You agreed with vectorio that strings must be in non-paged memory for it to work. But in this thread you implied that strings may be in any page (banked data, banked function). Can you clarify that?

If you're sure that string can be anywhere then chances are I made some silly mistakes. What course of action would you recommend, such as experiments to find out what's worng?

Sector

0 Kudos
783 Views
CrasyCat
Specialist III
Hello
 
I would recommend you to look at the FAQ-27439 on Freescale web site.
This FAQ explains you what you need to care about if you want to allocate string constants in banked memory.
 
I assume you did nor generate a new version of ANSI library supporting banked string constants.
 
Also note that the process is different for HCS12 & HCS12X.
I hope this helps.
 
CrasyCat
0 Kudos
783 Views
vectorio
Contributor II
Many thanks, it works!
 
However, if I use something like
 
 printf("Good morning");
 
this "implicitly" creates a constant string... how can I influence where it is placed? Is it possible to tell the compiler that I want it in __PPAGE_SEG?
 
0 Kudos
783 Views
CrasyCat
Specialist III
Hello
 
Did you try to put the pragma STRING_SEG prior to the implementation of the function where you have the printf?
 
This should do the trick (in my opinion). All string constants within the function will then be allocated in the same user defined string section.
 
CrasyCat
0 Kudos
783 Views
vectorio
Contributor II
Well, yes I did, but I also put the DEFAULT pragma before it :smileywink: ... it works now. Again many thanks.
0 Kudos