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.
I was wondering how I could program the mcu flash.
I have imported the 2802x_FlashAPI_BootROMSymbols_v2.01.lib into my project, and included the flash api v201a includes.
I called the version check in my code and I was able to get the 2.01 as the floating value.
But when I try to program the flash it halts. I can see that I am clearing the flash at the particular location I am trying to write at (Sector C) and I am doing a simple program flash as seen in the flash api example:
//############################################################################# // // File: Example_F2802xLedBlink.c // // Title: F2802x LED Blink Getting Started Program. // //! \addtogroup example_list //! <h1>LED Blink</h1> //! //! This example configures CPU Timer0 for a 500 msec period, and toggles //! the GPIO0-4 LEDs once per interrupt. For testing purposes, this example //! also increments a counter each time the timer asserts an interrupt. //! //! Watch Variables: //! - interruptCount //! //! Monitor the GPIO0-4 LEDs blink on (for 500 msec) and off (for 500 msec) //! on the 2802x0 control card. // //############################################################################# // $TI Release: F2802x Support Library v230 $ // $Release Date: Fri May 8 07:43:05 CDT 2015 $ // $Copyright: Copyright (C) 2008-2015 Texas Instruments Incorporated - // http://www.ti.com/ ALL RIGHTS RESERVED $ //############################################################################# #include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include "Flash2802x_API_Library.h" //#include "Flash2802x_API_Config.h" //#include "F2802x_BootVars.h" #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/timer.h" #include "f2802x_common/include/wdog.h" // Prototype statements for functions found within this file. __interrupt void cpu_timer0_isr(void); #define Flash_API #ifdef Flash_API uint16_t interruptCount = 0; uint16_t myValues = 0x0; typedef struct { Uint16 *StartAddr; Uint16 *EndAddr; } SECTOR; #define WORDS_IN_FLASH_BUFFER 0x010 uint16_t Buffer[WORDS_IN_FLASH_BUFFER]; uint16_t i; uint16_t Status; uint16_t *Flash_ptr; // Pointer to a location in flash uint16_t Length; // Number of 16-bit values to be programmed float32 Version; // Version of the API in floating point uint16_t VersionHex; // Version of the API in decimal encoded hex FLASH_ST FlashStatus; float version; SECTOR Sector[4] = { (Uint16 *)0x3F6000,(Uint16 *)0x3F7FFF, (Uint16 *)0x3F4000,(Uint16 *)0x3F5FFF, (Uint16 *)0x3F2000,(Uint16 *)0x3F3FFF, (Uint16 *)0x3F0000,(Uint16 *)0x3F1FFF, }; #endif ADC_Handle myAdc; CLK_Handle myClk; FLASH_Handle myFlash; GPIO_Handle myGpio; PIE_Handle myPie; TIMER_Handle myTimer; void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application 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)); myTimer = TIMER_init((void *)TIMER0_BASE_ADDR, sizeof(TIMER_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_7, (intVec_t)&cpu_timer0_isr); // Configure CPU-Timer 0 to interrupt every 500 milliseconds: // 60MHz CPU Freq, 50 millisecond Period (in uSeconds) // ConfigCpuTimer(&CpuTimer0, 60, 500000); TIMER_stop(myTimer); TIMER_setPeriod(myTimer, 50 * 500000); TIMER_setPreScaler(myTimer, 0); TIMER_reload(myTimer); TIMER_setEmulationMode(myTimer, TIMER_EmulationMode_StopAfterNextDecrement); TIMER_enableInt(myTimer); TIMER_start(myTimer); // Configure GPIO 0-3 as outputs GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_0_Mode_GeneralPurpose); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_0_Mode_GeneralPurpose); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_0_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output); GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output); GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output); GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output); GPIO_setLow(myGpio, GPIO_Number_0); GPIO_setHigh(myGpio, GPIO_Number_1); GPIO_setLow(myGpio, GPIO_Number_2); GPIO_setHigh(myGpio, GPIO_Number_3); // Enable CPU INT1 which is connected to CPU-Timer 0: CPU_enableInt(myCpu, CPU_IntNumber_1); // Enable TINT0 in the PIE: Group 1 interrupt 7 PIE_enableTimer0Int(myPie); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); #ifdef Flash_API version = Flash_APIVersion(); Flash_ptr = Sector[2].StartAddr; i = 0xA5A5; Length = 1; Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus); // Length = 0x001; // Status = Flash2802x_Program(Flash_ptr,Buffer,Length,&FlashStatus); myValues = (uint16_t)(*((uint16_t *)(0x3F4000))); #endif for(;;) { __asm(" NOP"); } } __interrupt void cpu_timer0_isr(void) { interruptCount++; // Toggle GPIOs GPIO_toggle(myGpio, GPIO_Number_0); GPIO_toggle(myGpio, GPIO_Number_1); GPIO_toggle(myGpio, GPIO_Number_2); GPIO_toggle(myGpio, GPIO_Number_3); // Acknowledge this interrupt to receive more interrupts from group 1 PIE_clearInt(myPie, PIE_GroupNumber_1); }
After it halts it resets all the flash sectors to 0x0000. Am i doing something wrong ?
Also, if I am using the bootROM library, i do not need to add any of the sections in my .cmd file, is this correct ?
Please advise how I could write one word to the flash sector C.
Regards,
Rajan Joshi
Are you using below example project found in controlSuite? Also, have you made any changes?
<controlSUITE>\libs\utilities\flash_api\2802x\v201a\example_ccsv5
Regards,
Manoj
Rajan,
1) Are you executing the Flash API functions from RAM (or) flash?
2) Did you single step through the code in assembly mode and find which instruction is causing the error? I'm wondering whether you are executing illegal opcode
3) Did you make sure to follow all the recommendations provided in the documentation in example?
Regards,
Manoj