之前一直是按照FLASH_API手册上的流程来操作,使用ecc option选项来插入错误,但是移植代码之后尝试了几次都会出现一些莫名其妙的问题,有时会崩溃报错,有些时候会在一烧录就插入错误,然后也没有找到解决的方法。在E2E论坛上求助之后,今天收到了回复:
没想到C2000里面还能存在专门用于ecc引入错误的c文件。sdl_ex_flash_ecc_test.c的内容如下:
//
// Included Files
//
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define PASS 0U
#define FAIL 1U
#define ISR_LOOP_TIMEOUT 0x3U
#define MASK_ALL_BUT_FLASH_ERR 0x3F6UL
//
// Flash ECC Logic test values
//
#define TEST_FLASH_DATAL ((uint32_t)(TEST_FLASH_DATA64))
#define TEST_FLASH_DATAH ((uint32_t)(TEST_FLASH_DATA64 >> 32))
#define TEST_FLASH_ADDR 0x00090000UL
#define TEST_FLASH_DATA64 0xFEDCBA0987654321ULL
//
// Typedefs
//
typedef enum
{
TEST_ECC_BLOCK_LOW = 0x00, //!< Low 64-bit block
TEST_ECC_BLOCK_HIGH = 0x02 //!< High 64-bit block
} ECCBlock;
//
// Globals
//
uint16_t calcECC;
uint32_t result = FAIL;
volatile bool nmiISRFlag;
uint16_t nmiStatus;
volatile bool errorISRFlag;
uint16_t errorStatus;
uint16_t errorCount;
uint32_t errorType;
uint64_t dataOut;
//
// Function Prototypes
//
__interrupt void nmiISR(void);
__interrupt void corrErrorISR(void);
uint16_t runCorrectableDataErrorTest(void);
uint16_t runCorrectableECCErrorTest(void);
uint16_t runUncorrectableErrorTest(void);
void testECCBlock(uint64_t data, uint32_t address, ECCBlock eccBlock,
uint16_t ecc);
#pragma CODE_SECTION(testECCBlock, ".TI.ramfunc");
uint16_t calculateECC(uint32_t address, uint64_t data);
//
// Main
//
void main(void)
{
uint16_t failCount;
//
// Initialize device clock and peripherals.
//
Device_init();
//
// 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();
//
// Clear all the NMI and Flash error status flags.
//
EALLOW;
HWREG(FLASH0ECC_BASE + FLASH_O_ERR_STATUS_CLR) = 0xFFFFFFFFU;
HWREG(FLASH0ECC_BASE + FLASH_O_ERR_INTCLR) = 0xFFFFFFFFU;
EDIS;
SysCtl_clearAllNMIFlags();
//
// Plug the NMI and Flash correctable error ISRs.
//
Interrupt_register(INT_NMI, &nmiISR);
Interrupt_register(INT_FLASH_CORR_ERR, corrErrorISR);
Interrupt_enable(INT_FLASH_CORR_ERR);
//
// Enabling the NMI global interrupt (typically already enabled by boot ROM
// or GEL file).
//
SysCtl_enableNMIGlobalInterrupt();
//
// Enable Global Interrupt (INTM) and Real Time interrupt (DBGM).
//
EINT;
ERTM;
//
// Calculate ECC on test data.
//
calcECC = calculateECC(TEST_FLASH_ADDR, TEST_FLASH_DATA64);
//
// Enable ECC.
//
Flash_enableECC(FLASH0ECC_BASE);
//
// Test detection of correctable ECC errors in Flash data bits.
//
failCount = runCorrectableDataErrorTest();
//
// Test detection of correctable ECC errors in Flash ECC bits.
//
failCount += runCorrectableECCErrorTest();
//
// Test detection of uncorrectable ECC errors in Flash.
//
failCount += runUncorrectableErrorTest();
//
// Status of a successful handling of the ECC errors.
//
if(failCount != 0U)
{
result = FAIL;
}
else
{
result = PASS;
}
//
// Loop here and check results in the CCS Expressions view.
//
while(1);
}
//
// nmiISR - The interrupt service routine called when the NMI is generated
// on an uncorrectable Flash ECC error.
//
__interrupt void nmiISR(void)
{
//
// Set a flag indicating the NMI ISR occurred and get the NMI status.
//
nmiISRFlag = true;
nmiStatus = SysCtl_getNMIFlagStatus();
//
// Record the error test status.
//
errorStatus = Flash_getECCTestStatus(FLASH0ECC_BASE);
//
// Clear all the flags.
//
EALLOW;
HWREG(FLASH0ECC_BASE + FLASH_O_ERR_STATUS_CLR) = 0xFFFFFFFFU;
EDIS;
Flash_clearUncorrectableInterruptFlag(FLASH0ECC_BASE);
SysCtl_clearAllNMIFlags();
}
//
// corrErrorISR - The interrupt service routine called when the correctable
// error count hits the configured interrupt threshold.
//
__interrupt void corrErrorISR(void)
{
//
// Set a flag indicating the RAM error ISR occurred.
//
errorISRFlag = true;
//
// Record the type of error injected, the status flags, the corrected data,
// and the number of single-bit ECC errors detected.
//
errorType = Flash_getECCTestSingleBitErrorType(FLASH0ECC_BASE);
errorStat

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



