EmbeddedRelated.com
Forums

Printf() in banked memory model

Started by "Profos, Georg" November 21, 2006
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.

Georg
Hi Georg,

I assume you are using CodeWarrior, correct?

I could guess your problem is that by default in the small/banked memory
model, string literals (or other constants) do have just a 16 bit
address, hence the compiler is taking the page as 0.
To explicitly tell the compiler that further string literals are far,
use the following pragma:
#pragma STRING_SEG __FAR_SEG MY_FAR_STRINGS

and then allocate MY_FAR_STRINGS into the paged area.
Placing the built-in STRINGS section there is a bit dangerous as some
other code may use string literals without being prepared that it is
allocated paged.

Daniel

PS: For constants use
#pragma CONST_SEG __FAR_SEG MY_FAR_CONSTANTS

PPS: Which derivative are you using? A HC12 (A4?), a HCS12 or a HCS12X?
Which version of the compiler?

Profos, Georg wrote:
> 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.
>
> Georg
>
> Yahoo! Groups Links
>
>
Many thanks. I tested your suggestion and it works... but... what if I
define a constant string implicitly, viz

printf("Hi there");

can I make the compiler place that string into another segment? If so,
how to proceed?

I use HCS12 with 512kB Flash. CW 4.5 for HCS12.

Georg

________________________________

Von: 6... [mailto:6...] Im Auftrag
von Daniel Friederich
Gesendet: Dienstag, 21. November 2006 13:12
An: 6...
Betreff: Re: [68HC12] Printf() in banked memory model

Hi Georg,

I assume you are using CodeWarrior, correct?

I could guess your problem is that by default in the small/banked memory

model, string literals (or other constants) do have just a 16 bit
address, hence the compiler is taking the page as 0.
To explicitly tell the compiler that further string literals are far,
use the following pragma:
#pragma STRING_SEG __FAR_SEG MY_FAR_STRINGS

and then allocate MY_FAR_STRINGS into the paged area.
Placing the built-in STRINGS section there is a bit dangerous as some
other code may use string literals without being prepared that it is
allocated paged.

Daniel

PS: For constants use
#pragma CONST_SEG __FAR_SEG MY_FAR_CONSTANTS

PPS: Which derivative are you using? A HC12 (A4?), a HCS12 or a HCS12X?
Which version of the compiler?

Profos, Georg wrote:
> 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.
>
> Georg
>
> Yahoo! Groups Links
Hi Georg,

Is this not the actual effect of the #pragma STRING_SEG?
After a #pragma STRING_SEG __FAR_SEG BLUBS_STRINGS,
all strings literals should end up in BLUBS_STRINGS, or?
This pragma has to be before any string literal, for example in a header
included by all source files first.

Daniel

Profos, Georg wrote:
> Many thanks. I tested your suggestion and it works... but... what if I
> define a constant string implicitly, viz
>
> printf("Hi there");
>
> can I make the compiler place that string into another segment? If so,
> how to proceed?
>
> I use HCS12 with 512kB Flash. CW 4.5 for HCS12.
>
> Georg
>
> ________________________________
>
> Von: 6... [mailto:6...] Im Auftrag
> von Daniel Friederich
> Gesendet: Dienstag, 21. November 2006 13:12
> An: 6...
> Betreff: Re: [68HC12] Printf() in banked memory model
>
> Hi Georg,
>
> I assume you are using CodeWarrior, correct?
>
> I could guess your problem is that by default in the small/banked memory
>
> model, string literals (or other constants) do have just a 16 bit
> address, hence the compiler is taking the page as 0.
> To explicitly tell the compiler that further string literals are far,
> use the following pragma:
> #pragma STRING_SEG __FAR_SEG MY_FAR_STRINGS
>
> and then allocate MY_FAR_STRINGS into the paged area.
> Placing the built-in STRINGS section there is a bit dangerous as some
> other code may use string literals without being prepared that it is
> allocated paged.
>
> Daniel
>
> PS: For constants use
> #pragma CONST_SEG __FAR_SEG MY_FAR_CONSTANTS
>
> PPS: Which derivative are you using? A HC12 (A4?), a HCS12 or a HCS12X?
> Which version of the compiler?
>
> Profos, Georg wrote:
>
>> 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.
>>
>> Georg
>>
>> Yahoo! Groups Links
>>
>
>
>
>
>
> Yahoo! Groups Links
>
>