Need help with GPAGE on S12X

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

Need help with GPAGE on S12X

4,736 Views
xgater
Contributor I
I have read AN2734.pdf and S12XCPUV1.pdf and expermented some in the simulator and I still don't get it. Can someone please explain how PPAGE, GPAGE, far pointers and __pptr pointers relate?
 
I'm trying to point to the beginning of the flash page FE. If I typecast the 32bit integer 7F8000 to a far pointer it points to a different location than if I cast it to a __pptr pointer. I think the far pointer is "right" but where is the __pptr pointing to????
 
Somebody help me please!
 
 
Labels (1)
0 Kudos
8 Replies

828 Views
xgater
Contributor I
Thanks, Daniel. I did put the 7F8000 in the wrong field and had a typo leaving out one of the 'p's in __pptr.
 
I have read the thread called "Problems erase flash sectors" where you suggested using the __pptr instead of __far and am still trying to figure out how the pptr works. So, if I want to write to global address 7F8000 would I need to cast FE8000 to a __pptr? Should I abandon my efforts to use the __pptr and use __far instead?
 
Thanks also to Steve. I hope you can get me those documents. Your map definitions are very helpful. In my bbl file it creates "global", "physical" and "logical" s record files. So, can you give me another defnition for the "physical" map?
 
0 Kudos

828 Views
Steve
NXP Employee
NXP Employee
I can't help with the explanation of physical - I guess these are legacy comments inside the BBL file - maybe one of the tool folks can help.
I found TN238 with CrasyCat's help - download http://www.freescale.com/files/soft_dev_tools/doc/support_info/CW_816-bit_Technical_Notes_SP.zip and you'll find an installer that installs a bunch of tech notes. Have a look for TN238 in the Build Tools folder. TN240 is also worth a look.
I'll work with one of the mods to get the other one up.
0 Kudos

828 Views
CompilerGuru
NXP Employee
NXP Employee
The other thread you refer to was containing existing assembly code for a HCS12 which did use logical addresses.
Especially for this setup I did mention __pptr, but when you
follow the thread further, then in the end the OP did use global addresses with __far pointers :smileyhappy:.

Basically both kind of pointers work, but the __pptr way has one limitation you have to handle when using __pptr's:
For dereferenciation they directly set PPAGE, and this only works if the code runs outside of the 0x8000..0xBFFF page window.
And because of this limitation, I only even mention __pptr pointers when there is some special use case for them.
So to keep you code simple, and if you do not have any other reason, I would go with __far pointers (and therefore with global addresses).


Daniel

PS: *(*__pptr)0xFE8000/* 'L */ is refering to the same memory byte as *(*__far)0x7F8000/* 'G */ (but only works when executing code out of 0x0000..0x7FFF or 0xC000..0xFFFF, well I repeat myself)
0 Kudos

828 Views
xgater
Contributor I
Sorry for my ingorance but I'm still lost. I've looked at AN2615 and AN2734 and found the hsc12xadrmap.exe (which I never would have found without your help). The hsc12xadrmap.exe doesn't seem to want to support my derivative "MC9S12XDT256". Its in the list but won't let me select it. But, it doesn't seem to matter for this which one I pick.
 
This app says that the logical address 7F8000 is equal to global address 5FC000. Where is this coming from? I don't see any global addresses in flash below 780000 in ANY of the documents I've looked at including the data sheet on my processor.
 
Everyone seems to say that this is confusing at first but once you get it everything will be ok. Well I've been writing asm and C for embedded systems for over 20 years and never come across anything this confusing and poorly documented. I've been trying to "get it" for days now. Someone needs to make a map that relates local, logical, physical and global addressing to the page registers, etc. My guess is that anyone who has figured this out keeps their own hand drawn map in a very safe place. I'm longing for my days with the "simple" MPC555.
 
So, my specific question is....
If I want to point to what I'm calling 7F8000 using a __ptr pointer type. What integer value would I cast to it? 7F8000 or 5FC000.
 
And the follow-up questions is...
If the right answer is 5FC000, how would I translate all my addresses in my s-record into that form for my flash loader?
 
0 Kudos

828 Views
Steve
NXP Employee
NXP Employee
Hopefully Daniel answered your specific question. I'd like to add a summary of the memory maps:
 
1/ Global map: 8MB linear space that contains all the on-chip and off-chip resources. This is everything that the MCU can "see". CPU uses special global load and store opcodes to access anywhere in this map. The upper 7 bits of the address are stored in the GPAGE register.
 
2/ Local map: This is the 64k space that the CPU can directly access using its native 16-bit instructions. It runs from 0x0000 to 0xFFFF and contains all the peripheral registers and fixed and paged areas of RAM, flash, and EEPROM. The exact RAM, flash and EEPROM pages in the map are controlled by the RPAGE, PPAGE and EPAGE registers. You can use global memory in addition to local memory so you can run code anywhere in flash and seamlessly access any other location in memory without having to modify the contents of the local pages.
 
3/ Logical map: this is a term coined by the CodeWarrior folks to describe the combination of local map and memory page registers. So for example logical address 0xFE8100 is an address in flash while 0xFE1100 is an address in RAM. The key to understanding this is to ignore the upper byte (which contains a local memory page - PPAGE, RPAGE, EPAGE) and look at the local address in the lower 16 bits to determine what type of memory is being accessed. This term is not used in the device documentation.
 
Let me see what I can do about getting TN238 and AAR112 made available because I believe that these explain the architecture and software considerations quite clearly.
0 Kudos

828 Views
CompilerGuru
NXP Employee
NXP Employee
The problem you have is that 0x7F8000 is NOT a logical address it is a global address.
So place this one into the global field!
Use (*unsigned char __far)0x7F8000 to access this memory in your code.

And add a big comment that 0x7F8000 is the global address 0x7F8000'G :smileyhappy:


>If I want to point to what I'm calling 7F8000 using a __ptr pointer
> type. What integer value would I cast to it? 7F8000 or 5FC000.

Well that's a confusing question as there is nothing like a __ptr.
Use __far, and use 0x7F8000.

Daniel
0 Kudos

828 Views
Steve
NXP Employee
NXP Employee
This comes down to fact that there are multiple ways of accessing memory on the S12X. For flash you have PPAGE, for RAM you have RPAGE and for EEPROM you have EPAGE and for all three you also have the alternative of using GPAGE. Depending on the circumstances one may be more efficient than the other so CodeWarrior gives a choice of how to access memory.
Basically you define the type of access used by a pointer in its declaration and the compiler will use that type of access from then on and so you can just get on and write C.
If you define a pointer with __pptr you will use PPAGE to access that memory. If you use far then you will use GPAGE. PPAGEs are 16k in size and apply only to the flash range 0x8000 to 0xBFFF and GPAGEs are 64k and applies to the entire 8Mb memory map. This explains why you have different addresses for the same memory location - one uses PPAGE page addresses and the other uses GPAGE page addresses.
In your example flash page 0xFE is a PPAGE value which corresponds to part of GPAGE (far) address of 0x7Fxxxx.
This can be confusing the first time you meet it but there is lots of supporting material and if you understand the approach you can write very efficient and small code.
Have a look at the memory map utility included with CodeWarrior. Find it in the /prog folder or as a component of the debugger: it's called hcs12xadrmap.exe. It allows you to translate between the different memory addresses.
For more background on the memory mapping on the part read AN2615 and AN2734. There were some training presentations from FTF last year which I can't find on the web right now but AAR112 is the number.
Of course if you always have the option of just using one approach and then all the pointers will behave in the same way using the same memory map.
0 Kudos

828 Views
CompilerGuru
NXP Employee
NXP Employee
The integer 0x7F8000 is just an long, so castet to different pointer types it does indeed point to different places.
Used as global address with a __far pointer it points to where you want because the global address 0x7F8000'G points to this flash location.
When casted to a logical __pptr pointer, it points to a flash löcation which does not exist for any current HCS12X (because none has that much flash yet).
So use __far. There is a utility program in codewarrior\prog which computes the mapping from the address spaces. Out of my memory, I'm not sure what the name is, I think something like hcs12xadrmap.exe. Try it out.
If you have an C object at this address, the simplest thing is to use the compiler and take the address of it.

Daniel
0 Kudos