Other Parts Discussed in Thread: C2000WARE

使用的CMD文件为2838x_FLASH_Ink_cpu1.cmd
MEMORY
{
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, 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 = 0x080002, length = 0x001FFE /* 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 = 0x001FF0 /* on-chip Flash */
// FLASH13_RSVD : origin = 0x0BFFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
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, ALIGN(8)
.text : >> FLASH1 | FLASH2 | FLASH3 | FLASH4, ALIGN(8)
.cinit : > FLASH4, ALIGN(8)
.switch : > FLASH1, ALIGN(8)
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMM1
#if defined(__TI_EABI__)
.init_array : > FLASH1, ALIGN(8)
.bss : > RAMLS5
.bss:output : > RAMLS3
.bss:cio : > RAMLS5
.data : > RAMLS5
.sysmem : > RAMLS5
/* Initalized sections go in Flash */
.const : > FLASH5, ALIGN(8)
#else
.pinit : > FLASH1, ALIGN(8)
.ebss : > RAMLS5
.esysmem : > RAMLS5
.cio : > RAMLS5
/* Initalized sections go in Flash */
.econst : >> FLASH4 | FLASH5, ALIGN(8)
#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
/* The following section definition are for SDFM examples */
Filter_RegsFile : > RAMGS0
Filter1_RegsFile : > RAMGS1, fill=0x1111
Filter2_RegsFile : > RAMGS2, fill=0x2222
Filter3_RegsFile : > RAMGS3, fill=0x3333
Filter4_RegsFile : > RAMGS4, fill=0x4444
Difference_RegsFile : >RAMGS5, fill=0x3333
#if defined(__TI_EABI__)
.TI.ramfunc : {} LOAD = FLASH3,
RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
ALIGN(8)
#else
.TI.ramfunc : {} LOAD = FLASH3,
RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
ALIGN(8)
#endif
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
测试文件为driverlib\f2838x\examples\c28x\flash\flashapi_ex1_programming.c
//#############################################################################
//
// FILE: flashapi_ex1_programming.c
//
// TITLE: Flash programming example
//
//! \addtogroup driver_example_list
//! <h1> Flash Programming with AutoECC, DataAndECC, DataOnly and EccOnly </h1>
//!
//! This example demonstrates how to program Flash using API's following options
//! 1. AutoEcc generation
//! 2. DataOnly and EccOnly
//! 3. DataAndECC
//!
//! \b External \b Connections \n
//! - None.
//!
//! \b Watch \b Variables \n
//! - None.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include "driverlib.h"
#include "device.h"
//
// Include Flash API include file
//
#include "F021_F2838x_C28x.h"
// Include Flash API example header file
//
#include "flash_programming_f2838x_c28x.h"
//
// Defines
//
//
// Length (in 16-bit words) of data buffer used for program
//
#define WORDS_IN_FLASH_BUFFER 0x100
//
// Globals
//
//
// Data Buffers used for program operation using the flash API program function
//
#pragma DATA_SECTION(Buffer,"DataBufferSection");
uint16 Buffer[WORDS_IN_FLASH_BUFFER];
uint32 *Buffer32 = (uint32 *)Buffer;
//
// Prototype of the functions used in this example
//
void Example_Error(Fapi_StatusType status);
void Example_Done(void);
void Example_CallFlashAPI(void);
void FMSTAT_Fail(void);
void ECC_Fail(void);
void Example_EraseSector(void);
void Example_ProgramUsingAutoECC(void);
void Example_ProgramUsingDataOnlyECCOnly(void);
void Example_ProgramUsingDataAndECC(void);
//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
// Copy the Flash initialization code from Flash to RAM
// Copy the Flash API from Flash to RAM
// Configure Flash wait-states, fall back power mode, performance features
// and ECC
//
Device_init();
//
// Initialize GPIO
//
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();
//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;
//
// At 200MHz, execution wait-states for external oscillator is 3. Modify the
// wait-states when the system clock frequency is changed.
//
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, 3);
//
// Pump access must be gained by the core using pump semaphore
//
#ifdef CPU1
Flash_claimPumpSemaphore(FLASH_CPU1_WRAPPER);
#elif defined(CPU2)
Flash_claimPumpSemaphore(FLASH_CPU2_WRAPPER);
#endif
//
// Flash API functions should not be executed from the same bank on which
// erase/program operations are in progress.
// Also, note that there should not be any access to the Flash bank on
// which erase/program operations are in progress. Hence below function
// is mapped to RAM for execution.
//
Example_CallFlashAPI();
//
// Release the pump access
//
Flash_releasePumpSemaphore();
//
// Example is done here
//
Example_Done();
}
//*****************************************************************************
// Example_CallFlashAPI
//
// This function will interface to the flash API.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_CallFlashAPI, ".TI.ramfunc");
#endif
void Example_CallFlashAPI(void)
{
uint16 i = 0;
Fapi_StatusType oReturnCheck;
//
// Initialize the Flash API by providing the Flash register base address
// and operating frequency(in MHz).
// This function is required to initialize the Flash API based on System
// frequency before any other Flash API operation can be performed.
// This function must also be called whenever System frequency or RWAIT is
// changed.
//
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS,
DEVICE_SYSCLK_FREQ/1000000U);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Initialize the Flash banks and FMC for erase and program operations.
// Fapi_setActiveFlashBank() function sets the Flash banks and FMC for
// further Flash operations to be performed on the banks.
//
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Fill a buffer with data to program into the flash.
//
for(i=0; i < WORDS_IN_FLASH_BUFFER; i++)
{
Buffer[i] = i;
}
//
// Program the sector using AutoECC option
//
Example_ProgramUsingAutoECC();
//
// Program the sector using DataOnly and ECCOnly options
//
Example_ProgramUsingDataOnlyECCOnly();
//
// Erase the sector before programming
//
Example_EraseSector();
//
// Program the sector using DataAndECC option
//
Example_ProgramUsingDataAndECC();
//
// Erase the sector for cleaner exit from the example.
//
Example_EraseSector();
}
//*****************************************************************************
// Example_ProgramUsingAutoECC
//
// Example function to Program data in Flash using "AutoEccGeneration" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingAutoECC, ".TI.ramfunc");
#endif
void Example_ProgramUsingAutoECC(void)
{
uint32 u32Index = 0;
uint16 i = 0;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// A data buffer of max 8 16-bit words can be supplied to the program
// function.
// Each word is programmed until the whole buffer is programmed or a
// problem is found. However to program a buffer that has more than 8
// words, program function can be called in a loop to program 8 words for
// each loop iteration until the whole buffer is programmed.
//
// Remember that the main array flash programming must be aligned to
// 64-bit address boundaries and each 64 bit word may only be programmed
// once per write/erase cycle. Meaning the length of the data buffer
// (3rd parameter for Fapi_issueProgrammingCommand() function) passed
// to the program function can only be either 4 or 8.
//
// Program data in Flash using "AutoEccGeneration" option.
// When AutoEccGeneration option is used, Flash API calculates ECC for the
// given 64-bit data and programs it along with the 64-bit main array data.
// Note that any unprovided data with in a 64-bit data slice
// will be assumed as 1s for calculating ECC and will be programmed.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// Monitor ECC address for the sector below while programming with
// AutoEcc mode.
//
// In this example, the number of bytes specified in the flash buffer
// are programmed in the flash sector below along with auto-generated
// ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 8, u32Index+= 8)
{
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
8, 0, 0, Fapi_AutoEccGeneration);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
//Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
//
// Verify the programmed values. Check for any ECC errors.
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32+(i/2),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_ProgramUsingDataOnlyECCOnly
//
// Example function to Program data in Flash using "DataOnly" option and ECC
// using "EccOnly" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingDataOnlyECCOnly, ".TI.ramfunc");
#endif
void Example_ProgramUsingDataOnlyECCOnly(void)
{
uint32 u32Index = 0;
uint16 i = 0, ECC_B = 0, ECC_LB = 0, ECC_HB = 0;
uint64 *LData, *HData, dataLow, dataHigh;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Program data using "DataOnly" option and ECC using "EccOnly" option.
//
// When DataOnly option is used, Flash API will program only the data
// portion in Flash at the address specified.
//
// When EccOnly option is used, Flash API will program only the ECC portion
// in Flash ECC memory space (Flash main array address should be provided
// for this function and not the corresponding ECC address).
// Fapi_calculateEcc is used to calculate the corresponding ECC of the data.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// In this example, 0x100 bytes are programmed in Flash Sector6
// along with the specified ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 8, u32Index+= 8)
{
//
// Point LData to the lower 64 bit data
// and HData to the higher 64 bit data
//
LData = (uint64 *)(Buffer32 + i/2);
HData = (uint64 *)(Buffer32 + i/2 + 2);
//
// Calculate ECC for lower 64 bit and higher 64 bit data
//
ECC_LB = Fapi_calculateEcc(u32Index,*LData);
ECC_HB = Fapi_calculateEcc(u32Index+4,*HData);
ECC_B = ((ECC_HB<<8) | ECC_LB);
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
8, 0, 0, Fapi_DataOnly);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//Check FMSTAT and debug accordingly
FMSTAT_Fail();
}
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, 0, 0,
&ECC_B, 2, Fapi_EccOnly);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
Flash_enableECC(FLASH0ECC_BASE);
//
// Read back the programmed data to check if there are any ECC failures
//
dataLow = *(uint64 *)(u32Index);
Flash_ErrorStatus errorStatusLow = Flash_getLowErrorStatus(FLASH0ECC_BASE);
if((errorStatusLow != FLASH_NO_ERR) || (dataLow != *LData))
{
ECC_Fail();
}
dataHigh = *(uint64 *)(u32Index + 4);
Flash_ErrorStatus errorStatusHigh = Flash_getHighErrorStatus(FLASH0ECC_BASE);
if((errorStatusHigh != FLASH_NO_ERR) || (dataHigh != *HData))
{
ECC_Fail();
}
//
// Verify the programmed values. Check for any ECC errors.
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32+(i/2),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_ProgramUsingDataAndECC
//
// Example function to Program data in Flash using "DataAndEcc" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingDataAndECC, ".TI.ramfunc");
#endif
void Example_ProgramUsingDataAndECC(void)
{
uint32 u32Index = 0;
uint16 i = 0, ECC_B = 0, ECC_LB = 0, ECC_HB = 0;
uint64 *LData, *HData, dataLow, dataHigh;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Program data and ECC in Flash using "DataAndEcc" option.
// When DataAndECC option is used, Flash API will program both the supplied
// data and ECC in Flash at the address specified.
// Fapi_calculateEcc is used to calculate the corresponding ECC of the data.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// In this example, 0x100 bytes are programmed in Flash Sector6
// along with the specified ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 8, u32Index+= 8)
{
//
// Point LData to the lower 64 bit data
// and HData to the higher 64 bit data
//
LData = (uint64 *)(Buffer32 + i/2);
HData = (uint64 *)(Buffer32 + i/2 + 2);
//
// Calculate ECC for lower 64 bit and higher 64 bit data
//
ECC_LB = Fapi_calculateEcc(u32Index,*LData);
ECC_HB = Fapi_calculateEcc(u32Index+4,*HData);
ECC_B = ((ECC_HB<<8) | ECC_LB);
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
8, &ECC_B, 2, Fapi_DataAndEcc);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
Flash_enableECC(FLASH0ECC_BASE);
//
// Read back the programmed data to check if there are any ECC failures
//
dataLow = *(uint64 *)(u32Index);
Flash_ErrorStatus errorStatusLow = Flash_getLowErrorStatus(FLASH0ECC_BASE);
if((errorStatusLow != FLASH_NO_ERR) || (dataLow != *LData))
{
ECC_Fail();
}
dataHigh = *(uint64 *)(u32Index + 4);
Flash_ErrorStatus errorStatusHigh = Flash_getHighErrorStatus(FLASH0ECC_BASE);
if((errorStatusHigh != FLASH_NO_ERR) || (dataHigh != *HData))
{
ECC_Fail();
}
//
// Verify the programmed values. Check for any ECC errors.
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32+(i/2),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_EraseSector
//
// Example function to Erase data of a sector in Flash.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_EraseSector, ".TI.ramfunc");
#endif
void Example_EraseSector(void)
{
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Erase the sector that is programmed in the above example
// Erase Sector6
//
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_Sector6_start);
//
// Wait until FSM is done with erase sector operation
//
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// erase command to see if there are any erase operation related errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check Flash API documentation for FMSTAT and debug accordingly
// Fapi_getFsmStatus() function gives the FMSTAT register contents.
// Check to see if any of the EV bit, ESUSP bit, CSTAT bit or
// VOLTSTAT bit is set (Refer to API documentation for more details).
//
FMSTAT_Fail();
}
//
// Verify that Sector6 is erased
//
oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_Sector6_start,
Sector64KB_u32length,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for error info
//
Example_Error(oReturnCheck);
}
}
//******************************************************************************
// For this example, just stop here if an API error is found
//******************************************************************************
void Example_Error(Fapi_StatusType status)
{
//
// Error code will be in the status parameter
//
__asm(" ESTOP0");
}
//******************************************************************************
// For this example, once we are done just stop here
//******************************************************************************
void Example_Done(void)
{
__asm(" ESTOP0");
}
//******************************************************************************
// For this example, just stop here if FMSTAT fail occurs
//******************************************************************************
void FMSTAT_Fail(void)
{
__asm(" ESTOP0");
}
//******************************************************************************
// For this example, just stop here if ECC fail occurs
//******************************************************************************
void ECC_Fail(void)
{
__asm(" ESTOP0");
}
//
// End of File
//
BOOT MODE设置为FLASH启动
使用MCU063B-开发板


