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.

Slow code speeds

I have a small program which toggles the LEDs. It does this at a speed slow enough that you can clearly see when the program runs. The program is intended to run from flash. When I download and hit the green arrow (to start the program) in CCS the program runs fine. If I then unplug the USB cable, and plug it back in (to reset the system) the program starts up but runs slower (LEDs are flashing at a noticeable lower rate). This suggests that when I download, the program "lands" in RAM, and when the board is reset (by a power cycle) it boots from flash. I would have expected that when I download to the board from CCS the code would go to flash and run from flash. What am I missing? Why do I have to either power cycle or hit the reset button to get execution from flash? I'm assuming I've overlooked something, but what?

  • Hi,

    When you debug the code; does it show "Erasing flash sectors.... Programming flash"? Cause what I feel is, you might be running the code via RAM and the program on flash might've been loaded long ago. So while debugging if the program loads quickly ie within 2 secs; then you're loading into RAM and not flash. Let me know what your observations are.

    Regards,

    Gautam

  • when you create your project you have to tell the linker where to place your code, in RAM and/or Flash.

    most of the projects are set-up so that you can right click, Build Options, and set Active a Debug (RAM), Release (RAM), or Flash build.

    if you place in Flash there is typically a switch on the hardware (LaunchPad or controlCARD) that must be positioned to allow the device to boot to flash and start running your application.

     

  • and a final point is to insure that you set-up the flash with correct number of waitstates for full speed operation.

    But any sort of software timer that is running should be in RAM.  If you are using a hardware timer that GPIO toggle should be fine in Flash.

     

  • Hello Chris,

    Thanks for the suggestions. It looks to me as if the code is indeed in flash... C-code and .map file below. As far as I can see the code execute from RAM when I download. When I press reset, the code runs from flash. I can tell by the different rates of LED cycling. The board boots in from flash fine after reset/power cycle - that's not the problem. I can't see why I get two different execution speeds...

    Code:

    /*

    * main.c

    */

    #include "DSP28x_Project.h" // Device Headerfile and Examples Include File

    #include "f2802x_common/include/adc.h"

    #include "f2802x_common/include/clk.h"

    #include "f2802x_common/include/flash.h"

    #include "f2802x_common/include/gpio.h"

    #include "f2802x_common/include/pie.h"

    #include "f2802x_common/include/pll.h"

    #include "f2802x_common/include/wdog.h"

     

    void delay_loop(void);

    void Gpio_select(void);

    ADC_Handle myAdc;

    CLK_Handle myClk;

    FLASH_Handle myFlash;

    GPIO_Handle myGpio;

    PIE_Handle myPie;

    PWM_Handle myPwm;

     

     

     

     

    //-----------------------------------------------------------------------------------------------------------------------------------------------------

    int main(void) {

    CPU_Handle myCpu;

    PLL_Handle myPll;

    WDOG_Handle myWDog;

     

     

     

     

    myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));

    myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));

    myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));

    myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));

    myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));

    myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));

    myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));

    myPwm = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));

    myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));

     

    WDOG_disable(myWDog);

    Gpio_select();

      

    for(;;){

    ((GPIO_Obj *)myGpio)->GPADAT = 0xAAAAAAAA;

    ((GPIO_Obj *)myGpio)->GPBDAT = 0x0000000A;

    delay_loop();

    ((GPIO_Obj *)myGpio)->GPADAT = 0x55555555;

    ((GPIO_Obj *)myGpio)->GPBDAT = 0x00000005;

    delay_loop();

    }

     

    return 0;

    }

     

    void delay_loop()

    {

    long unsigned int i;

    for (i = 0; i < 50000; i++) {}

    }

    void Gpio_select(void)

    {

    EALLOW;

    ((GPIO_Obj *)myGpio)->GPAMUX1 = 0x00000000;

    ((GPIO_Obj *)myGpio)->GPAMUX2 = 0x00000000;

    ((GPIO_Obj *)myGpio)->GPBMUX1 = 0x00000000;

    ((GPIO_Obj *)myGpio)->GPADIR = 0xFFFFFFFF;

    ((GPIO_Obj *)myGpio)->GPBDIR = 0x0000000F;

    EDIS;

    }

    .map File:

    ******************************************************************************

    TMS320C2000 Linker PC v6.2.0

    ******************************************************************************

    >> Linked Tue Jan 14 22:03:21 2014

    OUTPUT FILE NAME: <test1.out>

    ENTRY POINT SYMBOL: "code_start" address: 003f7ff6

     

    MEMORY CONFIGURATION

    name origin length used unused attr fill

    ---------------------- -------- --------- -------- -------- ---- --------

    PAGE 0:

    RAMM0 00000050 000003b0 00000004 000003ac RWIX

    OTP 003d7800 00000400 00000000 00000400 RWIX

    FLASHB 003f6000 00001000 00000000 00001000 RWIX

    FLASHA 003f7000 00000f80 00000180 00000e00 RWIX

    CSM_RSVD 003f7f80 00000076 00000076 00000000 RWIX

    BEGIN 003f7ff6 00000002 00000002 00000000 RWIX

    CSM_PWL_P0 003f7ff8 00000008 00000008 00000000 RWIX

    IQTABLES 003fe000 00000b50 00000000 00000b50 RWIX

    IQTABLES2 003feb50 0000008c 00000000 0000008c RWIX

    IQTABLES3 003febdc 000000aa 00000000 000000aa RWIX

    ROM 003ff27c 00000d44 00000000 00000d44 RWIX

    RESET 003fffc0 00000002 00000000 00000002 RWIX

    VECTORS 003fffc2 0000003e 00000000 0000003e RWIX

    PAGE 1:

    BOOT_RSVD 00000000 00000050 00000000 00000050 RWIX

    RAMM1 00000400 00000400 00000315 000000eb RWIX

    RAML0 00008000 00000400 00000000 00000400 RWIX

     

    SECTION ALLOCATION MAP

    output attributes/

    section page origin length input sections

    -------- ---- ---------- ---------- ----------------

    .pinit 0 003f7000 00000000 UNINITIALIZED

    ramfuncs 0 003f7000 00000004 RUN ADDR = 00000050

    003f7000 00000004 driverlib.lib : F2802x_asmfuncs.obj (ramfuncs)

    .text 0 003f7004 00000166

    003f7004 0000008f main.obj (.text)

    003f7093 00000044 rts2800_ml.lib : boot.obj (.text)

    003f70d7 00000019 : args_main.obj (.text)

    003f70f0 00000019 : exit.obj (.text)

    003f7109 00000012 driverlib.lib : F2802x_asmfuncs.obj (.text)

    003f711b 00000009 rts2800_ml.lib : _lock.obj (.text)

    003f7124 00000008 driverlib.lib : adc.obj (.text:_ADC_init)

    003f712c 00000008 : pie.obj (.text:_PIE_init)

    003f7134 00000008 : wdog.obj (.text:_WDOG_disable)

    003f713c 00000007 : clk.obj (.text:_CLK_init)

    003f7143 00000007 : flash.obj (.text:_FLASH_init)

    003f714a 00000007 : gpio.obj (.text:_GPIO_init)

    003f7151 00000007 : pll.obj (.text:_PLL_init)

    003f7158 00000007 : pwm.obj (.text:_PWM_init)

    003f715f 00000007 : wdog.obj (.text:_WDOG_init)

    003f7166 00000004 : cpu.obj (.text:_CPU_init)

    .cinit 0 003f716a 00000016

    003f716a 0000000a rts2800_ml.lib : _lock.obj (.cinit)

    003f7174 0000000a : exit.obj (.cinit)

    003f717e 00000002 --HOLE-- [fill = 0]

    csm_rsvd 0 003f7f80 00000076

    003f7f80 00000076 driverlib.lib : F2802x_asmfuncs.obj (csm_rsvd)

    codestart

    * 0 003f7ff6 00000002

    003f7ff6 00000002 driverlib.lib : F2802x_asmfuncs.obj (codestart)

    csmpasswds

    * 0 003f7ff8 00000008

    003f7ff8 00000008 driverlib.lib : F2802x_asmfuncs.obj (csmpasswds)

    .reset 0 003fffc0 00000002 DSECT

    003fffc0 00000002 rts2800_ml.lib : boot.obj (.reset)

    vectors 0 003fffc2 00000000 DSECT

    .stack 1 00000400 00000300 UNINITIALIZED

    00000400 00000300 --HOLE--

    .ebss 1 00000700 00000015 UNINITIALIZED

    00000700 0000000c main.obj (.ebss)

    0000070c 00000004 rts2800_ml.lib : _lock.obj (.ebss)

    00000710 00000004 : exit.obj (.ebss)

    00000714 00000001 driverlib.lib : cpu.obj (.ebss)

     

    GLOBAL DATA SYMBOLS: SORTED BY DATA PAGE

    address data page name

    -------- ---------------- ----

    00000400 10 (00000400) __stack

    00000700 1c (00000700) _myAdc

    00000702 1c (00000700) _myPie

    00000704 1c (00000700) _myPwm

    00000706 1c (00000700) _myFlash

    00000708 1c (00000700) _myGpio

    0000070a 1c (00000700) _myClk

    0000070c 1c (00000700) __unlock

    0000070e 1c (00000700) __lock

    00000710 1c (00000700) ___TI_cleanup_ptr

    00000712 1c (00000700) ___TI_dtors_ptr

    00000714 1c (00000700) _cpu

     

    GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name

    address name

    -------- ----

    ffffffff .text

    003f70f0 C$$EXIT

    003f7124 _ADC_init

    003f713c _CLK_init

    003f7166 _CPU_init

    003f7114 _DSP28x_DisableInt

    003f7118 _DSP28x_RestoreInt

    00000050 _DSP28x_usDelay

    003f7143 _FLASH_init

    003f714a _GPIO_init

    003f707c _Gpio_select

    003f712c _PIE_init

    003f7151 _PLL_init

    003f7158 _PWM_init

    00000004 _RamfuncsLoadSize

    003f7000 _RamfuncsLoadStart

    00000050 _RamfuncsRunStart

    003f7134 _WDOG_disable

    003f715f _WDOG_init

    00000700 __STACK_END

    00000300 __STACK_SIZE

    00000001 __TI_args_main

    00000710 ___TI_cleanup_ptr

    00000712 ___TI_dtors_ptr

    ffffffff ___binit__

    ffffffff ___c_args__

    003f716a ___cinit__

    ffffffff ___etext__

    ffffffff ___pinit__

    ffffffff ___text__

    003f70d7 __args_main

    0000070e __lock

    003f7123 __nop

    003f711f __register_lock

    003f711b __register_unlock

    00000400 __stack

    0000070c __unlock

    003f70f0 _abort

    003f7093 _c_int00

    00000714 _cpu

    003f706c _delay_loop

    003f70f2 _exit

    003f7004 _main

    00000700 _myAdc

    0000070a _myClk

    00000706 _myFlash

    00000708 _myGpio

    00000702 _myPie

    00000704 _myPwm

    003f7111 _setDBGIER

    ffffffff binit

    003f716a cinit

    003f7ff6 code_start

    ffffffff etext

    ffffffff pinit

     

    GLOBAL SYMBOLS: SORTED BY Symbol Address

    address name

    -------- ----

    00000001 __TI_args_main

    00000004 _RamfuncsLoadSize

    00000050 _DSP28x_usDelay

    00000050 _RamfuncsRunStart

    00000300 __STACK_SIZE

    00000400 __stack

    00000700 __STACK_END

    00000700 _myAdc

    00000702 _myPie

    00000704 _myPwm

    00000706 _myFlash

    00000708 _myGpio

    0000070a _myClk

    0000070c __unlock

    0000070e __lock

    00000710 ___TI_cleanup_ptr

    00000712 ___TI_dtors_ptr

    00000714 _cpu

    003f7000 _RamfuncsLoadStart

    003f7004 _main

    003f706c _delay_loop

    003f707c _Gpio_select

    003f7093 _c_int00

    003f70d7 __args_main

    003f70f0 C$$EXIT

    003f70f0 _abort

    003f70f2 _exit

    003f7111 _setDBGIER

    003f7114 _DSP28x_DisableInt

    003f7118 _DSP28x_RestoreInt

    003f711b __register_unlock

    003f711f __register_lock

    003f7123 __nop

    003f7124 _ADC_init

    003f712c _PIE_init

    003f7134 _WDOG_disable

    003f713c _CLK_init

    003f7143 _FLASH_init

    003f714a _GPIO_init

    003f7151 _PLL_init

    003f7158 _PWM_init

    003f715f _WDOG_init

    003f7166 _CPU_init

    003f716a ___cinit__

    003f716a cinit

    003f7ff6 code_start

    ffffffff .text

    ffffffff ___binit__

    ffffffff ___c_args__

    ffffffff ___etext__

    ffffffff ___pinit__

    ffffffff ___text__

    ffffffff binit

    ffffffff etext

    ffffffff pinit

    [55 symbols]

  • you must have CodeStartBranch.asm if you project runs from flash at all, correct?

    seems like a clock divider or flash clock isn't set correctly.

     

  • I would also add that you aren't setting up the PLL in your code.  The flash programming algorithms that run when CCS programs the device will setup the PLL, but after you reset the device is running at the internal oscillator or external crystal frequency (typically 10MHz).

    Add the PLL setup code and it should resolve your issue.