S12X and reading  >64 K of flash in one loop

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

S12X and reading  >64 K of flash in one loop

830 Views
AndersJ
Contributor IV

I want to read many pages of flash in a single loop.

 

I declared:

unsigned short *far pGetAddressPoi; // FAR Pointer to a word variable

 

And load the pointer like this:

pGetAddressPoi = (unsigned short *far) 0x788000; // Point to word at global address

 

This works, for 64 K,

but how do I "add 0x1_0000" to the 16 bit pointer,

to read from 79_8000, 7A_8000 etc.

 

I tried incrementing GPAGE, but it is stuck at 0x78.

 

What am I doing wrong?

 

Thanks,

Anders J

Labels (1)
0 Kudos
Reply
7 Replies

621 Views
kef
Specialist I

Try replacing far with __far24. Difference between qualifiers is that 2nd is slower when doing pointer math, since full 24-bit address is calculated.

0 Kudos
Reply

621 Views
AndersJ
Contributor IV

__far24 does not compile.

 

C2450; Expected: ,

C2801; ';' missing

 

 

 

0 Kudos
Reply

621 Views
kef
Specialist I

Probably you are using older compiler version. According to <CW root>\Release_Notes\HC12\Notes_HC12_Compiler.txt , __far24 was introduced in compiler version V5.0.38.

 

If so, then I would try typecasting far pointer to long integer, calculate full address using integer math, and typecast the result back to far pointer. far pointer math operates on 16bit pointer ofset only.

0 Kudos
Reply

621 Views
AndersJ
Contributor IV

True, I use CW 4.7.

 

This is bootloader code, running in non banked memory, on the stack.

Will long integers be handled correctly when banked memory to

store required libraries is not available?

 

AJ

 

0 Kudos
Reply

621 Views
kef
Specialist I

Are you developing bootloader using banked memory model? I don't understand the problem of using libraries. Even if you chose wrong memory model, you can edit bootloaders PRM to allocate all banked and nonbanked code for example at 0xC000-0xFFFF.

 

I meant try doing this to add 0x10000 to the pointer.

     pGetAddressPoi  = (unsigned short *far)( (unsigned long)pGetAddressPoi + 0x10000 );

 

 

P.S.

  • This works, for 64 K,
  • but how do I "add 0x1_0000" to the 16 bit pointer,
  • to read from 79_8000, 7A_8000 etc.

Yyou meant add 0x8000 to get 798000, 7A8000 etc, right? Because pointer to short is incremented by what you add times sizeof(short). Typecasting to long int and calculating address you should take into account this difference between pointer math and integer math.

0 Kudos
Reply

621 Views
AndersJ
Contributor IV

Yes, banked memory bootloader.

 

I'm not saying there IS a library problem, just asking.

 

When I did this for the S12DT256 (CW 3.1) a few years back, I had problems with long integers

not being available from non banked code, because "long int" libraries were banked,

and therefore not available when running from stack.

Perhaps this is not a entirely accurate description, but it was something along those lines.

My query was whether there are any similar issues for HCS12X, CW 4.7.

 

Or, I am entirely wrong, barking up the wrong tree.......

 

Anyway, typecasting to long works, so I guess long int or not, is a non issue.

 

Thanks for your assistance.

 

Anders J

 

0 Kudos
Reply

621 Views
kef
Specialist I

It's more clear now. Even if library function is banked, you can edit PRM file and make banked functions allocated in nonbanked segment. Yes, if you make bootloader which is supposed to run from RAM (because flash is not readable while you it is being programmed, blablabla), you should not forget to copy banked routines to RAM. CPU won't complain if you call banked function, which doesn't appear within PPAGE window. But it is the best to choose small memory model for bootloader. far pointers are available even in small memory model.

0 Kudos
Reply