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.

Access to EPI external SDRAM in TM4C1294

Hi,

I am working on the custom board based on TM4C1294+lwip1.4.1+freeRTOS+ccs5.5.x(Compiler ti v5.1.9).

After reconfiguring EPI ports to access 8MB Sdram, it worked fine as I tested the example of "sdram.c"

However, As I declared some arrays in .h like below

extern SC_TESTSETUP sctest[NUMCHANS] __attribute__ ((section (".external")));   /* array of setuptest structures */
extern SC_HOLDSTAT  scholdstat[NUMCHANS] __attribute__ ((section (".external")));   /* array of hstat structures */

and accessed to the variables in .c, they still sit address at 0x20000000 around which is not area of the external sdram(0x60000000).

    SC_TESTSETUP sctest[NUMCHANS] ;   /* array of setuptest structures */
    SC_HOLDSTAT  scholdstat[NUMCHANS] ;   /* array of hstat structures */

    memset((char *) sctest,0 ,sizeof(sctest));
    memset((char *) scholdstat,0 ,sizeof(scholdstat));
    
// write values for testing sctest[0].clrbits = 0; sctest[0].numcells = 4; sctest[0].test[0].dcapac = 1;

As I read back the values that I wrote, all values are "0"


Here is my .cmd

/* The starting address of the application.  Normally the interrupt vectors  */
/* must be located at the beginning of the application.                      */
#define APP_BASE 0x00000000
#define RAM_BASE 0x20000000
#define SDRAM_BASE 0x60000000

/* System memory map */

MEMORY
{
    /* Application stored in and executes from internal flash */
    FLASH (RX) : origin = APP_BASE, length = 0x00100000
    /* Application uses internal RAM for data */
    SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    /* Application uses external RAM for large data arrays */
    SDRAM (RWX) : origin = SDRAM_BASE, length = 0x00800000
}

/* Section allocation in memory */

SECTIONS
{
    .intvecs:   > APP_BASE
    .text   :   > FLASH
    .const  :   > FLASH
    .cinit  :   > FLASH
    .pinit  :   > FLASH
    .init_array : > FLASH

    .vtable :   > RAM_BASE
    .data   :   > SRAM
    .bss    :   > SRAM
    .sysmem :   > SRAM
    .stack  :   > SRAM
    .external : > SDRAM
}

__STACK_TOP = __stack + 16384;

I am not sure what's wrong with accessing the external sdram.



Thanks,

Jin

  • I don't know what compiler you are using but that setup looks odd to me. I'd normally expect the placement attribute to be added where the variable was defined. I would expect any attributes defined with an extern to be either ignored or to generate a syntax error(1).

    I'd check the compiler's documentation

    Robert

    1 - It's syntactically correct to have multiple externs for a variable in C/C++ so in the compiler could run into a conflict that could only be detected at link time. You might be able to extend C++ name mangling to protect against this but in C you would end up with multiple copies of the variable to link to, hopefully the linker would complain about that.
  • Hi Robert,

    Thank you for replying to me.

    My complier ver is TI v5.1.9.
    I just declared extern variables once in .h, and defined/initialized them .c once as well. I don't think I have multiple externs for one variable.

    Thanks,
    Jin

  • Sorry Jin, I think you missed by point.

    I think putting the attribute on the extern will not work. It probably should be on the definition in the C file.

    Robert
  • Check your compiler manual for the proper syntax.

    Robert
  • Hello Robert,

    If the read-back and action is not there then can the compiler optimize it!!!!

    Regards
    Amit
  • But Amit, it cannot move an explicitly place variable unless there is a compiler bug. I still think the attribute has been placed in the wrong part of the code makes the most likely explanation.

    Robert
  • Hello Robert,

    Some time back I was looking at a similar issue where the user was foing

    #pragma DATA_SECTION(flash32test,"ParameterSpace")
    #endif
    const uint32_t flash32test=20000;

    test32readout=flash32test;

    and the CCS compiler optimized it.

    By adding a code like

    for(ui32Loop = 0; ui32Loop < test32readout; ui32Loop++)
    {
    }

    it correctly assigned it. Of course that was a preload. So wanted to make sure it is not getting optimized under higher settings of optimization.

    Regards
    Amit
  • I think you are missing something in your example, there is no reason for a loop in it (the meaning of const also changes between C and C++ ;) ).

    And while memset could be in-lined it should still be setting the memory at the location explicitly located. Especially for a global, the compiler gets no "as-if" exceptions in that case. It must assume other modules have access to the memory.

    Conceivably the compiler could set an area of memory and copy it to the final location but that is almost as broken as not placing it as requested.

    Robert
  • I also rather assumed the OP was checking the map file not a debugger, that may be a trifle optimistic of me.

    Robert
  • Hi ,

    I have changed a bit since I could not see any allocated address in .map and go back to original codes that worked on Stellaris version.

    all global vars are declared in one header which is "extern.h"

    extern CHGR_CMD comand[MAX_COMANDS] __attribute__ ((section (".external"))); /* area to hold charger comands */
    extern RAWDAT rawdat[MAX_RAWDAT] __attribute__ ((section (".external")));      /* area to hold raw data */
    extern SC_TESTSETUP chparam[NUMCHANS] __attribute__ ((section (".external")));   /* array of setuptest structures */
    extern SC_HOLDSTAT  stats[NUMCHANS] __attribute__ ((section (".external")));   /* array of hstat structures */
    

    And the variables are defined  in "variables.c"

    CHGR_CMD comand[MAX_COMANDS] ; /* area to hold charger comands */
    RAWDAT rawdat[MAX_RAWDAT] ;      /* area to hold raw data */
    
    SC_TESTSETUP chparam[NUMCHANS] ;   /* array of setuptest structures */
    SC_HOLDSTAT  stats[NUMCHANS] ;   /* array of hstat structures */

    .map according to the above codes

    60000000    60000000    00025880   00000000    rw-
      60000000    60000000    00025880   00000000    rw- .external
    
    .external 
    *          0    60000000    00025880     UNINITIALIZED
                      60000000    00025880     variables.obj (.external)
    
    GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name 
    
    address    name
    --------   ----
    60000000   comand
    60011700   rawdat
    6001f900   chparam
    60025000   stats
    
    

    .map looks fine for me, but as I programmed it using LM Flash it did not even execute.

    Thanks,

    Jin

  • Hi Amit,

    All extern variables are in extern.h and they are defined in variables.c without initialization in my project. The initialization of extern variables are done by a couple of functions .

    In my project, lots of structs are used ,and some of them need to be extern variables. For test "int" type is used instead of own struct variables. I have tried to test with/without "extern" ahead of "attribute directive", in a nutshell both did not work.

    extern int abab[20]; //is declared in episdram.h

    and in episdram.c

    int abab[20]__attribute__ ((section (".external")));

    memset((char *) abab ,0 ,sizeof(abab));

    I do not have any compile errors and can see the address of "abab" variable in .map but nothing works.

    I wonder how the variables that need to be declared as "extern" and stored in "external SDRAM" can be used and how to program them?

    Regards,

    Jin