📄 flash_test.c
字号:
/*
* File: flash_test.c
* Purpose: Test the AM29LV160CB Flash on the M5282EVB
*
*/
#include "src/init/m5282evb.h"
#include "src/fat/fat.h"
/********************************************************************/
void
flash_test(void)
{
uint32 i;
uint16 data = 0xA5A5;
int sector_erase(uint32);
RESULTS |= FLASH_TEST;
/* Erase sector 0, 2, 5, 10 */
if (!sector_erase(0))
return;
if (!sector_erase(0x3000))
return;
if (!sector_erase(0x40000))
return;
if (!sector_erase(0xE0000))
return;
/* Unlock Bypass command */
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0AAA)) = 0x00AA;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0554)) = 0x0055;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0AAA)) = 0x0020;
/* Unlock Bypass Program command */
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x00A0;
/* Program 16-bits of data to the 5 sectors */
*((uint16 *)(EXT_FLASH_ADDRESS)) = data;
for (i = 0; i < 200; i++) {};
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x00A0;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x3000)) = data;
for (i = 0; i < 200; i++) {};
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x00A0;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x40000)) = data;
for (i = 0; i < 400; i++) {};
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x00A0;
*((uint16 *)(EXT_FLASH_ADDRESS + 0xE0000)) = data;
for (i = 0; i < 400; i++) {};
/* Unlock Bypass Reset command */
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x0090;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) = 0x0000;
/* Verify Data in all 5 sectors */
if (*((uint16 *)(EXT_FLASH_ADDRESS + 0x0000)) != data)
{
RESULTS |= FLASH_FAIL;
return;
}
if (*((uint16 *)(EXT_FLASH_ADDRESS + 0x3000)) != data)
{
RESULTS |= FLASH_FAIL;
return;
}
if (*((uint16 *)(EXT_FLASH_ADDRESS + 0x40000)) != data)
{
RESULTS |= FLASH_FAIL;
return;
}
if (*((uint16 *)(EXT_FLASH_ADDRESS + 0xE0000)) != data)
{
RESULTS |= FLASH_FAIL;
return;
}
/* Test passed... Erase sector 0, 2, 5, and 10 again */
if (!sector_erase(0))
return;
if (!sector_erase(0x3000))
return;
if (!sector_erase(0x40000))
return;
if (!sector_erase(0xE0000))
return;
}
/********************************************************************/
int
sector_erase(uint32 address)
{
int i;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0AAA)) = 0x00AA;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0554)) = 0x0055;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0AAA)) = 0x0080;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0AAA)) = 0x00AA;
*((uint16 *)(EXT_FLASH_ADDRESS + 0x0554)) = 0x0055;
*((uint16 *)(EXT_FLASH_ADDRESS + address)) = 0x0030;
for (i = 0; i < 40000000; i++)
{
if (*((uint16*)(EXT_FLASH_ADDRESS + address)) == 0xFFFF)
break;
}
if (i == 40000000)
{
RESULTS |= FLASH_FAIL;
return FALSE;
}
return TRUE;
}
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -