Author Topic: setting up utasker for external RAM  (Read 10388 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
setting up utasker for external RAM
« on: September 04, 2009, 03:16:31 PM »
Hi Mark,
  I have a 512k ram connected to the mini-flexbus on the 52259. How do I set this up within utasker?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: setting up utasker for external RAM
« Reply #1 on: September 04, 2009, 05:34:18 PM »
Hi Neil

Take a look at the routine fnConfigureBus() in M5223X.c

This is showing how to configure the MRAM on the Kirin3 EVAL board. This may works as it is or it may requires some adjustment for the data bus width, or address you want it to be at within the memory map.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: setting up utasker for external RAM
« Reply #2 on: September 04, 2009, 07:48:09 PM »
Hi Mark,
   Will there be anything required to set in linker file?

Neil


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: setting up utasker for external RAM
« Reply #3 on: September 04, 2009, 08:03:41 PM »
Hi Neil

Whether you need to configure the linker set up depends on whether you want to memory map the extra RAM so that the compiler/linker can access it via symbols. (eg. global variables are positioned there which code can access without knowing their exact addresses).

If the memory is used for other purposes (such as a large struct or array) it can be accessed using pointers (set to point to the RAM's address in memory) and so the linker doesn't need anything.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: setting up utasker for external RAM
« Reply #4 on: September 07, 2009, 09:08:42 PM »
Hi Mark,
  I would like to use it to setup up using symbols, so I would need to include the the linker. How do I do this? I would like ot use ethernet/serial etc  buffers in processor ram, and leave external RAM for other uses, but not sure how to do this.  The device I use is a 10ns part, and connected it the same (it has all same pins) as in dev kit (it is 256k 16bit)

Many Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: setting up utasker for external RAM
« Reply #5 on: September 07, 2009, 10:09:58 PM »
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);
   } > sram



Here 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