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/TMS320F28035: Problem FLASH programming TMS320F28035 uController

Part Number: TMS320F28035

Tool/software: Code Composer Studio

Hi, I am having major problems getting my code to run from FLASH on a TMS320F28035.

My code (written in C) worked perfectly well when operating in DEBUG mode (in RAM) and the operation was as I expected. I have since attempted to create a version that I can program into FLASH which will boot and operate at power up.

I have followed the examples and methods described in the application note (SPRA958L) and also looked at a number of resolved enquiries in this forum -but no joy. I believe I have selected the correct example linker file (F28035.cmd as opposed to the 28035_RAM_Ink.cmd file). When I program the device, I get the dialogue indicating that FLASH is being erased and then written to and I can initiate the code using the green triangle or single step. However, when I power off and disconnect the XDS110, it will not start up. The XRS pin (reset) is pulsing low for ~50us every ~13ms, which suggests the watchdog is going off and resetting the device, yet I have (I believe) disabled it in the setup routine (ala SPRA958L).

I have included a cut down version of the code (I really do not want to bore any potential helpers with all the code) that just flashes a couple of LEDS. I am happy to post any extra data as necessary if someone can help.

I know it is going to be embarrassingly obvious – but at this point I would be happy for any help, as I have spent an awful of time trying to program the part.

 

J

Code below:

#include "DSP28x_Project.h"
#include "DSP2803x_Device.h"
//#include "DSP2803x_SysCtrl.c"
#include "DSP2803x_Adc.c"
#include "EP1401_DSP28035_GPIO.c"
//#include "DSP2803x_PieCtrl.c"
//#include "DSP2803x_PieVect.c

#include <string.h>
#include <stdint.h>

#pragma CODE_SECTION(InitFlash, "ramfuncs");

//Global Variables
int LEDToggleCount = 0;         //Toggle count to allow the LED to be turned off and on.
int LED = 0;                    //LED state: 0 = ON, 1 = OFF.

void InitialisePorts(void)
{
    EALLOW;
    /*
     * Set up functions of GPIO
     */
    GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3;    //GPIO18 = XCKLOUT
    //LED control bits
    GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 0b00;    //GPIO
    GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 0b00;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 0b00;   // GPIO functionality GPIO16-GPIO31
    //Unused
    GpioCtrlRegs.GPBMUX1.bit.GPIO42 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO43 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 0;   // GPIO functionality GPIO16-GPIO31
    //COMMs data bits
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0;   // GPIO functionality GPIO16-GPIO31
    //digital Data
    GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO44 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 0;   // GPIO functionality GPIO16-GPIO31
    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;   // GPIO functionality GPIO16-GPIO31
    /*
     * Set up direction of GPIO
     */
    GpioCtrlRegs.GPADIR.bit.GPIO18 = 1;   // GPIO are GP outputs XCLKOUT
    //LEDS
    GpioCtrlRegs.GPADIR.bit.GPIO22 = 1;   // GPIO0-GPIO31 are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO29 = 1;   // GPIO are GP outputs
    GpioCtrlRegs.GPBDIR.bit.GPIO32 = 1;   // GPIO are GP outputs
    GpioCtrlRegs.GPBDIR.bit.GPIO33 = 1;   // GPIO are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;   // GPIO are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO28 = 1;   // GPIO are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO23 = 1;   // are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO26 = 1;   // are GP outputs
    //Spare
    GpioCtrlRegs.GPBDIR.bit.GPIO42 = 1;   // are GP outputs
    GpioCtrlRegs.GPBDIR.bit.GPIO43 = 1;   // are GP outputs
    GpioCtrlRegs.GPADIR.bit.GPIO27 = 1;   // are GP outputs
    //COMMs data bits
    GpioCtrlRegs.GPADIR.bit.GPIO0 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;   // GPIO are GP output
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;   // GPIO are GP output
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;   // GPIO are GP input
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;   // GPIO are GP output
    GpioCtrlRegs.GPADIR.bit.GPIO6 = 1;   // GPIO are GP output
    GpioCtrlRegs.GPADIR.bit.GPIO7 = 0;   // GPIO are GP input
    //Digital data
    GpioCtrlRegs.GPADIR.bit.GPIO8 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPADIR.bit.GPIO25 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPBDIR.bit.GPIO44 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPBDIR.bit.GPIO41 = 0;   // GPIO are GP input
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 0;   // GPIO are GP input
    //Disable interrupts
    DINT;
    //End edit of control registers
    EDIS;
}
/*
 *This section sets up the ADC to read the input voltages
 *There are 5 inputs to read hence SOC0 to SOC4
 *ADC operation is software driven and does NOT use any interrupts.
 *A simple time delay is employed to provide time for the ADC operation
 */
void SetUpADC(void)
{
    EALLOW;
    //Single Sample Mode
    AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 0x00;     //Single sample mode for 0 and 1
    //ADC Port B-0  --TB_MEASURE_A      Pin 23
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 0x00;    //0x00 means Software triggers ADC process
    AdcRegs.ADCSOC0CTL.bit.CHSEL    = 0x08;    //SOC0 = ADC-IP B0 Pin 23
    AdcRegs.ADCSOC0CTL.bit.ACQPS    = 0x09;    //10 Clock Cycles Sample period
    //ADC Port B-1  --MISSILE_P44V_A    Pin 24
    AdcRegs.ADCSOC1CTL.bit.TRIGSEL  = 0x00;    //0x00 means Software triggers ADC process
    AdcRegs.ADCSOC1CTL.bit.CHSEL    = 0x09;    //SOC1 = ADC-IP B1 Pin 24
    AdcRegs.ADCSOC1CTL.bit.ACQPS    = 0x09;    //10 Clock Cycles Sample period
    //Single Sample Mode
    AdcRegs.ADCSAMPLEMODE.bit.SIMULEN2 = 0x00;     //Single sample mode for 2 and 3
    //ADC Port B-2  --28V_Sense_A       Pin 25
    AdcRegs.ADCSOC2CTL.bit.TRIGSEL  = 0x00;    //0x00 means Software triggers ADC process
    AdcRegs.ADCSOC2CTL.bit.CHSEL    = 0x0A;    //SOC2 = ADC-IP B2 Pin 25
    AdcRegs.ADCSOC2CTL.bit.ACQPS    = 0x09;    //10 Clock Cycles Sample period
    //ADC Port B-3  --44V_Sense_A       Pin 26
    AdcRegs.ADCSOC3CTL.bit.TRIGSEL  = 0x00;    //0x00 means Software triggers ADC process
    AdcRegs.ADCSOC3CTL.bit.CHSEL    = 0x0B;    //SOC3 = ADC-IP B3 Pin 26
    AdcRegs.ADCSOC3CTL.bit.ACQPS    = 0x09;    //10 Clock Cycles Sample period
    //Single Sample Mode
    AdcRegs.ADCSAMPLEMODE.bit.SIMULEN4 = 0x00;     //Single sample mode for 4 and 5
    //ADC Port B-4  --TB_GOOD           Pin 27
    AdcRegs.ADCSOC4CTL.bit.TRIGSEL  = 0x00;    //0x00 means Software triggers ADC process
    AdcRegs.ADCSOC4CTL.bit.CHSEL    = 0x0C;    //SOC3 = ADC-IP B4 Pin 27
    AdcRegs.ADCSOC4CTL.bit.ACQPS    = 0x09;    //10 Clock Cycles Sample period
    EDIS;
}

/*
 * This code intitilises the LEDS OFF
 */
void IntialiseLEDS(void)
{
    GpioDataRegs.GPADAT.bit.GPIO22 = 0; //Turn on LED3 (RED)
    GpioDataRegs.GPBDAT.bit.GPIO32 = 0; //Turn on LED4 (RED) ?
    GpioDataRegs.GPBDAT.bit.GPIO33 = 0; //Turn on LED5 (RED)
    GpioDataRegs.GPADAT.bit.GPIO23 = 0; //Turn on LED6 (RED)
    GpioDataRegs.GPADAT.bit.GPIO29 = 0; //Turn on LED1 (GREEN) ?
    GpioDataRegs.GPADAT.bit.GPIO26 = 0; //Turn on LED2 (GREEN)
    GpioDataRegs.GPADAT.bit.GPIO9 = 0; //Turn on LED7 (GREEN)
    GpioDataRegs.GPADAT.bit.GPIO28 = 0; //Turn on LED8 (GREEN)

    GpioDataRegs.GPADAT.bit.GPIO22 = 1; //Turn off LED3 (RED)
    GpioDataRegs.GPBDAT.bit.GPIO32 = 1; //Turn off LED4 (RED) ?
    GpioDataRegs.GPBDAT.bit.GPIO33 = 1; //Turn off LED5 (RED)
    GpioDataRegs.GPADAT.bit.GPIO23 = 1; //Turn off LED6 (RED)
    GpioDataRegs.GPADAT.bit.GPIO29 = 1; //Turn off LED1 (GREEN) ?
    GpioDataRegs.GPADAT.bit.GPIO26 = 1; //Turn off LED2 (GREEN)
    GpioDataRegs.GPADAT.bit.GPIO9 = 1; //Turn off LED7 (GREEN)
    GpioDataRegs.GPADAT.bit.GPIO28 = 1; //Turn off LED8 (GREEN)
}
/*
 * This code initialises the communication control
 */
void InitialiseComms(void)
{
    //GpioDataRegs.GPADAT.bit.GPIO1 = 0;              //Allow WCU clock in
    GpioDataRegs.GPADAT.bit.GPIO1 = 1;              //TEST Disable WCU clock in
    GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;        //Disable the PU
    GpioDataRegs.GPADAT.bit.GPIO2 = 1;              //Allow Data out
    GpioDataRegs.GPADAT.bit.GPIO5 = 0;              //Allow RTL in
    GpioDataRegs.GPADAT.bit.GPIO6 = 1;              //Allow PMG Frequency out
}
/*
 * This is the MAIN
 */
/*
 * The following 'extern' statements have been added to overcome the flash issue.
 */
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadSize;
extern Uint16 RamfuncsRunStart;
//
extern Uint16 PieVectTableInit;

extern unsigned int econst_loadstart;
extern unsigned int econst_loadsize;
extern unsigned int econst_runstart;


void main(void)
{
    memcpy(&RamfuncsRunStart,&RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);

    InitSysCtrl();
    InitGpio();
    DINT;

//Following line added to attmept to fix the Flash issue (SPRA958L application note). 
    /*** Initialize the PIE_RAM ***/
//    PieCtrlRegs.PIECTRL.bit.ENPIE = 0; // Disable the PIE
//    EALLOW;
//    memcpy((Uint16 *)&PieVectTable+6, (Uint16 *)&PieVectTableInit+6, 256-6);

    InitAdc();
    //Initialise the ports
    InitialisePorts();
    //Initialise the LEDS (off)
    IntialiseLEDS();
    //Enable the communications buffers
    InitialiseComms();
    //Configure the ADC
    SetUpADC();
    //read the PMG detected status
    PMGConnected();
    IntialiseLEDS(); //ODD - two of the LEDS are on when they should be off!!!!
    GpioDataRegs.GPBDAT.bit.GPIO32 = 1;
    GpioDataRegs.GPADAT.bit.GPIO29 = 1;
//test code
//end test code
    while(1)
    {
        if (LEDToggleCount == 20)
        {
            GpioDataRegs.GPADAT.bit.GPIO22 = LED;                   //Toggle LED
            LED = (!LED);
            LEDToggleCount = 0;
        }
        else
        {
        LEDToggleCount++;
        }
        GpioDataRegs.GPADAT.bit.GPIO26 = 0; //Turn off LED2 (GREEN)
        GpioDataRegs.GPADAT.bit.GPIO26 = 1; //Turn off LED2 (GREEN)
    /*
     * The sequnce will simply now repeat ad infinitum....
     * or at least until the power is removed
     *
     */
    }
}

 

  • Hi John,

    Have you included the CodeStartBranch.asm file into your project?

    Have you ensured that the device is configured to boot to flash?

    It is likely one of these two things which is your issue.

    Regards,
    sal
  • Hi Sal,

    Yes the CodeStartBracnch.asm is included in the project (visible in the Project Explorer window of CCS). There is also the CodeStartBracnch.obj entry under the configuration.

    I 'think' I have configured the device to boot to flash... but I would be happy to be guided through the buttons to press and options to select so as to be sure.

    In truth I have been fiddling about with the project for so long it is possible that I have inadvertently set an option that is adding to the problem.

    If I were to start from scratch and have a simple bit of code that flashes a couple of LEDS (toggles a few GPIO ports), what options do I need to set 'out of the box' to make the code run from FLASH at power up? If I can get past this I am confident that I can move forward.

    Your help is appreciated.

    J

  • You need to confirm that the boot mode select pins are set properly to boot to flash.

    You can also connect to the device and load the boot ROM symbols. And then set the device to boot to flash using the EMU boot mode options. Then you can begin stepping through the boot ROM to ensure that it is branching to the flash entry point, and you can check also that your codestartbranch codestart section is placed at that location. You can do that last part without running boot ROM. you can confirm that the codestart section with the "LB _c_int00" is placed in the proper place with the memory browser.

    Please see www.ti.com/.../sprugo0b.pdf

    Regards,
    sal
  • Hi Sal,

    Thank you for your help.

    What you suggested fixed the issue, it was the boot option pins - GPIO34 specifically which I had connected to a signal that on power up was at 0V. This prevented the device from booting up into FLASH. Whilst in related documents mention is made that this pin is read at power up to determine the boot up mode, the datasheet pin configuration page describes it as general purpose and I missed that this would be problematic. Fortunately the design can easily be altered.

    I did get the code working in FLASH only to uncover a few other issues (all sorted).

    When single stepping through the code, the steps were jumping around in a sequence that was not related to the code. This was fixed by setting the 'optimisation' option to OFF. Which begs the question if optimisation is needed for speed purposes, how do I step through the code and makes sense of where I am? Also I found that a local variable (i.e. in a simple delay loop) was being optimised out - such that the code was not being run. Initially I fixed this by making the count variable global (not ideal). When the optimisation was turned OFF, the problem appears to have gone away and I can have local variables. Is this normal behaviour for the optimiser?

    Thanks again for your help

    J
  • Hi John,

    When you turn the optimizer on in the code generation tool, then the compiler will optimize the instructions. Many times this means removing unnecessary code and also re-ordering operations.

    If you need to ensure that accesses to memory locations or variables, such as local variables are not optimized out, you need to declare them 'volatile' with the volatile key word. You do not need to make the variable global, only declare it with the volatile keyword.

    Regards,
    sal