📄 flash.c
字号:
printf("Flash Reading at [0x%08X - 0x%08X]...\n", sAddress, nAddress);
// Data Read
// *******************
//pData=memcpy(pData, (U32*) nAddress, nData);
//nDone = nData;
while (nWalk < nAddress)
{
i++;
if ((i & 0xFFFF) == 0)
{
printf("R");
}
*dWalk = *sWalk;
dWalk++;
sWalk++;
nWalk +=sizeof(*dWalk);
}
printf("\nFlash Read Complete\n");
return (U32*)sAddress;
}
// ***************************************************************************
//
// Function: FlashVerify
//
//
//
// Parameters: U32 rAddress RAM starting address
// U32 fAddress Flash starting address to be verified
// U32 nWords number of words to check
//
// Return Value: U32 Errors number of programming errors
// in word
//
// ***************************************************************************
U32 FlashVerify(U32 fAddress, U32 rAddress, U32 nWords)
{
U32 i;
U32 Errors = 0;
U32* fWalk;
U32* rWalk;
U32 nAddress;
fWalk = (U32*)fAddress;
rWalk = (U32*)rAddress;
nAddress = fAddress + (nWords - 1) * sizeof(*fWalk);
printf("Flash Verifing at [0x%08X - 0x%08X]...\n", fAddress, nAddress);
for (i = 0; i < nWords;i++)
{
if (*fWalk != *rWalk)
{
printf("Programming Error at 0x%08X\n", (U32)fWalk);
Errors++;
}
else
{
if ((i & 0xFFFF) == 0)
{
printf("S");
}
}
fWalk++;
rWalk++;
}
return Errors;
}
// ***************************************************************************
//
// Function: FlashLoader
//
//
//
// Parameters: U32 rAddress RAM starting address
// U32 fAddress Flash starting address to be programmmed
// U32 nWords number of words to write
//
// Return Value: void
//
// ***************************************************************************
void FlashLoader(U32 fAddress, U32 rAddress, U32 nWords)
{
U32 nAddress;
U32 Errors;
U32 hClk = 108;
U32 fClk = 54;
printf("\nStarting Flash Programming\n");
nAddress = fAddress + (nWords - 1) * sizeof(fAddress);
//BoardControlBurstMode(FALSE,fAddress,hClk,fClk);
NewFlashSectorErase(fAddress,nAddress);
FlashWrite(fAddress, (U32*)rAddress, nWords);
Errors = FlashVerify(fAddress,rAddress,nWords);
if (Errors)
{
printf("\nFlash Programming Error:\n");
printf("Total no. of Errors: %d words\n",Errors);
}
else
{
printf("\nThe Flash Program rewrite for lhy!!!\nProgramming Complete!!!\n");
}
return;
}
// ***************************************************************************
//
// Function: Flash_Full_Test - 32Mbytes
// Fill the SDRAM with a test pattern and then the
// Flash Routine copy them from RAM into the Flash
//
// Parameters: BOOL Burst BurstMode??
//
// Return Value: U32 Success Test Pass/Fail
//
// ***************************************************************************
BOOL Flash_Full_Test(BOOL Burst)
{
U32 SourceAddress = 0xC2000000;
U32 TargetAddress = 0xC8000000;
U32 WordSize = 8*1024*1024;
U32 Testpat = 0x55AA55AA;
U32 Error = 0;
U32 hClk = 108;
U32 fClk = 54;
BOOL BurstOn = TRUE;
BOOL Success;
printf("\nFlash Full Test\n");
// PLL setup: FCLK = 266MHz and HCLK = 133MHz
//*******************************************
printf("\n***PLL setup***\n");
SetPRESC(4);
SetBCLKDIV(10);
SetMcuPll(hClk * 2);
SetPRESC(1);
SetBCLKDIV(2);
ShowHCLK();
Memory_Fill_U32(SourceAddress,WordSize,Testpat);
BoardControlBurstMode(BurstOn,TargetAddress, hClk, fClk);
FlashChipErase(TargetAddress);
FlashWrite(TargetAddress, (U32*)SourceAddress, WordSize);
Error = MemCheck_U32(TargetAddress,WordSize,Testpat);
printf("\nFlash Full Test Complete\n");
return Error ? FALSE:TRUE;
}
// ***************************************************************************
//
// Function: Flash_Quick_Test - 1Mbytes at each bank
// Fill the internal RAM with a test pattern and then the
// Flash Routine copy this test pattern into the Flash
//
// Parameters: BOOL Burst BurstMode??
//
// Return Value: U32 Success Test Pass/Fail
//
// ***************************************************************************
BOOL Flash_Quick_Test(BOOL BurstOn)
{
U32 SourceAddress = 0xC2000000;
U32 TargetAddress = 0xC8000000;
U32 hClk = 133;
U32 fClk = 66;
U32 Bank_one = TargetAddress;
U32 Bank_two = Bank_one + (8*4*1024+31*32*1024)*4;
U32 Bank_three = Bank_two + (96*32*1024)*4;
U32 Bank_four = Bank_three + (96*32*1024)*4;
U32 WordSize = 0x40000;
U32 Testpat = 0x55AA55AA;
U32 Error = 0;
U32 Total_errors = 0;
U32 i = 0;
printf("\nFlash Quick Test\n");
// PLL setup: FCLK = 266MHz and HCLK = 133MHz
//*******************************************
printf("\n***PLL setup***\n");
SetPRESC(4);
SetBCLKDIV(10);
SetMcuPll(hClk * 2);
SetPRESC(1);
SetBCLKDIV(2);
ShowHCLK();
Memory_Fill_U32(SourceAddress,WordSize,Testpat);
BoardControlBurstMode(BurstOn,TargetAddress,hClk,fClk);
for (i = 1;i <= 4; i++)
{
switch (i)
{
case (1):
printf("\nBank One of Flash Memory:\n");
FlashSectorErase(Bank_one, Bank_one + (4*WordSize));
printf("\nBlank Check at Bank one\n");
MemCheck_U32(Bank_one,WordSize,0xFFFFFFFF);
FlashWrite(Bank_one, (U32*)SourceAddress, WordSize);
Error = MemCheck_U32(Bank_one,WordSize,Testpat);
if (Error)
{
printf("Flash Memory fail at Bank 1\n");
}
else
{
printf("Flash Memory pass at Bank 1\n");
}
break;
case (2):
printf("\nBank Two of Flash Memory:\n");
FlashSectorErase(Bank_two, Bank_two + (4*WordSize));
printf("\nBlank Check at Bank two\n");
MemCheck_U32(Bank_two,WordSize,0xFFFFFFFF);
FlashWrite(Bank_two, (U32*)SourceAddress, WordSize);
Error = MemCheck_U32(Bank_two,WordSize,Testpat);
if (Error)
{
printf("Flash Memory fail at Bank 2\n");
}
else
{
printf("Flash Memory pass at Bank 2\n");
}
break;
case (3):
printf("\nBank Three of Flash Memory:\n");
FlashSectorErase(Bank_three, Bank_three + (4*WordSize));
printf("\nBlank Check at Bank three\n");
MemCheck_U32(Bank_three,WordSize,0xFFFFFFFF);
FlashWrite(Bank_three, (U32*)SourceAddress, WordSize);
Error = MemCheck_U32(Bank_three,WordSize,Testpat);
if (Error)
{
printf("Flash Memory fail at Bank 3\n");
}
else
{
printf("Flash Memory pass at Bank 3\n");
}
break;
case (4):
printf("\nBank Four of Flash Memory:\n");
FlashSectorErase(Bank_four, Bank_four + (4*WordSize));
printf("\nBlank Check at Bank four\n");
MemCheck_U32(Bank_four,WordSize,0xFFFFFFFF);
FlashWrite(Bank_four, (U32*)SourceAddress, WordSize);
Error = MemCheck_U32(Bank_four,WordSize,Testpat);
if (Error)
{
printf("Flash Memory fail at Bank 4\n");
}
else
{
printf("Flash Memory pass at Bank 4\n");
}
break;
}
Total_errors += Error * sizeof(Error);
}
if (Total_errors)
{
printf("\nFlash Quick Test Fail\n");
printf("Total no. of Errors is %dbytes\n", Total_errors);
}
else
{
printf("\nFlash Quick Test Complete\n");
}
return Total_errors ? FALSE:TRUE;
}
// ***************************************************************************
//
// Function: Flash_Burst_Test - 1Mbytes at each bank
// Asyn. Flash Write sequentially from 1 to 256, then perform
// a Burst Read and calculated a checksum
// Burst Test is passed if the calculated checksum is equal
// to a predefined value
//
// Parameters: U32 hClk System Clock frequency
// U32 fClk Burst Clock frequency
//
// Return Value: U32 Success Test Pass/Fail
//
// ***************************************************************************
BOOL Flash_Burst_Test(U32 fClk)
{
U32 SourceAddress = 0xC2000000;
U32 TargetAddress = 0xC8000000;
U32* dWalk = (U32*)0xC2000000;
U32 q;
U32 data_limit = 0x100;
U32 theor_result;
U32 result;
U32 hClk = 108;
BOOL BurstOn = TRUE;
BOOL BurstOff = FALSE;
BOOL Success;
printf("\n***Flash Burst Test Begin***\n");
printf("\n***Flash Write sequentially from 1 to 256***\n");
/**********************************
** Flash Erase and Write **
**********************************/
// disable burst mode in EIM and flash device
BoardControlBurstMode(FALSE,TargetAddress,hClk,fClk);
FlashSectorErase(0xc8000000, 0xc8000400);
//FlashChipErase(TargetAddress);
for (q = 1; q <= data_limit; q++)
{
*dWalk = (q << 0) | (q << 16);
dWalk++;
}
FlashWrite(TargetAddress, (U32*)SourceAddress, data_limit);
FlashVerify(TargetAddress, SourceAddress, data_limit);
/**************************
** Burst testing **
**************************/
// calculate the theoretical result
// Equation represents 1+2+3+4+5+...+ data_limit (q)
q = data_limit;
theor_result = ((q*q + q)/2 << 0) | ((q*q + q)/2 << 16);
// PLL setup: FCLK = 216MHz and HCLK = 108MHz
//*******************************************
printf("\n***PLL setup***\n");
SetPRESC(4);
SetBCLKDIV(10);
SetMcuPll(hClk * 2);
SetPRESC(1);
SetBCLKDIV(2);
ShowHCLK();
// enable burst mode in EIM and flash device
BoardControlBurstMode(TRUE,TargetAddress,hClk,fClk);
printf("\n***Perform Flash Burst Read and calculate the checksum***\n");
result = LoadMultiple();
printf("\nresult = 0x%x\n", result);
printf("theoretical result is: 0x%x\n", theor_result);
if (result != theor_result) // the sum of all the ADD instructions
{
printf("*** Burst Read FAIL ***\n");
Success = FALSE;
}
else
{
printf("*** Burst Read Success ***\n");
Success = TRUE;
}
// disable burst mode in EIM and flash device
BoardControlBurstMode(FALSE,TargetAddress,hClk,fClk);
return Success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -