This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM57L843: Declaring Arrays and Variables in External Memory - EMIF

Part Number: RM57L843


Hi!

I have connected an external memory interface through the EMIF module. Basically, its a DPRAM (4K x 16 bit). Unfortunately, I have missed the pins BA0, BA1 and A0 of controller and directly connected A1 of controller to A0 of DPRAM. 

This hardware error cannot be corrected for now and I have planned to go ahead with this implementation for now.

Now, when I have to declare variables in DPRAM space, I use:

#pragma LOCATION(ui_dummy_variable, 0x64000000)

uint16 ui_dummy_variable;

to allocate the address 0x64000000 to the variable, "ui_dummy_variable" right?

Because of the above hardware error, if I have to increment by next address in DPRAM memory space, then I will have to multiply the address by 8 to generate next sequential address.

#pragma LOCATION(ui_next_dummy_variable, ((0x64000000 + 1) * 8))

uint16 ui_next_dummy_variable;

Therefore, both the variables "ui_dummy_variable" and "ui_next_dummy_variable" are assigned one after the other in the DPRAM space.

The question is, what if I need an array of a particular size?

For instance, if I declare like this:

#pragma LOCATION(ui_dummy_array, ((0x64000000 + 2) * 8))

uint16 ui_dummy_array[4];

Does this allocate memory in the following way in DPRAM:

ui_dummy_array[0] = ((0x64000000 + 2) * 8)) <-- address of ui_dummy_array[0]

ui_dummy_array[0] = ((0x64000000 + 3) * 8))

ui_dummy_array[0] = ((0x64000000 + 4) * 8))

ui_dummy_array[0] = ((0x64000000 + 5) * 8))

If not, then it what way is memory allocated to "ui_dummy_array[4]" in DPRAM?

Please provide some help.

Thanks!

Regards,

Chetan.

  • Sorry for the typo:

    ui_dummy_array[0] = ((0x64000000 + 2) * 8)) <-- address of ui_dummy_array[0]

    ui_dummy_array[1] = ((0x64000000 + 3) * 8))

    ui_dummy_array[2] = ((0x64000000 + 4) * 8))

    ui_dummy_array[3] = ((0x64000000 + 5) * 8))

    *Indices corrected....

  • The EMIF address pin EMIF_A[0] always provides the least significant bit of a 32-bit word address. This is why the EMIF_A[0] is mapped to SRAM_A[1] (16-bit memory), and EMIF_A[1] is mapped to SRAM_A[2].

    If you connect EMIF_A[1] to SRAM_A[0], the address 0x00 (offset) is mapped to first half word of SRAM, and 0x08 is mapped to the 2nd half-word of SRAM.

    EMIF (offset)            SRAM (location of half-word)

    0                               0

    8                               1

    16                              2

    24                              3

    32                              4

    So if you want to write to the nth half-word, the address in your code should be changed to 0x64000000 + n*8

  • Hi Wang!

    I got your point and that is what I guess I typed in my question. Yes, I have to add nth address to base address 0x64000000 and then multiply it with 8.

    What I am asking is about my declaration of array in such external memory space! Let's forget the fact that whether its a SRAM or DPRAM etc. 

    When I am using #pragma LOCATION() and declaring an array of certain size, I want to know the order in which addresses are assigned in external memory? If my array size is huge (say 1K), then I can't keep using #pragma LOCATION for every element of the array, right? 

    Also, is there any other way of syntactically declaring an array in external memory if what I have suggested in my first post is wrong.

    Regards,

    Chetan.

  • Hi Chetan,

    I don't know how to use variable in #pragma location(). 

    You can declare a long variable, but only lower 2-bytes are used, and allocate this variable directly to that memory address.

    #pragma location(x, 0x64000000)

    uint64_t x[200];

    main(){

       x[0] = 0x0000000000005a5b; --> or x[0]=0x5a5b

       x[1] = 0x0000000000006a6b; -->or x[1]=0x6a6b

    ....

    so 0x5a5b will be placed at 0x64000000, and 0x6a6b is placed at 0x64000008

  • Hi Wang!

    Yes, even to me, it seemed that that is the only way! I will try it that way only.

    Thanks,

    Chetan.

  • Dear Wang,

    Generally, how do you declare variables in external memory space if you don't use #pragma LOCATION(). Just curious to know. Do you directly use pointers in that memory space?

    Regards,

    Chetan.

  • Hi Chetan,

    You can put the variables to a data section which is allocated to the external memory:

    #pragma SET_DATA_SECTION(".myRAM")

    uint8 buffer[128]= {0}; 

    uint32 x, y, z;

    #pragma SET_DATA_SECTION()

    Then in linker cmd file, map .myRAM section to external memory

    MEMORY

    {

       ......

       EXT_MEM:  (RW) : origin=0x064000000 length=0x00001000

    }

    SECTIONS

    {

       ....

       .myRAM : {} > EXT_MEM

    }

    So the buffer[], x, y, and z will be placed to the external memory.