MC9S12XEP100 EEPROM Emulation Questions

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

MC9S12XEP100 EEPROM Emulation Questions

2,897 Views
roberthiebert
Senior Contributor I

MC9S12XEP100. Code Warrior IDE V5.9.0 build 5294. Absolute assembler. Freescale USBDM.

I am trying to do a one time process to configure the processor so the complete D-Flash and Buffer Ram can be used for EEPROM Emulation. I have been studying the MC9S12XEP100RMV1 reference manual , application notes AN3490 and AN3743, as well as the EEPROM-XEP100-Example+description.

I have written the attached sample code, which runs, but I do not see the results expected when I use the de-bugger.

Any suggestions on what I might be doing wrong would be greatly appreciated.

Regards,

Robert Hiebert

0 Kudos
Reply
11 Replies

2,449 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

have you already read a reference manual. I know, it is not easy but... such help is far out of technical support and falls into paid support.

Attached you can find full solution for variables E/W in EEEPROM with entire buffer ram used and entire d-flash used for emulation.

Be sure you change FCLKDIV to correct value corresponding to your oscclk. Values can be found in the ref. manual.

I believe you will understand. It is not complicated just need hours and hours of experience.

Best regards,

Ladislav

 

0 Kudos
Reply

2,438 Views
roberthiebert
Senior Contributor I

Hi Ladislav,

Thanks for that attachment. It confirms what I already had figured out from all of the information that you had given me before, which I appreciate very much, but it still doesn't answer my question.

I understand your WRITE_EEE_WORD subroutine, and I have been able to get the same result in a test code, but I have 4 kilobytes of default word aligned values that I have to copy from P-Flash to buffer RAM. I can do this one step at a time by defining each and every EEE_var_W and calling the subroutine every time, but there must be a more efficient way to do it by incrementing EEE_ADDR and doing it in a loop.  I just haven't been able to figure out how to do that yet.

Regards,

Robert   

0 Kudos
Reply

2,420 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

The MCU does not have DMA, but it does have XGATE (a RISC core, routines are triggered by an interrupt request), which can be used together with semaphores to process data in parallel, independent of CPU activity. However, this requires the use of the XGATE assembler. Honestly, I wouldn't do it in assembler, but I would do it in C, which is much easier. Or I would do it in C at least in the first approach and look at the translation.

Some XGATE examples (I did a looooong time ago) you can find at

https://community.nxp.com/t5/S12-MagniV-Microcontrollers/LAMA-s-S12XE-unofficial-examples/ta-p/11007...

 

Best regards,

Ladislav

 

0 Kudos
Reply

2,406 Views
roberthiebert
Senior Contributor I

Hi Ladislav,

I'll keep working on it. Maybe I can attack it from another angle. Thanks so much for all your help. The learning process is at work.

Regards,

Robert

0 Kudos
Reply

2,851 Views
roberthiebert
Senior Contributor I

Ops. I wondered why I haven't received any answers to my post. I just noticed my code example didn't get attached so I'll try again.

The code seems to run OK without any errors. When I use the debugger I see that global addresses from $13_F000 to $13_FFFF have been erased. Also, local addresses $0800 to $0FFF have been erased.

I would like to be able to use all of the 4Kb in Buffer RAM for EEE but only 2Kb is available in local addresses $0800 to $0FFF. How do I access the remaining 2KB?

Regards,

Robert

0 Kudos
Reply

2,830 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I would like to ask. Do you really need 4kB of data in emulated eeprom. The more data the less number of updates. Have you calculated your requirement by means of S12XE_EEE_CALCULATOR 

https://www.nxp.com/search?keyword=S12XE_EEE_CALCULATOR%2520&start=0

If you want to use entire buffer ram and also as a linear space you have to use global addressing mode and global instruction for R/W.

From memory map I sent to you..

lama_0-1745961444880.png

So the space fill be 13F000-13FFFF and far pointer or globally defined variable must be used.... or ASM instruction for global addres R/W ... se S12X V2 core reference manual.

The example XEP100-BufferRAMasOneArray-CW51 shows how to address entire buffer RAM with far pointer. Of course this is only one approach. You can also define a variable into this space.

 

For example writing address 0x13F400 with value 0x22 (char)

LDAB #$22 ; prepare value to be written

LDAA #$13 ; prepare gpage of buffer ram and write it to

STAA $10  ; gpage register

GSTAB $F400 ; finally write the value 0x22 to the address 0x13F4000

 

For example writing address 0x13F400 with value 0x1234 (int)

LDD #$1234 ; prepare value to be written

LDAA #$13 ; prepare gpage of buffer ram and write it to

STAA $10  ; gpage register

GSTD $F400 ; finally write the value 0x22 to the address 0x13F4000

 

 

Hmmmmm, please read carefully reference manual and examples.

 

BTW, currently my access is limited up to May 12 because of vacation.

 

Best regards,

Ladislav

 

 

 

 

0 Kudos
Reply

2,810 Views
roberthiebert
Senior Contributor I

Hi Ladislav,

I downloaded and installed the EEE calculator, but the application won't run. I was able to read some of the the included files and gather from that the calculator is supposed to allow the user to balance the number of writes to EEPROM with the expected working life of the chip.

The program I am working with has about 2.5Kb of configurable constants that need to have the option of being changed, but not all at once. As the program is being used, the need of change will fall to almost zero, most likely within the space of several hundred operations.

What I don't know is, if, let's say, 10 words are changed at one time, does the whole D-Flash have to be updated, or just the 10 words that were changed?

This would be the typical sequence of changes. A few words here and there. Then nothing, then a few more words in a different area, and so on.

I think the point I am trying to make is that I have to have at least 2.5Kb of Buffer Ram available as EEE without having to change and limit my program.

Obviously it is easier for me to be able to use just the 2Kb available from $0800 to $0FFF, but if this is not practical than I will just have to learn how to use the global addressing procedure.

Oh, I must say again, my knowledge is indeed only very basic. I am not an engineer, or even a technologist. I am just a hobbyist with no formal training, learning what I can, as I go.

Thanks again for your patience.

Regards,

Robert

0 Kudos
Reply

2,773 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

If you do not want to use DFLASH for another purpose so direct access is not required then the simplest approach is to use full partition when entire buffer RAM uses entire DFLASH.

Of course the les buffer RAM used the more updates so if you want you can think about different partition…and use remaining DFLASH for another purpose….see excel file attached.

 

There is an internal EE emulation machine with its logic inside the MCU  which ensures the only necessary DFLASH parts are updated when there is change in the buffer RAM. The most important from your side is to be sure the flag which inform that all data from buffer RAM were written into DFLASH is set… so none of the data is waiting in buffer for update.

 

There is no 2KB (capital B) local space you can use.  However you wrote 25Kb (lowercase b). Do you really mean 2.5 Kilo bits.

For 2.5 kb, meant 320 Bytes, you really can  use only local (direct ) addressing in the space 0xC00~0xFFF  (1KB size)

 

Of course, this consideration nothing changes on the simpliest approach to use fulll buffer RAM on full DFlash.

 

However, if you mean 2.5KB (Kilo Bytes) then you can should use global addressing mode for variables out of local addressing space of the buffer RAM or you can use global addressing for entire buffer RAM space to do not use two types of addressing.

 

Best regards,

Ladislav

0 Kudos
Reply

2,746 Views
roberthiebert
Senior Contributor I

Hi Ladislav,

Sorry about the confusion as to how much buffer RAM I require.

I do not need to use any of the DFLASH for any other purpose so I have been able to successfully do a full partition on the chip I am working with.

Using your example code I was also able to write values to the buffer RAM at global address $13_F000 to $13_FFFF, using Global Store instructions. I was also able to read the values in buffer RAM using the global read instructions.

So far, so good, but I've got a problem that I cant quite figure out yet.

I have an array of default values in PFlash starting at address $4000. I want to copy them to buffer RAM using indexed addressing. I will also need to read them using indexed addressing when I have them in my main program.

I am OK with indexed addressing to get the values from the array in PFlash, but I don know how to increment the global address in Buffer RAM. I am studying the manuals, but so far I haven't been able to figure it out. 

Here is the test code snippet I am using now:

;***********************************************************************************



; - EEE_F: is the beginning of the array of default buffer Ram values

; stored in P Flash starting at address $4000



; ORG RAMStart ; Address $2000

 

; EEEOffset: ds 2 ; Offset from beginning of default buffer Ram values in P-Flash

; EEECnt: ds 2 ; Counter for EEEOffset



;***********************************************************************************



movw #$0006,EEECnt ; initialize EEECnt to 6

movw #$0000,EEEOffset ; Initialize offset to zero

ldaa #$13 ; $13 -> Accu A

staa GPAGE ; Copy to GPAGE

 

EEELoop:

ldd #EEE_F ; Address of start of EEE_F values in P-Flash

ldx EEEOffset ; Offset -> X

ldy D,X ; Value in EEE_F values in P-Flash, offset EEEOffset -> Y

gsty $F000 ; Copy to Global address $13_F000:$13_F001

ldx EEECnt ; EEECnt -> X

subx #1 ; Subtract 1

stx EEECnt ; Update EEECnt

beq EEELoopDone ; If EEECnt = zero branch to EEELoopDone: (Finished)



ldx EEEOffset ; EEEOffset -> X

addx #2 ; Add decimal 2 (increment by two for next word)

stx EEEOffset ; Update EEEOffset

bra EEELoop ; Loop back for next value

 

EEELoopDone:



;***********************************************************************************



Obviously this just keeps replacing the value at $13_F000 with the next value in the PFlash array . I have to figure out how to increment the buffer RAM address.

I realize you are away on holidays until the 12th, so I'll keep working on it. Have a good holiday

Regards,

Robert

 

0 Kudos
Reply

2,651 Views
roberthiebert
Senior Contributor I

Hi Ladislav,

I've been working away at this and it looks like my problem is that I just don't know how to use indexed addressing with the global address in Buffer Ram. Here is a snippet of my latest test code attempt:

;**************************************************************************************
; - This code reads the 4 words in unpaged Flash starting at address $4000, and writes 
;   to Buffer Ram for EE emulation starting at global address 13_F000
;   BUT IT DOESN'T WORK !!!
;**************************************************************************************
;**************************************************************************************
;--------------------------------------------------------------------------------------
; - DefaultBufRam: is the beginning of the array of default buffer Ram values
;   stored in P Flash starting at address $4000
 
;            ORG   $4000  ; Unpaged Flash Sector 1, $4000 to $43FF (1024 bytes)
 
;DefaultBufRam:
;    dc.w $0123,$4567,$89AB,$CDEF
;--------------------------------------------------------------------------------------
; - These are the variables used in this test code
 
;            ORG RAMStart   ; Address $2000 (Start of RAM)  
 
;    EEEOffset:   ds 2  ; Offset value for EEE Buffer Ram
;    EEECnt:      ds 2  ; Counter for EEEOffset
;    EEEAddress:  ds 2  ; 16 byte EEE address
;--------------------------------------------------------------------------------------
;**************************************************************************************
 
;    lbra   EEELoopDone       ; SKIP OVER THIS CODE IF UN-COMMENTED 
 
    movw   #$0004,EEECnt     ; initialize EEECnt to 4
    movw   #$0000,EEEOffset  ; Initialize offset to zero
    movw   #$F000,EEEAddress ; Initialize EEEAddress to $F000
ldaa   #$13              ; $13 -> Accu A
staa   GPAGE             ; Copy to GPAGE
 
EEELoop:
ldd   #DefaultBufRam     ; Address of start of DefaultBufRam values in P-Flash  -> Accu D
    ldx   EEEOffset          ; Offset -> X
    ldy   D,X                ; Value in DefaultBufRam values in P-Flash, offset in EEEOffset -> Y  
    gsty  EEEAddress         ; Copy to Global address    ;( THIS COMMAND DOESN'T CHANGE        ; ;ANYTHING IN BUFFER RAM !!! )          
ldx   EEECnt             ; EEECnt -> X
subx  #1                 ; Subtract 1
stx   EEECnt             ; Update EEECnt
beq   EEELoopDone        ; If EEECnt = zero branch to EEELoopDone: (Finished) 
 
    ldx   EEEOffset          ; EEEOffset -> X
    addx  #2                 ; Add decimal 2 (increment by two for next word to write to Buffer Ram)
    stx   EEEOffset          ; Update EEEOffset
    ldx   EEEAddress         ; EEEAddress -> X
    addx  #2                 ; Add decimal 2 (increment by two for next addrress to write to Buffer ;Ram)
    stx   EEEAddress         ; Update EEEAddress
bra   EEELoop            ; Loop back for next word value
 
EEELoopDone:
 
;**************************************************************************************
 
When I step through it the registers and variables update as expected, but the global store command won't do anything.
 
I'll keep working on it.
 
Regards,
Robert
0 Kudos
Reply

2,467 Views
roberthiebert
Senior Contributor I

I'm afraid I'm still stuck here.

I've been studying the MC9S12XEP100RMV1 manual, the S12XCPUV2 manual, the CW_Assembler_HC12_RM manual, the AN3490 application note, the AN3743 application note and sample code in EEC answer.zip. 

So far I am still unable to figure out how to write to and read from Global buffer RAM from 13_F000 to 13_FFFF in absolute assembler, using indexed addressing.

If anyone can point me to a code example of this it would be greatly appreciated.

Regards,

Robert

0 Kudos
Reply