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.

TMS320F28335: Program execution time in flash and ram

Part Number: TMS320F28335


Hi community!

I am using a TMS320F28335 for the purpose of a motor control. Would someone please let me know the maximum frequency of the program execution when the whole program is written on flash? Is there any way to move the written program from flash to RAM every time the microcontroller stats operation? How? Dose the code execute faster in this way?

Regards

  • Hello Jake,

    It is slower to run a program from Flash (about 37 ns for access time according to the table 7.9.7.4 Flash/OTP Access Timing, I do not know if this changes for program execution vs data access). The memory from which a program runs from can be configured in the .cmd file of a CCS project. The best method is to load all code onto Flash and move the ones that need to be executed in a timely manner onto RAM once (it's best to not repeatedly have to copy back and forth, unless the devices is powering off or resetting). The code will execute faster on RAM, and doing most of the initial configuration on Flash will save some space on RAM.

    I've provided a basic template for configuring a .cmd file to start from Flash and load a program to RAM using the F2838x device (you will need to adjust the naming/which RAM units are available for your device, but the main points are to use the .TI.ramfunc, .binit, #pragma statement, and the memcpy function).

    Command linker file:

    MEMORY
    {
       /* BEGIN is used for the "boot to SARAM" bootloader mode   */
       BEGIN            : origin = 0x000000, length = 0x000002
       BOOT_RSVD        : origin = 0x000002, length = 0x0001AF     /* Part of M0, BOOT rom will use this for stack */
       RAMM0            : origin = 0x0001B1, length = 0x00024F
       RAMM1            : origin = 0x000400, length = 0x0003F8     /* on-chip RAM block M1 */
    //   RAMM1_RSVD       : origin = 0x0007F8, length = 0x000008     /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
       RAMD0            : origin = 0x00C000, length = 0x000800
       RAMD1            : origin = 0x00C800, length = 0x000800
       RAMLS0           : origin = 0x008000, length = 0x000800
       RAMLS1           : origin = 0x008800, length = 0x000800
       RAMLS2           : origin = 0x009000, length = 0x000800
       RAMLS3           : origin = 0x009800, length = 0x000800
       RAMLS4           : origin = 0x00A000, length = 0x000800
       RAMLS5           : origin = 0x00A800, length = 0x000800
       RAMLS6           : origin = 0x00B000, length = 0x000800
       RAMLS7           : origin = 0x00B800, length = 0x000800
       RAMGS0           : origin = 0x00D000, length = 0x001000
       RAMGS1           : origin = 0x00E000, length = 0x001000
       RAMGS2           : origin = 0x00F000, length = 0x001000
       RAMGS3           : origin = 0x010000, length = 0x001000
       RAMGS4           : origin = 0x011000, length = 0x001000
       RAMGS5           : origin = 0x012000, length = 0x001000
       RAMGS6           : origin = 0x013000, length = 0x001000
       RAMGS7           : origin = 0x014000, length = 0x001000
       RAMGS8           : origin = 0x015000, length = 0x001000
       RAMGS9           : origin = 0x016000, length = 0x001000
       RAMGS10          : origin = 0x017000, length = 0x001000
       RAMGS11          : origin = 0x018000, length = 0x001000
       RAMGS12          : origin = 0x019000, length = 0x001000
       RAMGS13          : origin = 0x01A000, length = 0x001000
       RAMGS14          : origin = 0x01B000, length = 0x001000
       RAMGS15          : origin = 0x01C000, length = 0x000FF8
    //   RAMGS15_RSVD     : origin = 0x01CFF8, length = 0x000008     /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
    
       /* Flash sectors */
       FLASH0           : origin = 0x080000, length = 0x002000  /* on-chip Flash */
       FLASH1           : origin = 0x082000, length = 0x002000  /* on-chip Flash */
       FLASH2           : origin = 0x084000, length = 0x002000  /* on-chip Flash */
       FLASH3           : origin = 0x086000, length = 0x002000  /* on-chip Flash */
       FLASH4           : origin = 0x088000, length = 0x008000  /* on-chip Flash */
       FLASH5           : origin = 0x090000, length = 0x008000  /* on-chip Flash */
       FLASH6           : origin = 0x098000, length = 0x008000  /* on-chip Flash */
       FLASH7           : origin = 0x0A0000, length = 0x008000  /* on-chip Flash */
       FLASH8           : origin = 0x0A8000, length = 0x008000  /* on-chip Flash */
       FLASH9           : origin = 0x0B0000, length = 0x008000  /* on-chip Flash */
       FLASH10          : origin = 0x0B8000, length = 0x002000  /* on-chip Flash */
       FLASH11          : origin = 0x0BA000, length = 0x002000  /* on-chip Flash */
       FLASH12          : origin = 0x0BC000, length = 0x002000  /* on-chip Flash */
       FLASH13          : origin = 0x0BE000, length = 0x002000  /* on-chip Flash */
       CPU1TOCPU2RAM    : origin = 0x03A000, length = 0x000800
       CPU2TOCPU1RAM    : origin = 0x03B000, length = 0x000800
    
       CPUTOCMRAM       : origin = 0x039000, length = 0x000800
       CMTOCPURAM       : origin = 0x038000, length = 0x000800
    
       CANA_MSG_RAM     : origin = 0x049000, length = 0x000800
       CANB_MSG_RAM     : origin = 0x04B000, length = 0x000800
       RESET            : origin = 0x3FFFC0, length = 0x000002
    }
    
    
    SECTIONS
    {
       codestart        : > BEGIN
       .binit			: > FLASH3 /* .binit will execute before main because it's in the linker file */
       .text            : >> FLASH1 | FLASH2 | FLASH3 | FLASH4
       .cinit           : > FLASH1
       .switch          : > FLASH1
       .reset           : > RESET, TYPE = DSECT /* not used, */
    
    	//
    	// Copies contents from Flash 3 to RAMLS0 and RAMLS1 (if not enough room
    	// on RAMLS0)
    	//
       .TI.ramfunc : {} LOAD = FLASH3,
                        RUN = RAMLS0 | RAMLS1,
                        table(BINIT),
                        PAGE = 0, ALIGN(4)
    
       .stack           : > RAMM1
    #if defined(__TI_EABI__)
       .bss             : > RAMLS5
       .bss:output      : > RAMGS0
       .init_array      : > RAMGS1
       .const           : >> FLASH5 | FLASH6 | FLASH7
       .data            : > RAMLS5
       .sysmem          : > RAMLS5
    #else
       .pinit           : > FLASH1
       .ebss            : >> RAMLS5 | RAMGS0 | RAMGS1
       .econst          : >> FLASH5 | FLASH6 | FLASH7
       .esysmem         : > RAMLS5
    #endif
    
       ramgs0 : > RAMGS0, type=NOINIT
       ramgs1 : > RAMGS1, type=NOINIT
    
       MSGRAM_CPU1_TO_CPU2 > CPU1TOCPU2RAM, type=NOINIT
       MSGRAM_CPU2_TO_CPU1 > CPU2TOCPU1RAM, type=NOINIT
       MSGRAM_CPU_TO_CM   > CPUTOCMRAM, type=NOINIT
       MSGRAM_CM_TO_CPU   > CMTOCPURAM, type=NOINIT
    }
    
    /*
    //===========================================================================
    // End of file.
    //===========================================================================
    */
    

    Main program code:

    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    #include "c2000ware_libraries.h"
    
    //
    // This pre-processor command loads the function into the .TI.ramfunc
    // section of memory
    //
    #pragma CODE_SECTION(ramCounter, ".TI.ramfunc");
    
    //
    // Main
    //
    void main(void)
    {
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pull-ups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // PinMux and Peripheral Initialization
        //
        Board_init();
    
        //
        // C2000Ware Library initialization
        //
        C2000Ware_libraries_init();
    
        //
        // Copy functions from .TI.ramfunc from Flash to RAM; the method of using
        // binit replaces memcpy in this example, the line remains as a template
        // of how the function can be called
        //
        //EALLOW;
        //memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
        //EALLOW;
    
        //
        // Enable Global Interrupt (INTM) and real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        while(1);
    }
    
    //
    // End of File
    //
    

    Best regards,

    Omer Amir

  • Thanks for the prompt reply.

    Best regards.