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.

C24xx compiler / linker array placement

Dear Forum members:

I am attempting to allocate a large number of multidimential arrays. These arrays need to be located in identical places among several different programs running at different times.

I am using CCS DSK 2.12.00 and the F2407 uController.

I have used pragma directives to attempt to locate an array thus:

#pragma DATA_SECTION(cursor_positions,".mysect1")

unsigned int cursor_positions[2][40];

then in my linker command file:

MEMORY { page 1 : my_area : origin = 0300h , length = 80 } SECTIONS { .mysect1 : load = my_area page 1 }

This works as long as the last few bits of the address are zero. If I attempt to allocate at 0301h for example, I get a "cannot alloocate" error message from the linker.

I assume this has something to do with the method the compiler uses to access the array and needs the array to start on some kind of even boundry.

Is there a way of telling the compiler to use a different method to access the array, and also to force the linker to comply with my odd request.

I have thought of rewriting the program to calculate offsets of pointers to access the array, then it is only a matter of reserving the space, but I would rather not do that.

Thanks for any help,

Mark Morenz

  • Hello Mark

    Can you tell us precisely what error message you get.

    It might be too obvious but anyhow: if you attempt to allocate at 0301h, than my_area memory block could overlap with the next one from 380h to 3FFh. (if I remember correctly 80h is the length of one page on 24xx CPU, and you have two DARAM blocks from 200h to 3FFh)

    What is the reason that you would want to allocate the array on odd address? From my knowledge the compiler generates more compact code if arrays are placed on even address, especially if the array is aligned at page boundary

    Regards, Mitja

  • Mitja:

    Thanks for taking the time to look at this.

    The error message is simply "Can't allocate .mysect1 in my_area."

    And I did verify the areas don't overlap.

    The reason I am doing this is because The code I want to place in the 2407 is too large to fit totally in internal flash. So, We have added an external flash device and I am placing some code there. I have written an overlay manager to get small routines to/from the external flash.

    The code must be compiled in 2 parts. Part one handles storing those overlay routines, the other part is the program that uses those routines.

    Both parts must think the memory variables are in the same place so the compiler creates proper code to access them.

    There is much more to the problem as any routines that are called from the overlay code must also be in the same place, but that is a different discussion.

    We are using the 2407 because it has the Code Security Module, and the external code is encrypted. (Only the first part has the encryption algorithm.)

    I have created an excel spreadsheet that mentions every variable that is not located on the stack. I wrote an external program that creates a C routine that declares all variables (with the pragmas) and the linker CMD file.

    So, basically, I am circumventing the linker automatic variable variable placement. (The hard way I might add.)

    I am hoping someone may have a better way to handle overlay code.

    Thanks, Mark.

  • Hi Mark I can tell you that you are not the only one with problems allocating the code within 2407 internal flash. Given all your work already invested in this workaround, I am not sure if it makes sense to change the way to overlay code. One thing that comes to mind (and I never tried it) is to check the CCS project dependencies feature(dependecies between various projects) and if this might be the way to go. Have you tried allocating the array on any different addresses (e.g. 302, 304, 308, ...) and what is the compiler output? Regards, Mitja