Reg: HCS12 Memory Re-Map

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

Reg: HCS12 Memory Re-Map

4,561 Views
nandu
Contributor III
Dear Everyone,
 
I am working with MC9S12DJ 64 MCU
 
By default, when I create a new project using Codewarrior Ver5.7.0. the .prm file assigns 3Kbytes to RAM i.e from 0x0400 TO 0x0FFF.
 
I want to remap this to have 4Kbytes.
 
And I came to know the default Start12.c code has his remap technique if we enable Serial Monitor according to the following code snippset.
 
Code:
#if defined(_HCS12_SERIALMON)   /* for Monitor based software remap the RAM & EEPROM to adhere      to EB386. Edit RAM and EEPROM sections in PRM file to match these. */   ___INITRG = 0x00;  /* lock registers block to 0x0000 */   ___INITRM = 0x39;  /* lock Ram to end at 0x3FFF */   ___INITEE = 0x09;  /* lock EEPROM block to end at 0x0fff */#endif

But, i have the follwoing two questions on this,

1. Can anyone please tell me how to enable this Serial Monitor code to re-map the memory in the MCU.

2. And imagine if the Serial Monitor is enabled, and the initialization of registers (INITRG = 0x00, INITRM = 0x39, and INITEE = 0x09) has become effective, what will be the starting address for the RAM or what are the boundaries of RAM in the whole memory map.

 According to the above snippset, it says the ending address of the RAM is 0x3FFF, and the total RAM size of this MCU is 4Kbytes, so the starting address will be 0x3000. (i.e. form 0x3000 to 0x3FFF = 4Kbytes)

Here, I am confused, why the INITRM was assigned 0x39 and why not 0x31...?? and what is the starting address of RAM if INITRM = 0x39; (Why the RAM11 bit of INITRM register has been assigned as 1).

Actually, I am pretty much confused with RAM11 bit, I referred to AN2881.pdf, it says...for example

if INITRM = 0x20; then RAM Boundary will be 0x2000 ~ 0x2FFF

if INITRM = 0x30; then RAM Boundary will be 0x3000 ~ 0x3FFF

so what will be the starting ddress format if we use RAM11 bit ...???

As I am not very experieced in this filed, all the help from you will be greatly helpful to me...

Thanks to you all in advance

Labels (1)
0 Kudos
9 Replies

803 Views
kef
Specialist I
Yadunandan,
 
What you want can be achieved two ways. You can create new project with PE enabled. PE by default remaps D64 RAM to 0x3000-0x3FFF.
Also you can do this without PE. You need to do two things, 1) modify start12.c or define _HCS12_SERIALMON making _Startup() initializing INITRM register, and 2) modify RAM setting in *.prm file:
 
/* RAM */
      RAM           = READ_WRITE    0x0400 TO   0x0FFF;
 

 
Regarding INITRM=0x39. RAM11 is relevant only for parts with 2k of RAM, RAM12 - for 4k RAM, RAM13 - 8k etc. 2k RAM block can be mapped to any 2k boundary like $0, $800,$1000, etc. 4k RAM block can be mapped to any 4k boundary: $0, $1000, $2000 etc. 8k - $0, $2000, $4000. 12k RAM block - $0, $4000, $8000 etc. Since 12k block doesn't fill all 16k location, RAMHAL decides does it start at bottom or ends at top of 16k block. And INITRM=0x39 is unique in that it will make almost all S12 parts (new S12P is different animal) mapping their RAM so that RAM ends at 0x3FFF. This is useful in that If one day there are no D64 in stock, you could buy D128 or bigger and chances are your code will work without single change.
 


Message Edited by kef on 2008-05-27 11:01 PM
0 Kudos

803 Views
nandu
Contributor III
HI Mr.Kef,
 
Thanks very much for your reply. I think i will use P&E to enable the Serial Monitor for my project.
 
And one more thing,,here  i face some pecurial problem, please have a look at it..
 
In my project, as the default Memory Re-map in the _Startup() is blocking by the _HCS12_SERIALMON,
I modified the default Reset Vector (i.e Vector at 0xFFFE) to my own ISR called _EntryPoint() in which I re-map the memory for RAM & EEPROM and then call the _Startup() function as below.
 
interrupt void _EntryPoint(void)
{  
*(uint8_t *)0x0011 = 0x00;
INITRM = 0x31;  /* RAM size : 4K , range : 0x3000 ~ 0x3FFF */
INITEE = 0x09;         
MISC   = 0x01;
__asm jmp _Startup;
}
 
and configured my .prm file to have RAM size from 0x3000 to 0x3FFF.
So, untill now there is no problem as I am using MC9S12D64. But recently i have changed my MCU from MC9S12D64 to MC9S12DG128. As you know, MC9S12DG128 has 8Kbyte of RAM which can be mappable to any 8Kbytes of total memory (I.e. from 0x0000 to 0xFFFF).
 
As MCU is changed and the RAM memory of new MCU is 8Kbyte, i have to change the INITRM value in my isr _EntryPoint() to 0x21 or 0x20 and i have to configure my .prm file to have RAM memory from 0x2000 to 0x3FFF.
 
But here i did a mistake, i changed my .prm file to have RAM memory from 0x2000 to 0x3FFF in the SECTIONS. But i forget to change the value that is assinged to INITRM register in my ISR (_EntryPoint()). It is same as previous value, i.e. INITRM = 0x31.That means, MCU tires to assign the RAM memory from 0x3000 to 0x4FFF(since RAMHAL bit dont have any effect for this MCU), which can not be acceptable for MC9S12DG128 as it has 8Kbyte RAM memory.
 
So, in this situation we generally expect the system should go to some malfunction or might expect to halt with illegal bp. But, there is no such of situation here. My system is working very fine even though i wrote 0x31 to INITRM register for MC9S12DG128 which is very very strange to me..:mansad:
 
how is it possible..? How my system is not getting halted ..?? What might be the possible reasons..?? :mansurprised:
 
I feel there is something that is restricting my RAM memory going beyong 0x3FFF, but i couldn't figure out what it is..
 
 
 

 
 
0 Kudos

803 Views
kef
Specialist I
 

INITRM = 0x31;  /* RAM size : 4K , range : 0x3000 ~ 0x3FFF */
...
 
and configured my .prm file to have RAM size from 0x3000 to 0x3FFF.
So, untill now there is no problem as I am using MC9S12D64. But recently i have changed my MCU from MC9S12D64 to MC9S12DG128. As you know, MC9S12DG128 has 8Kbyte of RAM which can be mappable to any 8Kbytes of total memory (I.e. from 0x0000 to 0xFFFF).

Not to any 8K, but to any 8K boundary. That means 8K RAM block can be mapped to 0-1FFF, 2000-3FFF, 4000-5FFF, etc. It can't be mapped for example to 3000-4FFF.
 


As MCU is changed and the RAM memory of new MCU is 8Kbyte, i have to change the INITRM value in my isr _EntryPoint() to 0x21 or 0x20 and i have to configure my .prm file to have RAM memory from 0x2000 to 0x3FFF.

Not really. If what you have in D64, 4k of RAM and 64k of flash is enough for you, but you want to be able to run the same compiled binary in D128 and in D256, then you should use INITRM=0x39 and use *.prm that is valid for smallest part, your code can run in.
INITRM=0x39 remaps D64 RAM to 0x3000-0x3FFF, D128 RAM to 0x2000-0x3FFF, 12k RAM block to 0x1000-0x3FFF etc. I mentioned that before.
 


But here i did a mistake, i changed my .prm file to have RAM memory from 0x2000 to 0x3FFF in the SECTIONS. But i forget to change the value that is assinged to INITRM register in my ISR (_EntryPoint()). It is same as previous value, i.e. INITRM = 0x31.That means, MCU tires to assign the RAM memory from 0x3000 to 0x4FFF(since RAMHAL bit dont have any effect for this MCU), which can not be acceptable for MC9S12DG128 as it has 8Kbyte RAM memory.

Again, RAMHAL is irrelevant for 2, 4, 8 and 16k RAM blocks. INITRM=31 remaps 8k of D128 RAM to 0x2000-0x3FFF.
 


So, in this situation we generally expect the system should go to some malfunction or might expect to halt with illegal bp. But, there is no such of situation here. My system is working very fine even though i wrote 0x31 to INITRM register for MC9S12DG128 which is very very strange to me..:mansad:

:smileyhappy:. You did set in prm, that your RAM is at 0x2000-0x3FFF. And INITRM=0x31 perfectly matches that. On D128 INITRM=0x20, 0x21, 0x22..0x3F do the same, remap D128 8K RAM block to 0x2000-0x3FFF.
 
Regards
0 Kudos

803 Views
nandu
Contributor III
Hi,
 
I completly agree with you Mr.Kef,
 
But, how the value of 0x39 to INITRM re-maps the RAM memory correctly according to the MCU like D64 RAM to 0x3000-0x3FFF, D128 RAM to 0x2000-0x3FFF, 12k RAM block to 0x1000-0x3FFF etc
I have a little confusion here
 
In general, i am thinking,the following INITRM values will give the memory map as shown below for an 8KByte MCU
 
if i write,
 
INITRM = 0x20   /*then, RAM will be from 0x2000 to 0x3FFF*/
INITRM = 0x21   /*then, RAM will be from 0x2000 to 0x3FFF*/
INITRM = 0x30   /*then, RAM will be from 0x3000 to 0x4FFF*/
INITRM = 0x31   /*then, RAM will be from 0x3000 to 0x4FFF*/
 
and since RAM can not be mappable to 0x3000 to 0x4FFF in case of DG128, does the MCU automatically sets the base address to 0x3FFF and maps the memory from 0x2000 to 0x3FFF even though we write 0x30 or 0x31 to INITRM..??
 
Did u got my point Kef, I hope i am not disturbing you much...
Kindly solve my confusion over this please
 
0 Kudos

803 Views
kef
Specialist I
Some derivatives ignore some INITRM bits
 
xxxxx---    C32 ignores 3 lower INITRM bits
 
xxxx----    D64 ignores 4 lower bits
 
xxx-----     D128 - ignores 5 lower bits
 
xx------    parts with 16k would ignore 6 lower bits
 
xx-----h   parts with 12k RAM ignore 5 :smileyminus: bits, and use RAMHAL (h) to align 12k block withing 16k window
 
 
0 Kudos

803 Views
nandu
Contributor III
Yes Mr.Kef.,,
 
Exaclty,.. I got cleared with this issue completly :smileyhappy:
 
Some of the INITRM bits will be ignored according to the RAM memory size of the derivative....
 
With your previous post, I got cleared with this and
 
The Memory Mapping Control Module (MMC) datasheet of MC9SDG128 also tells that which bits are relevant for INITRM register according to derivative... ( Table 3-3, Page No.17)
 
Thank you very much agian..this is such a useful information for me.. :manhappy:
 
 
0 Kudos

803 Views
JimDon
Senior Contributor III
From what I know, the only way to get SerMon to remap memory would be to modify the source code, re-assemble it and re-flash  it.

There are no provisions for re-mapping.




Message Edited by JimDon on 2008-05-26 10:48 AM
0 Kudos

803 Views
nandu
Contributor III
Thank you very much Mr.Jim
 
But I am confused, where should i modify my source code..??
 
I am very much new to this MCU memory organization and re-mapping.,...can you please give me some detailed picture or idea about this..it will be greatly helpful to me..
 
 
Thanks and Regards
Nandu
0 Kudos

802 Views
JimDon
Senior Contributor III
I don't use that chip, but CW should have set up the PRM file to work right with serial monitor.
CW puts that code in there for a sermon project bcause that is what sermon expects.

If you change things too much then serman may crash, as it needs some of ram to function, and expects it to be where CE put it.
I also don't use sermon much (ok, at all, except for testing versions that I have built),.

0 Kudos