Hi.
I'm working in a personal project using uC MC9S12XEP100 and external RAM CY7C1041GN.
I think I setup up all registers correctly because I can read from and write to the memory correctly.
Here a brief of my hardware:
- uC: MC9S12XEP100 144-LQFB
- Ext. RAM: CY7C1041GN Static RAM 4Mb / 512KB
- ADDR [18:1] / !UDS
- !CS1 as Enable Signal
My registers' values:
// EBICTL0
EBICTL0_ASIZ = 0b10011; // External Address Bus Size : 10011 -> ADDR[18:1], UDS'
EBICTL0_HDBE = 1; // High Data Byte Enable - UDS' e LDS' signals : 0 Disabled / 1 Enabled
EBICTL0_ITHRS = 0; // Reduced Input Threshold : 0 5V / 1 3V3
// EBICTL1
EBICTL1_EXSTR0 = 0b000; // External Access Stretch Option 0
EBICTL1_EXSTR_10 = 0b000; // External Access Stretch Option 1
// MMCCTL0
MMCCTL0_CS0E = 0b00; // Chip Select 0 Enables : 00 -> Disabled / 01, 10 or 11 -> Enabled
MMCCTL0_CS1E = 0b01; // Chip Select 1 Enables : 00 -> Disabled / 01, 10 or 11 -> Enabled
MMCCTL0_CS2E = 0b00; // Chip Select 2 Enables : 00 -> Disabled / 01, 10 or 11 -> Enabled
MMCCTL0_CS3E = 0b00; // Chip Select 3 Enables : 00 -> Disabled / 01, 10 or 11 -> Enabled
// MMCCTL1
MMCCTL1_ROMON = 0b1; // Enable FLASH or ROM in the memory map
MMCCTL1_ROMHM = 0b0; // FLASH or ROM only in higher Half of Memory Map : 1 -> Accesses to 0x4000-0x7FFF will be mapped to 0x14_4000-0x14_7FFF in the global memory space (external access).
MMCCTL1_EROMON = 0b1; // Enables emulated Flash or ROM memory in the memory map : 0 - Disable / 1 - Enable
MMCCTL1_RAMHM = 0b0; // RAM only in higher Half of the memory map : 1 Accesses to $4000-$7FFF will be mapped to $0F_C000-$0F_FFFF in the global memory space (RAM area)
MMCCTL1_PGMIFRON = 0b0; // Program IFR visible in the memory map : 0 Not Visible / 1 Visible
MMCCTL1_EEEIFRON = 0b0; // EEE IFR visible in the memory map : 0 Not Visible / 1 Visible
MMCCTL1_TGMRAMON = 0b0; // EEE Tag RAM and FTM SCRATCH RAM visible in the memory map : 0 Not Visible / 1 Visible
// MODE
MODE_MODx = 0b101; // MODC MODB MODA : 101 -> Normal Expanded
To read/write the memory, I made something like that:
// Byte access
byte *far externalAddress = (byte *far)0x200000;
externalAddress[0] = value;
value = externalAddress[0];
// as well as word access
word *far externalAddress = (word *far)0x200000;
externalAddress[0] = value;
value = externalAddress[0];
The image below show a log of access to some addresses in the external memory.
Access to External RAM
However, I can't execute code which I stored in the external memory.
I wrote "by hand" this assembly code and opcode values which oscillate the PTH0 pin.
/*
1C 02 62 01 BSET _DDRH,#1
1C 02 60 01 BSET _PTH,#1
1D 02 60 01 BCLR _PTH,#1
20 F6 BRA *-8 ;abs = 0004
*/
externalRAM[0] = 0x1C;
externalRAM[1] = 0x02;
externalRAM[2] = 0x62;
externalRAM[3] = 0x01;
externalRAM[4] = 0x1C;
externalRAM[5] = 0x02;
externalRAM[6] = 0x60;
externalRAM[7] = 0x01;
externalRAM[8] = 0x1D;
externalRAM[9] = 0x02;
externalRAM[10] = 0x60;
externalRAM[11] = 0x01;
externalRAM[12] = 0x20;
externalRAM[13] = 0xF6;
So, I created a function pointer type in order to try calling this "function" and tried many ways to go there:
// Function pointer type
typedef void (*far funcVoid)(void);
// Global address
funcVoid funcOsc @ 0x200000L;
// Local address
funcVoid addrFunc = (funcVoid)0x200000;
// ... and these calls (one at a time)
asm {
call 0, $20
}
((funcaoVoid)externalRAM)();
addrFunc();
funcOsc();
But all these call interrupt the execution and no access to external RAM appears in the oscilloscope lines.
I made the it a time in the past using 9S12DP512, but there the external RAM wasn't paged and a simple call to any address from 0x4000-7FFF generated access to it.
How can execute code in the external RAM with paged memory?
I noticed that @lama answer many questions about external memory. Can you or anyone help me with this problem?
Thanks in advance.