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.

Problem executing F28335 Flash API from FLASH

Hi,

I have the same problem as http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/30583.aspx but the answer don't work for me.

When I load the program directly in the RAM, the API works and when I load it into Flash, the API jump to the begginning of the code (main first line).

The flash api is copied into the RAM and interrupt are disable  for the execution.

Flash28_API:
{
   -l Flash28335_API_V210.lib(.econst)
   -l Flash28335_API_V210.lib(.text)
} LOAD = FLASHF,
RUN = RAML1,
LOAD_START(_Flash28_API_LoadStart),
LOAD_END(_Flash28_API_LoadEnd),
RUN_START(_Flash28_API_RunStart),
PAGE = 0

Why the program restart?

Any suggestions?

Thanks

Simon

  • Hi Simon!

    1 Check please into Flash2833x_API_Config.h that the specification of device is correct:

    /*-----------------------------------------------------------------------------
    1. Specify the device.
    Define the device to be programmed as "1" (no quotes).
    Define all other devices as "0" (no quotes).
    -----------------------------------------------------------------------------*/

    #define FLASH_F28335 1
    #define FLASH_F28334 0
    #define FLASH_F28332 0

    2 Did you include CodeStartBranch.asm file to your project?

    3 Could you please attach your main C-file & cmd-file.

    Regards,

    Igor

  • Hi Simon,

    Please go through this doc thoroughly, this might solve your problem:

    http://www.ti.com/lit/an/spra958l/spra958l.pdf

    Regards,

    Gautam

  • Hi,

    point 1 & 2 are OK. I upload the files.

    //###########################################################################
    
    /*----------------------------------------------------------------------**
    **	Projet: 		Commande pour un transfert d'�nergie � distance		**
    **																		**
    **	Auteur: 		Simon Cantin										**
    **																		**
    **	Description:	G�re un transfert d'�nergie de 100kW				**
    **						- Gestion des PWM								**
    **						- Liaison PC									**
    **						- Mesure puissance triphas�e au primaire		**
    **						- Mesure du courant de sortie � fr�quence �lev�e**
    **----------------------------------------------------------------------*/
    
    #include "DSP2833x_Device.h"	// DSP2833x Headerfile Include File
    #include "DSP2833x_Examples.h"	// DSP2833x Examples Include File
    #include "GlobalsVariables.h"	// D�finition des variables globales
    #include "Mesures.h"
    #include "Securite.h"
    #include "SaveFlash.h"
    #include "Sci.h"
    #include "string.h"
    #include "IQmathlib.h"			// Librairie IQmath
    #include <stdio.h>
    
    interrupt void cpu_timer0_isr(void);
    interrupt void cpu_timer2_isr(void);
    void Init(void);
    
    /*------------------------------------------------------------------------**
    **						 	   Main										  **
    **------------------------------------------------------------------------*/
    
    // Copie certaines fonctions dans la RAM quand le programme est charg� dans la FLASH
    extern unsigned int RamfuncsLoadStart;
    extern unsigned int RamfuncsLoadEnd;
    extern unsigned int RamfuncsRunStart;
    extern Uint16 Flash28_API_LoadStart;
    extern Uint16 Flash28_API_LoadEnd;
    extern Uint16 Flash28_API_RunStart;
    
    
    
    void main(void)
    {
    	Init();
    	// Message TERMINAL
    	/*scia_msg("\rTransfert d'energie sans contact\n\r\0");
    	scia_msg("---------\n\r\0");
    	scia_msg("RUN\t:R\t\0");
    	scia_msg("STOP\t:S\t\0");
    	scia_msg("RESET\t:T\n\r\0");
    	scia_msg("Mesures actuelles\t:M\t\0");
    	scia_msg("Mesures courant\t:m\n\r\0");
    	scia_msg("Set parametre\t:Pno+val+exp\t");
    	scia_msg("Get parametre\t:Gno\n\r");
    	scia_msg("---------\n\r\0");
    	scia_msg("Taper votre commande et valider avec Enter:\n\r\0");*/
    	// Charge les donn�es de la flash dans le buffer
    	Example_MemCopy(Sector[1].StartAddr, Sector[1].StartAddr + LENGTH_BUFFER, (Uint16*) &parametresFloat[0]);
    
    
      	/*------------------------------------------------------------------------**
      	**			  Boucle sans fin, attente de l'interruption			  	  **
      	**------------------------------------------------------------------------*/
    	for(;;)
    	{
    		// Communications
    		scia_loop();
    
    	}
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Interruption avec le timer0
    #pragma CODE_SECTION(cpu_timer0_isr,"ramfuncs");
    // INT1.6
    interrupt void cpu_timer0_isr(void)
    {
    	/*------------------------------------------------------------------------------------------**
    	**							Description de l'interruption									**
    	**------------------------------------------------------------------------------------------*/
    	// Programme principal
    	/*------------------------------------------------------------------------------------------**
    	**									D�but de l'interruption									**
    	**------------------------------------------------------------------------------------------*/
    	//GPIO59_ON;
       /*------------------------------------------------------------------------------------------**
       	**									Machine d'�tat											**
       	**------------------------------------------------------------------------------------------*/
    	time += 100e-6;
    
       // TRANSITIONS RAPIDES
       if((VER_HARD || verSoft) && etatMachine != QUITTANCE)	// Va � l'�tat erreur en cas d'erreur soft ou hard sauf dans le cas de la quittance
    	   etatMachine = ERREUR;
       else if((STOP_TEL || stopSoft) && (etatMachine == DEMARRAGE || etatMachine == MARCHE_MesureCourant || etatMachine == MARCHE)) // REPOS si machine en marche
       //else if((stopSoft) && (etatMachine == DEMARRAGE || etatMachine == MARCHE_MesureCourant || etatMachine == MARCHE)) // REPOS si machine en marche
    	   etatMachine = REPOS;
    
       switch(etatMachine)
       {
       	   case  REPOS: // Installation arret�e
       	   	   // ACTIONS: coupe les PWM, met l'affiche stop, effectue les mesures, d�sactive le RESET
       		   stopSoft = 0;
       	   	   RESET_SOFT_OFF;
       	   	   LED_START_OFF;
       	   	   LED_STOP_ON;
       	   	   EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD*(0.0);
       	   	   EPwm2Regs.CMPA.half.CMPA = EPwm2Regs.TBPRD*(0.0);
       	   	   fpwm_current = fStart;
       	   	   duty_current = 0.0;
       	   	   mesuresGenerales();
       	   	   transitoireFini = 0;
       	   	   /*if(demandeSaveFlash)
       	   	   {
       	   		   demandeSaveFlash = 0;
       	   		   saveFlash();
       	   	   }*/
       	   	   // TRANSITIONS
       	   	   if(START_TEL || startSoft)
       	   		   etatMachine = DEMARRAGE;
       	   	   break;
       	   case DEMARRAGE: // D�marre le transfert avec une rampe sur le rapport cyclique et une sur la fr�quence
       	   	   // S�curit�s sur les param�tres saisis pour les rampes
       		   if(fStop > fStopMAX || fStop < fStopMIN || fStart > fStop || fStart > fStartMAX || fStart < fStartMIN)
       			   etatMachine = ERREUR;
       		   if(dutyStop > dutyStopMAX || dutyStop < dutyStopMIN || 0.0 > dutyStop)
       			   etatMachine = ERREUR;
       		   if(fSlope > fSlopeMAX || fSlope < fSlopeMIN || 0.0 > fSlope)
       			   etatMachine = ERREUR;
       		   if(dutySlope > dutySlopeMAX || dutySlope < dutySlopeMIN || 0.0 > dutySlope)
       			   etatMachine = ERREUR;
    
       		   // ACTION: LED: start, incr�ment des rampes
       		   startSoft = 0;
       	   	   LED_START_ON;
       	   	   LED_STOP_OFF;
       	   	   rampeDemarrage();
       	   	   // TRANSITIONS
       	   	   if(transitoireFini)
       	   		   etatMachine = MARCHE_MesureCourant;
       	   	   break;
       	   case MARCHE_MesureCourant:	// Mesure l'allure du courant apr�s le transitoire de d�marrage
       		   // ACTIONS: mesures haute fr�quence du courant
       		   mesuresCourant();
       		   // TRANSITIONS
       		   if(mesureCourantFini)
    			   etatMachine = MARCHE;
       		   break;
       	   case MARCHE:
       		   // Etat de fonctionnement normal, mesure la puissance au primaire et les temp�ratures
       		   mesuresGenerales();
       		   break;
       	   case QUITTANCE:
       		   // ACTION: D�sactive le verrouillage soft, attend 10us, fait un reset, attend 10us et regarde le verrouillage harwdare
       		   resetSoft = 0;
       		   VER_SOFT_OFF;
       		   RESET_SOFT_ON;
       		compteurQuittance++;
       		   // TRANSITION
       		   if (!VER_HARD)
       			   etatMachine = REPOS;
       		   else if (compteurQuittance > 1000)
       			   etatMachine = ERREUR;
       		   break;
       	   default: 	// Erreur par d�faut
       	   case ERREUR: // Erreur hard ou soft
       	   		   // ACTION: D�sactive les PWMS, verrouille le harwarde, led: stop
       		   	   RESET_SOFT_OFF;
       	   		   VER_SOFT_ON;
       	   		   LED_START_OFF;
       	   		   if((int)(time) % 2 >= 1)
       	   			   LED_STOP_ON;
       	   		   else
       	   			   LED_STOP_OFF;
       	   		   EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD*(0.0);
       	   		   EPwm2Regs.CMPA.half.CMPA = EPwm2Regs.TBPRD*(0.0);
       	   		   compteurQuittance = 0;
       	   		   // Statistique de l'erreur
       	   		   erreurSTAT = STAT_overtemp1 * 1 + STAT_overtemp2 * 2 + STAT_overcurrent1 * 4 + STAT_overcurrent2 * 8 + STAT_err1 * 16 + STAT_err2 * 32 + STAT_arretUrgence * 64 + STAT_verSoft * 128;
       	   		   // TRANSITION
       	   		   if(RESET_TEL || resetSoft)
       	   			   etatMachine = QUITTANCE;
       	   		   break;
       }
    
    
       	/*------------------------------------------------------------------------------------------**
       	**									Fin de l'interruption									**
       	**------------------------------------------------------------------------------------------*/
       // Acknowledge this interrupt to receive more interrupts from group 1
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    
       //GPIO59_OFF;
    }
    
    
    
    void Init(void)
    {
    	/*------------------------------------------------------------------------**
    	**						 	  Initialisations							  **
    	**------------------------------------------------------------------------*/
    	// Syst�me
    	InitSysCtrl();
    	// Entr�es - sorties
    	InitGpio();
    	InitSciGpio();
    	// interruptions
    	DINT;
    	/*------------------------------------------------------------------
    		   Copy API Functions into SARAM
    	------------------------------------------------------------------*/
    
    	// Copy the Flash API functions to SARAM
    	Example_MemCopy(&Flash28_API_LoadStart, &Flash28_API_LoadEnd, &Flash28_API_RunStart);
    
    	// We must also copy required user interface functions to RAM.
    	Example_MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
    
    	InitPieCtrl();
    	IER = 0x0000;
    	IFR = 0x0000;
    	InitPieVectTable();
    	IER |= 0x0001; // enable ADC interrupt
    	EALLOW;  // This is needed to write to EALLOW protected registers
    	PieVectTable.TINT0 = &cpu_timer0_isr;
    	PieVectTable.TINT2 = &cpu_timer2_isr;
    	EDIS;    // This is needed to disable write to EALLOW protected registers
    	// Interrupts that are used in this example are re-mapped to
    	// ISR functions found within this file.
    	EALLOW;	// This is needed to write to EALLOW protected registers
    	//PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
    	//PieVectTable.SCITXINTA = &sciaTxFifoIsr;
    	//PieVectTable.SCIRXINTB = &scibRxFifoIsr;
    	//PieVectTable.SCITXINTB = &scibTxFifoIsr;
    	EDIS;   // This is needed to disable write to EALLOW protected registers
    	// Copie certaines fonctions dans la RAM dans le cas o� le programme est charg� dans la flash
    	//memcpy( &RamfuncsRunStart, &RamfuncsLoadStart, &RamfuncsLoadEnd - &RamfuncsLoadStart);
    
    	//initXintf();
    	InitFlash();
    	// global variables initialisation
    	init_globals();
    	// Initialise le Timer
    	InitCpuTimers();
    	//Initialisation of ADC module, tensions + courants triphas�s, temp�ratures + courants r�sonants
    	InitAdc();
    	//Initialisations des PWM
    	InitEPwm1(fpwm_current, T_dead_band, 0.0);		// Diagonale 1
    	InitEPwm2(fpwm_current, T_dead_band, 180.0);	// Diagonale 2
    	// Configure CPU-Timer 0 to interrupt every millisecond:
    	// 150MHz CPU Freq, 1 millisecond Period (in uSeconds)
    	ConfigCpuTimer(&CpuTimer0, 150, 100);					// 100us => 10kHz
    	ConfigCpuTimer(&CpuTimer2, 150, 10);					// 10us => 100kHz
    
    	CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
    	CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
    
    	// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
    	// which is connected to CPU-Timer 1, and CPU int 14, which is connected
    	// to CPU-Timer 2:
    	IER |= M_INT1;
    	IER |= M_INT14;
    	IER |= M_INT9;
    	// Enable TINT0 in the PIE: Group 1 interrupt 7
    	PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // autorise interruption timer0
    
    	scia_init();  // Init SCI-A
    	scib_init();  // Init SCI-B
    
    	// Demarrer tous les PWMs en UP/DOWN
    	EPwm1Regs.TBCTL.bit.CTRMODE = 0x2;
    	EPwm2Regs.TBCTL.bit.CTRMODE = 0x2;
    
    	PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
    	PieCtrlRegs.PIEIER9.bit.INTx1=1;     // PIE Group 9, int1
    	PieCtrlRegs.PIEIER9.bit.INTx2=1;     // PIE Group 9, INT2
    	PieCtrlRegs.PIEIER9.bit.INTx3=1;     // PIE Group 9, INT3
    	PieCtrlRegs.PIEIER9.bit.INTx4=1;     // PIE Group 9, INT4
    	IER |= 0x100;	// Enable CPU INT
    	PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //autoriser l'interruption ADC
    	EINT;   // Enable Global interrupt INTM
    	//ERTM;   // Enable Global realtime interrupt DBGM
    	/*------------------------------------------------------------------------**
    	**			  				FLASH_API								  	  **
    	**------------------------------------------------------------------------*/
    	// Assuming PLLSTS[CLKINDIV] = 0 (default on XRSn).  If it is not
       // 0, then the PLLCR cannot be written to.
       // Make sure the PLL is not running in limp mode
       if (SysCtrlRegs.PLLSTS.bit.MCLKSTS != 1)
       {
    	   if (SysCtrlRegs.PLLCR.bit.DIV != PLLCR_VALUE)
    	   {
    
    
    		  EALLOW;
    		  // Before setting PLLCR turn off missing clock detect
    		  SysCtrlRegs.PLLSTS.bit.MCLKOFF = 1;
    		  SysCtrlRegs.PLLCR.bit.DIV = PLLCR_VALUE;
    		  EDIS;
    
    		  // Wait for PLL to lock.
    		  // During this time the CPU will switch to OSCCLK/2 until
    		  // the PLL is stable.  Once the PLL is stable the CPU will
    		  // switch to the new PLL value.
    		  //
    		  // This time-to-lock is monitored by a PLL lock counter.
    		  //
    		  // The watchdog should be disabled before this loop, or fed within
    		  // the loop.
    
    		  EALLOW;
    		  SysCtrlRegs.WDCR= 0x0068;
    		  EDIS;
    
    		  // Wait for the PLL lock bit to be set.
    		  // Note this bit is not available on 281x devices.  For those devices
    		  // use a software loop to perform the required count.
    
    		  while(SysCtrlRegs.PLLSTS.bit.PLLLOCKS != 1) { }
    
    		  EALLOW;
    		  SysCtrlRegs.PLLSTS.bit.MCLKOFF = 0;
    		  EDIS;
    	   }
       }
    
       // If the PLL is in limp mode, shut the system down
       else
       {
    	  // Replace this line with a call to an appropriate
    	  // SystemShutdown(); function.
    	  asm("        ESTOP0");
       }
    
    
       /*------------------------------------------------------------------
    	 Initalize Flash_CPUScaleFactor.
       ------------------------------------------------------------------*/
       Flash_CPUScaleFactor = SCALE_FACTOR;
       /*------------------------------------------------------------------
    	 Initalize Flash_CallbackPtr.
       ------------------------------------------------------------------*/
       Flash_CallbackPtr = &MyCallbackFunction;
    
    }
    
    
    
    /*------------------------------------------------------------------------**
    **						 		End of file								  **
    **------------------------------------------------------------------------*/
    
    

  • /*
    // TI File $Revision: /main/9 $
    // Checkin $Date: August 28, 2007   11:23:38 $
    //###########################################################################
    //
    // FILE:	F28335.cmd
    //
    // TITLE:	Linker Command File For F28335 Device
    //
    //###########################################################################
    // $TI Release: DSP2833x Header Files V1.02 $
    // $Release Date: October 5, 2007 $
    //###########################################################################
    */
    
    /* ======================================================
    // For Code Composer Studio V2.2 and later
    // ---------------------------------------
    // In addition to this memory linker command file, 
    // add the header linker command file directly to the project. 
    // The header linker command file is required to link the
    // peripheral structures to the proper locations within 
    // the memory map.
    //
    // The header linker files are found in <base>\DSP2833x_Headers\cmd
    //   
    // For BIOS applications add:      DSP2833x_Headers_BIOS.cmd
    // For nonBIOS applications add:   DSP2833x_Headers_nonBIOS.cmd    
    ========================================================= */
    
    /* ======================================================
    // For Code Composer Studio prior to V2.2
    // --------------------------------------
    // 1) Use one of the following -l statements to include the 
    // header linker command file in the project. The header linker
    // file is required to link the peripheral structures to the proper 
    // locations within the memory map                                    */
    
    /* Uncomment this line to include file only for non-BIOS applications */
    /* -l DSP2833x_Headers_nonBIOS.cmd */
    
    /* Uncomment this line to include file only for BIOS applications */
    /* -l DSP2833x_Headers_BIOS.cmd */
    
    /* 2) In your project add the path to <base>\DSP2833x_headers\cmd to the
       library search path under project->build options, linker tab, 
       library search path (-i).
    /*========================================================= */
    
    /* Define the memory block start/length for the F28335  
       PAGE 0 will be used to organize program sections
       PAGE 1 will be used to organize data sections
    
        Notes: 
              Memory blocks on F28335 are uniform (ie same
              physical memory) in both PAGE 0 and PAGE 1.  
              That is the same memory region should not be
              defined for both PAGE 0 and PAGE 1.
              Doing so will result in corruption of program 
              and/or data. 
              
              L0/L1/L2 and L3 memory blocks are mirrored - that is
              they can be accessed in high memory or low memory.
              For simplicity only one instance is used in this
              linker file. 
              
              Contiguous SARAM memory blocks can be combined 
              if required to create a larger memory block. 
     */
    
    
    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 = 0x001000     /* on-chip RAM block L1 */
       RAML2       : origin = 0x00A000, length = 0x001000     /* on-chip RAM block L2 */
       RAML3       : origin = 0x00B000, length = 0x001000     /* on-chip RAM block L3 */
       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 */
       ZONE0D       : origin = 0x004000, length = 0x001000     /* XINTF zone 0 */
      
       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
    {
     	Flash28_API:
       {
            -l Flash28335_API_V210.lib(.econst)
            -l Flash28335_API_V210.lib(.text)
       }                   LOAD = FLASHF,
                           RUN = RAML1,
                           LOAD_START(_Flash28_API_LoadStart),
                           LOAD_END(_Flash28_API_LoadEnd),
                           RUN_START(_Flash28_API_RunStart),
                           PAGE = 0
       /* Allocate program areas: */
       .cinit              : > FLASHA      PAGE = 0
       .pinit              : > FLASHA,     PAGE = 0
       .text               : > FLASHA      PAGE = 0
    /*   .text			   : LOAD = FLASHE,
    						 RUN = RAML1,
    						 LOAD_START(_textLoadStart),
                             LOAD_END(_textLoadEnd),
                             RUN_START(_textRunStart),
    						 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 
       IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD 
       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
    	ExtDPRamData        : > ZONE0D,    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
    
    }
    
    /*
    //===========================================================================
    // End of file.
    //===========================================================================
    */
    
    

    ...

    /*----------------------------------------------------------------------**
    ** File:		SaveFlash.c												**
    ** Author:		Simon Cantin, IAI										**
    ** Description: Sauvegarde dans la flash								**
    **																		**
    **----------------------------------------------------------------------*/
    
    #include "SaveFlash.h"
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Ecriture dans la FLASH
    #pragma CODE_SECTION(saveFlash,"ramfuncs");
    
    void saveFlash(void)
    {
    	Uint16  Status;
    	Uint16  *Flash_ptr;     // Pointer to a location in flash
    	Uint32  Length;         // Number of 16-bit values to be programmed
    	float32 Version;        // Version of the API in floating point
    	Uint16  VersionHex;     // Version of the API in decimal encoded hex
    
    	PieCtrlRegs.PIECTRL.bit.ENPIE = 0;   // Enable the PIE block
    	erreurFlash = 0;
    	/*------------------------------------------------------------------
    	  Toggle Test
    
    	  The toggle test is run to verify the frequency configuration of
    	  the API functions.
    
    	  The selected pin will toggle at 10kHz (100uS cycle time) if the
    	  API is configured correctly.
    
    	  Example_ToggleTest() supports common output pins. Other pins can be used
    	  by modifying the Example_ToggleTest() function or calling the Flash_ToggleTest()
    	  function directly.
    
    	  Select a pin that makes sense for the hardware platform being used.
    
    	  This test will run forever and not return, thus only run this test
    	  to confirm frequency configuration and not during normal API use.
    	------------------------------------------------------------------*/
    
    	   // Example: Toggle GPIO0
    	   // Example_ToggleTest(0);
    
    	   // Example: Toggle GPIO10
    	   // Example_ToggleTest(10);
    
    	   // Example: Toggle GPIO15
    	   // Example_ToggleTest(15);
    
    	   // Example: Toggle GPIO31
    	   // Example_ToggleTest(31);
    
    	   // Example: Toggle GPIO34
    	   //Example_ToggleTest((Uint16)(34));
    	/*------------------------------------------------------------------
    	  Check the version of the API
    
    	  Flash_APIVersion() returns the version in floating point.
    	  FlashAPIVersionHex() returns the version as a decimal encoded hex.
    
    	  FlashAPIVersionHex() can be used to avoid processing issues
    	  associated with floating point values.
    	------------------------------------------------------------------*/
    	   VersionHex = Flash_APIVersionHex();
    	   if(VersionHex != 0x0210)
    	   {
    	       // Unexpected API version
    	       // Make a decision based on this info.
    	       asm("    ESTOP0");
    	   }
    
    
    	   Version = Flash_APIVersion();
    	   if(Version != (float32)2.10)
    	   {
    	       // Unexpected API version
    	       // Make a decision based on this info.
    	       asm("    ESTOP0");
    	   }
    	/*------------------------------------------------------------------
    	  Before programming make sure the sectors are Erased.
    
    	------------------------------------------------------------------*/
    
    	   // Example: Erase Sector B,C
    	   // Sectors A and D have the example code so leave them
    	   // programmed.
    
    	   // SECTORB, SECTORC are defined in Flash2833x_API_Library.h
    	   Status = Flash_Erase(SECTORB,&FlashStatus);
    	   if(Status != STATUS_SUCCESS)
    	   {
    	       Error_Flash(Status);
    	   }
    	   /*------------------------------------------------------------------
    	     Program Flash Examples
    
    	   ------------------------------------------------------------------*/
    
    	   // A buffer can be supplied to the program function.  Each word is
    	   // programmed until the whole buffer is programmed or a problem is
    	   // found.  If the buffer goes outside of the range of OTP or Flash
    	   // then nothing is done and an error is returned.
    
    
    	       // Example: Program 0x400 values in Flash Sector B
    
    	       // In this case just fill a buffer with data to program into the flash.
    	       /*for(i=0;i<WORDS_IN_FLASH_BUFFER;i++)
    	       {
    	    	   bufferSaveFlash[i] = 0x100+i;
    	       }*/
    
    	       Flash_ptr = Sector[1].StartAddr;
    	       Length = LENGTH_BUFFER;
    	       Status = Flash_Program(Flash_ptr,(Uint16*) parametresFloat,Length,&FlashStatus);
    	       if(Status != STATUS_SUCCESS)
    	       {
    	    	   Error_Flash(Status);
    	       }
    
    	       // Verify the values programmed.  The Program step itself does a verify
    	       // as it goes.  This verify is a 2nd verification that can be done.
    	       /*Status = Flash_Verify(Flash_ptr,bufferSaveFlash,Length,&FlashStatus);
    	       if(Status != STATUS_SUCCESS)
    	       {
    	    	   Error_Flash(Status);
    	       }*/
    	 PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
    }
    #pragma CODE_SECTION(Error_Flash,"ramfuncs");
    void Error_Flash(Uint16 Status)
    {
    	erreurFlash += 1;
    }
    /*------------------------------------------------------------------
      Simple memory copy routine to move code out of flash into SARAM
    -----------------------------------------------------------------*/
    
    void Example_MemCopy(Uint16 *SourceAddr, Uint16* SourceEndAddr, Uint16* DestAddr)
    {
        while(SourceAddr < SourceEndAddr)
        {
           *DestAddr++ = *SourceAddr++;
        }
        return;
    }
    void MyCallbackFunction(void)
    {
    	// envoie au PC si la sauvegarde s'est bien d�roul�e (erreurFlash)
    }
    void Example_ToggleTest(Uint16 PinNumber)
    {
           Uint32 mask;
    
           // Before calling the Toggle Test, we must setup
           // the MUX and DIR registers.
    
           if(PinNumber > (Uint16)34)
           {
               asm("    ESTOP0");  // Stop here. Invalid option.
               for(;;);
           }
    
           // Pins GPIO16-GPIO31
           else if(PinNumber >= 32)
           {
               EALLOW;
               mask = ~( ((Uint32)1 << (PinNumber-16)*2) | ((Uint32)1 << (PinNumber-32)*2+1) );
               GpioCtrlRegs.GPBMUX1.all &= mask;
               GpioCtrlRegs.GPBDIR.all = GpioCtrlRegs.GPADIR.all | ((Uint32)1 << (PinNumber-32) );
               Flash_ToggleTest(&GpioDataRegs.GPBTOGGLE.all, ((Uint32)1 << PinNumber) );
               EDIS;
           }
    
           // Pins GPIO16-GPIO31
           else if(PinNumber >= 16)
           {
               EALLOW;
               mask = ~( ((Uint32)1 << (PinNumber-16)*2) | ((Uint32)1 << (PinNumber-16)*2+1) );
               GpioCtrlRegs.GPAMUX2.all &= mask;
               GpioCtrlRegs.GPADIR.all = GpioCtrlRegs.GPADIR.all | ((Uint32)1 << PinNumber);
               Flash_ToggleTest(&GpioDataRegs.GPATOGGLE.all, ((Uint32)1 << PinNumber) );
               EDIS;
           }
    
           // Pins GPIO0-GPIO15
           else
           {
               EALLOW;
               mask = ~( ((Uint32)1 << PinNumber*2) | ((Uint32)1 << PinNumber*2+1 ));
               GpioCtrlRegs.GPAMUX1.all &= mask;
               GpioCtrlRegs.GPADIR.all = GpioCtrlRegs.GPADIR.all | ((Uint32)1 << PinNumber);
               EDIS;
               Flash_ToggleTest(&GpioDataRegs.GPATOGGLE.all, ((Uint32)1 << PinNumber) );
           }
    
    }
    
    //===========================================================================
    // End of file.
    //===========================================================================
    

  • Hi Simon!

    Thanks. Try this project for base or try only CMD-file included to it 7585.flash_example.zip.

    Regards,

    Igor

  • Hi,

    I try the example and it works. I try it with my cmd file and it doesn't work. I try the example cmd file with my project and it still doesn't work.

    CCS give a warning for this in the cmd file example : 

    Description Resource Path Location Type
    #10068-D no matching section f28335_flash_prog.cmd /CLET100kW line 147 C/C++ Problem

    boot > FLASHA PAGE = 0
    {
    rts2800_fpu32.lib<boot.obj> (.text)

    }

    Regards

    Simon

  • Hi Simon!

    1 Try this new CMD with your project 

    /*
    //###########################################################################
    //
    // FILE:	F28335_flash_prog.cmd
    //
    // TITLE:	Linker Command File For F28335 Device
    //
    //###########################################################################
    // $TI Release: F28335 API Release V2.10 $
    // $Release Date: August 18, 2008 $
    //###########################################################################
    */
    
    /* ======================================================
    // For Code Composer Studio V2.2 and later
    // ---------------------------------------
    // In addition to this memory linker command file, 
    // add the header linker command file directly to the project. 
    // The header linker command file is required to link the
    // peripheral structures to the proper locations within 
    // the memory map.
    //
    // The header linker files are found in <base>\DSP2833x_Headers\cmd
    //   
    // For BIOS applications add:      DSP2833x_Headers_BIOS.cmd
    // For nonBIOS applications add:   DSP2833x_Headers_nonBIOS.cmd    
    ========================================================= */
    
    /* ======================================================
    // For Code Composer Studio prior to V2.2
    // --------------------------------------
    // 1) Use one of the following -l statements to include the 
    // header linker command file in the project. The header linker
    // file is required to link the peripheral structures to the proper 
    // locations within the memory map                                    */
    
    /* Uncomment this line to include file only for non-BIOS applications */
    /* -l DSP2833x_Headers_nonBIOS.cmd */
    
    /* Uncomment this line to include file only for BIOS applications */
    /* -l DSP2833x_Headers_BIOS.cmd */
    
    /* 2) In your project add the path to <base>\DSP2833x_headers\cmd to the
       library search path under project->build options, linker tab, 
       library search path (-i).
    /*========================================================= */
    
    /* Define the memory block start/length for the F28335  
       PAGE 0 will be used to organize program sections
       PAGE 1 will be used to organize data sections
    
        Notes: 
              Memory blocks on F28335 are uniform (ie same
              physical memory) in both PAGE 0 and PAGE 1.  
              That is the same memory region should not be
              defined for both PAGE 0 and PAGE 1.
              Doing so will result in corruption of program 
              and/or data. 
              
              L0/L1/L2 and L3 memory blocks are mirrored - that is
              they can be accessed in high memory or low memory.
              For simplicity only one instance is used in this
              linker file. 
              
              Contiguous SARAM memory blocks can be combined 
              if required to create a larger memory block. 
     */
    
    
    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 = 0x001000     /* on-chip RAM block L1 */
       RAML2       : origin = 0x00A000, length = 0x001000     /* on-chip RAM block L2 */
       RAML3       : origin = 0x00B000, length = 0x001000     /* on-chip RAM block L3 */
       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: */
       /* The Flash API functions can be grouped together as shown below.
          The defined symbols _Flash28_API_LoadStart, _Flash28_API_LoadEnd
          and _Flash28_API_RunStart are used to copy the API functions out
          of flash memory and into SARAM */
    
       Flash28_API:
       {
            -lFlash28335_API_V210.lib(.econst) 
            -lFlash28335_API_V210.lib(.text)
       }                   LOAD = FLASHD, 
                           RUN = RAML0,  
                           LOAD_START(_Flash28_API_LoadStart),
                           LOAD_END(_Flash28_API_LoadEnd),
                           RUN_START(_Flash28_API_RunStart),
                           PAGE = 0
       .cinit              : > FLASHA      PAGE = 0
       .pinit              : > FLASHA,     PAGE = 0
    /*  
     boot 		  > FLASHA PAGE = 0
       {
    		rts2800_fpu32.lib<boot.obj> (.text)
    
       }
    */
       .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 
       IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD 
       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
    	ExtDPRamData        : > ZONE0,    PAGE = 0
    
    
       /* .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
    
    }
    
    /*
    //===========================================================================
    // End of file.
    //===========================================================================
    */
    
    

    2 Would you like to take my example for basis (If you are already convinced that it works)?

    Regards,

    Igor

  • Hi,

    The new CMD file doesn't work.

    I see this warning in my project: 

    warning #16002-D: build attribute vendor section TI missing in   "C:/Users/simon.cantin/Documents/iAi/CLET/CarteDeCommande/SoftDSP/Flash28335

    Is that a clue?

    Otherwise I restart from the example.

    Regards

    Simon

  • Hi,

    I restart from the example and now the flash API works. 

    But I have another problem, when I allow the interrupt of Timer2, the program go to illegal_isr (Timer0 interrupt works). If I do the initialisation step by step, it works. I try to increase the stack but it did not change anything.

    Any idea?

    Thanks

    Simon

  • Hi!

    I'm not sure but it seems there was the similar issue in this thread http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/282091.aspx?pi177899=1. Please pay attention on all posts of this thread.

    Regards,

    Igor

  • I took my first project. In InitPieVectTable(), I just comment the line PieCtrlRegs.PIECTRL.bit.ENPIE = 1; and now it works. I think there was an interrupt during the initialisation.

    Simon