Hi Neil
I don't have an example of this and haven't done it as such, but I think that the following will be close (you may have to do a bit of debugging to get it all right though).
1) I think that the interrupt vectors should be left in SRAM and also the stack should be left there. This means that in the linker can be left as it it in terms of SRAM define but needs a further RAM define.
MEMORY
{
flash (RX) : ORIGIN = 0x00001000, LENGTH = 0x0003F000 /* 4k reserved for SPI FLASH boot loader */
vectorram(RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000400
sram (RWX) : ORIGIN = 0x20000400, LENGTH = 0x00007C00
ram (RWX) : ORIGIN = 0x??, LENGTH = ?? <- fill in as required
ipsbar (RWX) : ORIGIN = 0x40000000, LENGTH = 0x0
}2)
You must ensure that the variables are placed in RAM and not SRAM:
.data : AT(___DATA_ROM)
{
___DATA_RAM = . ;
*(.exception)
. = ALIGN(0x10);
__exception_table_start__ = .;
EXCEPTION
__exception_table_end__ = .;
___sinit__ = .;
STATICINIT
*(.data)
. = ALIGN (0x10);
___DATA_END = .;
__START_SDATA = .;
*(.sdata)
. = ALIGN (0x10);
__END_SDATA = .;
__SDA_BASE = .;
. = ALIGN(0x10);
} > sramHere you see that
.sdata and
.data are being put to SRAM. I am not sure of the difference but there needs to be moved to a new
ram block added which accept these instead.
3) The variable need to be initialised
AFTER the memory controller has been configured. The variables are initialised in
mcf52235_init() so you will need to put the memory controller initialisation in there and then ensure that the initialisation (below) does correctly use the external RAM addresses.
if (__DATA_ROM != __DATA_RAM) { // move initialized data from ROM to RAM.
dp = (unsigned char *)__DATA_RAM;
sp = (unsigned char *)__DATA_ROM;
n = (unsigned long)(__DATA_END - __DATA_RAM);
while (n--) {
*dp++ = *sp++;
}
}
if (__BSS_START != __BSS_END) { // zero uninitialised data
sp = (unsigned char *)__BSS_START;
n = (unsigned long)(__BSS_END - __BSS_START);
while (n--) {
*sp++ = 0;
}
}4) The LAN buffers, serial buffers, OS queues etc. are put on heap and it seems sensible to keep this also in SRAM.
Heap is defined to stretch from the last variable up to the stack pointer. This need to be changed though since the last variable is now in external RAM. To do this you will need to modify the following lines of code in
m5223x.c.
Original:
extern unsigned char __HEAP_END;
#define HEAP_START_ADDRESS &__HEAP_END
The heap start location can be positioned directly after the interrupt vectors. I think that the following may be the location: __exception_table_end__ (see linker script). You may also be able to set a fixed address if this is not correctly automated ((unsigned char *)0x20000400). However also be careful that the USB controller may be using some extra memory there (see the USB user's guide http://www.utasker.com/docs/uTasker/USB_User_Guide.PDF - appendix A for details). It would mean that it is 0x20000480 instead.
I think that that is about all that is needed but there may be a surprise somewhere(?). To check it with the debugger these are the general steps:
1. Ensure that the memory controller is correctly initialised very early on (before variable initialisation).
2. Ensure that the variables are correctly initialised (the BSS section must be set to 0 and other variables copied from their FLASH init values to RAM).
3. Check that the heap is being set to the correct area (from teh end of the interrupt vectors (or USB) to the stack pointer (which should also be at the top of internal SRAM).
Can't think of anything else at the moment. Good luck!
Regards
Mark