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.

CCS/TMS320F28335: Different behavior from RAM to Flash on TMS320F28335

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hi,

I've a problem with a custom design used from two years ago in our company to control stepper motors.

We've enhanced the characteristics of the system and now the behavior of the algorithm from RAM emulation and flash programmed emulation is different.

Sometimes the system jump to Illegal ISR and sometimes don't run the code in right way.

The F28335.cmd and 28335_RAM_lnk.cmd has not changed and the compiler and linker don't tell anything wrong. All is correct.

Can anyone explain how to identify the problem? Till now I don't need to look the stack to understand from where to where the controller was jumping, identify memory allocations, etc.

I don't know how to move or allocate sections of the program on the memory.

The modified part of the  28335_RAM_lnk.cmd is this :

RAML0      : origin = 0x008000, length = 0x000100
RAML1      : origin = 0x008100, length = 0x003F00 
RAML2      : origin = 0x00D000, length = 0x000500
RAML3      : origin = 0x00E000, length = 0x001000

And the modified part on the F28335.cmd is this:

RAML0       : origin = 0x008000, length = 0x001000
RAML1      : origin = 0x009000, length = 0x002000
RAML2      : origin = 0x00B000, length = 0x001000
RAML3      : origin = 0x00C000, length = 0x001000

On this two files the rest is the original configuration.

Thanks.

  • Fermin,

    Thanks for reaching out to the forum.

    Is the 28335_RAM_lnk.cmd the original linker file and the 28335.cmd the new file that shows issues?  

    Can you also share the later parts of the linker files, where you have assigned sections to these locations?  This will help narrow down what might be in conflict new to old.

    Best,
    Matthew

  • Hi Mathew,

    here the 28335_RAM_lnk.cmd

    MEMORY
    {
    PAGE 0 :
       /* BEGIN is used for the "boot to SARAM" bootloader mode      */

       BEGIN      : origin = 0x000000, length = 0x000002     /* Boot to M0 will go here                      */
       RAMM0      : origin = 0x000050, length = 0x0003B0
       RAML0      : origin = 0x008000, length = 0x000100
       RAML1      : origin = 0x008100, length = 0x003F00

       RAML2      : origin = 0x00D000, length = 0x000500
       RAML3      : origin = 0x00E000, length = 0x001000    //160704  Origin era D000

       ZONE7A     : origin = 0x200000, length = 0x00FC00    /* XINTF zone 7 - program space */
       CSM_RSVD   : origin = 0x33FF80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
       CSM_PWL    : origin = 0x33FFF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA            */
       ADC_CAL    : origin = 0x380080, length = 0x000009
       RESET      : origin = 0x3FFFC0, length = 0x000002
       IQTABLES   : origin = 0x3FE000, length = 0x000b50
       IQTABLES2  : origin = 0x3FEB50, length = 0x00008c
       FPUTABLES  : origin = 0x3FEBDC, length = 0x0006A0
       BOOTROM    : origin = 0x3FF27C, length = 0x000D44


    PAGE 1 :
       /* BOOT_RSVD is used by the boot ROM for stack.               */
       /* This section is only reserved to keep the BOOT ROM from    */
       /* corrupting this area during the debug process              */

       BOOT_RSVD  : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
       RAMM1      : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
       RAML4      : origin = 0x00C000, length = 0x001000
       RAML5      : origin = 0x00D000, length = 0x001000
       RAML6      : origin = 0x00E000, length = 0x001000
       RAML7      : origin = 0x00F000, length = 0x001000
       ZONE7B     : origin = 0x20FC00, length = 0x000400     /* XINTF zone 7 - data space */
    }


    SECTIONS
    {
       /* Setup for "boot to SARAM" mode:
          The codestart section (found in DSP28_CodeStartBranch.asm)
          re-directs execution to the start of user code.  */
       codestart        : > BEGIN,     PAGE = 0
       ramfuncs         : > RAML0,     PAGE = 0
       .text            : > RAML1,     PAGE = 0
       .cinit           : > RAML0,     PAGE = 0
       .pinit           : > RAML0,     PAGE = 0
       .switch          : > RAML0,     PAGE = 0

       .stack           : > RAMM1,     PAGE = 1
       .ebss            : > RAML4,     PAGE = 1
       .econst          : > RAML5,     PAGE = 1
       .esysmem         : > RAMM1,     PAGE = 1

       IQmath           : > RAML1,     PAGE = 0
       IQmathTables     : > IQTABLES,  PAGE = 0, TYPE = NOLOAD

       /* Uncomment the section below if calling the IQNexp() or IQexp()
          functions from the IQMath.lib library in order to utilize the
          relevant IQ Math table in Boot ROM (This saves space and Boot ROM
          is 1 wait-state). If this section is not uncommented, IQmathTables2
          will be loaded into other memory (SARAM, Flash, etc.) and will take
          up space, but 0 wait-state is possible.
       */
       /*
       IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
       {

                  IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)

       }
       */

       FPUmathTables    : > FPUTABLES, PAGE = 0, TYPE = NOLOAD

       DMARAML4         : > RAML4,     PAGE = 1
       DMARAML5         : > RAML5,     PAGE = 1
       DMARAML6         : > RAML6,     PAGE = 1
       DMARAML7         : > RAML7,     PAGE = 1

       ZONE7DATA        : > ZONE7B,    PAGE = 1

       .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used                    */
       csm_rsvd         : > CSM_RSVD   PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
       csmpasswds       : > CSM_PWL    PAGE = 0, TYPE = DSECT /* not used for SARAM examples */

       /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
       .adc_cal     : load = ADC_CAL,   PAGE = 0, TYPE = NOLOAD

    }

    And F28335.cmd

    MEMORY
    {
    PAGE 0:    /* Program Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */

       ZONE0       : origin = 0x004000, length = 0x001000     /* XINTF zone 0 */
       RAML0       : origin = 0x008000, length = 0x001000     /* on-chip RAM block L0 *
       RAML1       : origin = 0x009000, length = 0x002000    //HE AñADIDO ESPACIO PARA LAS VARIABLES QUE GUARDA EN LA ZONA .text
       RAML2       : origin = 0x00B000, length = 0x001000    //PARA QUE PUEDA COMPILARe
       RAML3       : origin = 0x00C000, length = 0x001000
       
       ZONE6       : origin = 0x0100000, length = 0x100000    /* XINTF zone 6 */
       ZONE7A      : origin = 0x0200000, length = 0x00FC00    /* XINTF zone 7 - program space */
       FLASHH      : origin = 0x300000, length = 0x008000     /* on-chip FLASH */
       FLASHG      : origin = 0x308000, length = 0x008000     /* on-chip FLASH */
       FLASHF      : origin = 0x310000, length = 0x008000     /* on-chip FLASH */
       FLASHE      : origin = 0x318000, length = 0x008000     /* on-chip FLASH */
       FLASHD      : origin = 0x320000, length = 0x008000     /* on-chip FLASH */
       FLASHC      : origin = 0x328000, length = 0x008000     /* on-chip FLASH */
       FLASHA      : origin = 0x338000, length = 0x007F80     /* on-chip FLASH */
       CSM_RSVD    : origin = 0x33FF80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
       BEGIN       : origin = 0x33FFF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
       CSM_PWL     : origin = 0x33FFF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */
       OTP         : origin = 0x380400, length = 0x000400     /* on-chip OTP */
       ADC_CAL     : origin = 0x380080, length = 0x000009     /* ADC_cal function in Reserved memory */
       
       IQTABLES    : origin = 0x3FE000, length = 0x000b50     /* IQ Math Tables in Boot ROM */
       IQTABLES2   : origin = 0x3FEB50, length = 0x00008c     /* IQ Math Tables in Boot ROM */  
       FPUTABLES   : origin = 0x3FEBDC, length = 0x0006A0     /* FPU Tables in Boot ROM */
       ROM         : origin = 0x3FF27C, length = 0x000D44     /* Boot ROM */        
       RESET       : origin = 0x3FFFC0, length = 0x000002     /* part of boot ROM  */
       VECTORS     : origin = 0x3FFFC2, length = 0x00003E     /* part of boot ROM  */

    PAGE 1 :   /* Data Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
               /* Registers remain on PAGE1                                                  */
       
       BOOT_RSVD   : origin = 0x000000, length = 0x000050     /* Part of M0, BOOT rom will use this for stack */
       RAMM0       : origin = 0x000050, length = 0x0003B0     /* on-chip RAM block M0 */
       RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
       RAML4       : origin = 0x00C000, length = 0x001000     /* on-chip RAM block L1 */
       RAML5       : origin = 0x00D000, length = 0x001000     /* on-chip RAM block L1 */
       RAML6       : origin = 0x00E000, length = 0x001000     /* on-chip RAM block L1 */
       RAML7       : origin = 0x00F000, length = 0x001000     /* on-chip RAM block L1 */
       ZONE7B      : origin = 0x20FC00, length = 0x000400     /* XINTF zone 7 - data space */
       FLASHB      : origin = 0x330000, length = 0x008000     /* on-chip FLASH */
    }

    /* Allocate sections to memory blocks.
       Note:
             codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code
                       execution when booting to flash
             ramfuncs  user defined section to store functions that will be copied from Flash into RAM
    */
     
    SECTIONS
    {
     
       /* Allocate program areas: */
       .cinit              : > FLASHA      PAGE = 0
       .pinit              : > FLASHA,     PAGE = 0
       .text               : > FLASHA      PAGE = 0
       codestart           : > BEGIN       PAGE = 0
       ramfuncs            : LOAD = FLASHD,
                             RUN = RAML0,
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             PAGE = 0

       csmpasswds          : > CSM_PWL     PAGE = 0
       csm_rsvd            : > CSM_RSVD    PAGE = 0
       
       /* Allocate uninitalized data sections: */
       .stack              : > RAMM1       PAGE = 1
       .ebss               : > RAML4       PAGE = 1
       .esysmem            : > RAMM1       PAGE = 1

       /* Initalized sections go in Flash */
       /* For SDFlash to program these, they must be allocated to page 0 */
       .econst             : > FLASHA      PAGE = 0
       .switch             : > FLASHA      PAGE = 0      

       /* Allocate IQ math areas: */
       IQmath              : > FLASHC      PAGE = 0                  /* Math Code */
       IQmathTables     : > IQTABLES,  PAGE = 0, TYPE = NOLOAD
       
       /* Uncomment the section below if calling the IQNexp() or IQexp()
          functions from the IQMath.lib library in order to utilize the
          relevant IQ Math table in Boot ROM (This saves space and Boot ROM
          is 1 wait-state). If this section is not uncommented, IQmathTables2
          will be loaded into other memory (SARAM, Flash, etc.) and will take
          up space, but 0 wait-state is possible.
       */
       /*
       IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
       {
       
                  IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)
       
       }
       */
       
       FPUmathTables    : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
             
       /* Allocate DMA-accessible RAM sections: */
       DMARAML4         : > RAML4,     PAGE = 1
       DMARAML5         : > RAML5,     PAGE = 1
       DMARAML6         : > RAML6,     PAGE = 1
       DMARAML7         : > RAML7,     PAGE = 1
       
       /* Allocate 0x400 of XINTF Zone 7 to storing data */
       ZONE7DATA        : > ZONE7B,    PAGE = 1

       /* .reset is a standard section used by the compiler.  It contains the */
       /* the address of the start of _c_int00 for C Code.   /*
       /* When using the boot ROM this section and the CPU vector */
       /* table is not needed.  Thus the default type is set here to  */
       /* DSECT  */
       .reset              : > RESET,      PAGE = 0, TYPE = DSECT
       vectors             : > VECTORS     PAGE = 0, TYPE = DSECT
       
       /* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
       .adc_cal     : load = ADC_CAL,   PAGE = 0, TYPE = NOLOAD

    }

    Regards.

  • I see in RAM_lnk.cmd that the space defined as RAML0 (0x8000 len = 0x100), it allocated to RAMFUNCs;

    Is it possible this space is dynamic, i.e. that other code tries to copy functions here, vs loading?  The space immediately after this is RAML1, which is allocated to .text which is the bulk of the program code.

    Any write to the RAML0 space that exceeds the 0x100 words would over-write the main program in RAML1 which could result in ITRAP/ code mis-behaivor.

    For the non-RAM I see that the RAM at 0xC000 is mapped to both the .ebss and DMARAML4.  I would try remvoving it from DMARAML4 to make sure the DMA isn't overwriting this section.

    Best,
    Matthew

  • Hi Matthew,

    I've corrected the code following your advices but now I can't compile because I don't have enough space for the .text section.

    How can I debug without to put the .text section on RAM? And related, how can I fit big size code on flash if the sections are "small"?

    I'm reading a lot of your workshops and I don't find how to do this.

    Regards.

  • For the RAM version it looks like RAML2 is not being used; you could just add that value to the declaration of RAML1 where your text is going.

    For the flash compile, there's no reason you can't execute from flash, it will just be slower(due to waitstates I beleive it is 3WS at 150MHz) that execution out of RAM(no waitstates). 

    For this device the IQ Math tables are in ROM, so you can just map them there(I see a comment section in the linker already for this) and free up more RAML1.  ROM is 1WS, so there is a penatly vs RAM if that is important.

    We typically recommend placing the time critical code in SRAM(usually ISRs) and leaving other things in Flash. 

    Let me know if with the above we can get things to fit.

    Best,
    Matthew

  • Hi Matthew,

    I think finally I've solved my problems... with your help and studying a little!

    Using your Lab 10 example from your Delfino Workshop (F28xDmdw, Revision 8.1, November 2010) as base I've modified all my configurations and now works.

    1.-  I've simplified my cmd file and increased the space for ADC_CAL 0x09 to 0x10 

    2.-  I've inserted all the projects files inside the project folders to compile without problems searching general definitions, tables, etc.

    3.-  I've assigned all my important (ISR) functions to RAM to serve as fast as possible using  #pragma CODE_SECTION (ADCINT_ISR, "ramfuncs")

    Now, all is working and every time with the same results.

    Thanks.

    LNK_FLASH_DSD_1-0.cmd

    MEMORY
    {
    PAGE 0:    /* Program Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */

       BEGIN_M0        : origin = 0x000000, length = 0x000002     /* Part of M0SARAM.  Used for "Boot to M0" bootloader mode. */

       L0123SARAM      : origin = 0x008000, length = 0x004000     /* SARAM, L0 through L3 combined.  CSM secure */

       FLASH_ABCDEFGH  : origin = 0x300000, length = 0x03FF80     /* On-chip FLASH */

       CSM_RSVD        : origin = 0x33FF80, length = 0x000076     /* Part of FLASH Sector A.  Reserved when CSM is in use. */

       BEGIN_FLASH : origin = 0x33FFF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
       PASSWORDS   : origin = 0x33FFF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */

       ADC_CAL     : origin = 0x380080, length = 0x000010     /* ADC_cal function in Reserved memory ENLARGED the length from 0x09 to 0x10*/
       OTP         : origin = 0x380400, length = 0x000400     /* on-chip OTP */
       
       IQTABLES    : origin = 0x3FE000, length = 0x000B50     /* IQ Math Tables in Boot ROM */
       IQTABLES2   : origin = 0x3FEB50, length = 0x00008C     /* IQ Math Tables in Boot ROM */
       FPUTABLES   : origin = 0x3FEBDC, length = 0x0006A0     /* FPU Tables in Boot ROM */

       BOOTROM     : origin = 0x3FF27C, length = 0x000D44     /* Boot ROM */
       RESET       : origin = 0x3FFFC0, length = 0x000002     /* part of boot ROM  */
       VECTORS     : origin = 0x3FFFC2, length = 0x00003E     /* part of boot ROM  */


    PAGE 1 :   /* Data Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
               /* Registers remain on PAGE1                                                  */
       
       M0SARAM     : origin = 0x000002, length = 0x0003FE     /* 1Kw M0 SARAM */
       M1SARAM     : origin = 0x000400, length = 0x000400     /* 1Kw M1 SARAM */
       L4SARAM     : origin = 0x00C000, length = 0x001000     /* 4Kw L4 SARAM, DMA accessible */
       L5SARAM     : origin = 0x00D000, length = 0x001000     /* 4Kw L5 SARAM, DMA accessible */
       L6SARAM     : origin = 0x00E000, length = 0x001000     /* 4Kw L6 SARAM, DMA accessible, 1 WS prog access */
       L7SARAM     : origin = 0x00F000, length = 0x001000     /* 4Kw L7 SARAM, DMA accessible 1 WS prog access */

    }


     
    SECTIONS
    {
     
       /* Allocate program areas: */
       .text        : > FLASH_ABCDEFGH,          PAGE = 0
       .cinit       : > FLASH_ABCDEFGH,          PAGE = 0
       .const       : > FLASH_ABCDEFGH,            PAGE = 0
       .econst      : > FLASH_ABCDEFGH,            PAGE = 0
       .pinit       : > FLASH_ABCDEFGH,            PAGE = 0
       .switch      : > FLASH_ABCDEFGH,          PAGE = 0
       .reset       : > RESET,                     PAGE = 0, TYPE = DSECT  /* Not using the .reset section */

       /* Allocate uninitalized data sections: */
       /* Data Memory (PAGE 1) sections */
       .stack       : > M1SARAM                   PAGE = 1
       .cio         : > M0SARAM,                   PAGE = 1
       .stack       : > M1SARAM,                   PAGE = 1
       .ebss        : > L4SARAM                   PAGE = 1
       .bss         : > L4SARAM,                   PAGE = 1
       .esysmem     : > M1SARAM                  PAGE = 1
       .sysmem      : > L4SARAM,                   PAGE = 1
       .cio         : > M0SARAM,                   PAGE = 1


       /*** User Defined Sections ***/
       codestart    : > BEGIN_FLASH               PAGE = 0                /* Used by file CodeStartBranch.asm */
       passwords    : > PASSWORDS                 PAGE = 0
       csm_rsvd     : > CSM_RSVD                PAGE = 0
       dmaMemBufs   : > L4SARAM,                   PAGE = 1

       /* Section RamFuncs used by file Flash.c */
       ramfuncs            : LOAD = FLASH_ABCDEFGH, PAGE = 0                /* Should be Flash */
                             RUN = L0123SARAM,      PAGE = 0                /* Must be CSM secured RAM */
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             LOAD_SIZE(_RamfuncsLoadSize)               


       /* Allocate IQ math areas: */
       IQmathTables         : > IQTABLES,              PAGE = 0, TYPE = NOLOAD
       IQmath                  : > FLASH_ABCDEFGH      PAGE = 0                  /* Math Code */
      
       
       FPUmathTables    : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
             
       /* Allocate DMA-accessible RAM sections: */
       DMAL4SARAM         : > L4SARAM,     PAGE = 1
       DMAL5SARAM         : > L5SARAM,     PAGE = 1
       DMAL6SARAM         : > L6SARAM,     PAGE = 1
       DMAL7SARAM         : > L7SARAM,     PAGE = 1
       

       .reset              : > RESET,      PAGE = 0, TYPE = DSECT
       vectors             : > VECTORS     PAGE = 0, TYPE = DSECT

    }