|
问题如下:
Ti EVM DM642采用flash为AMD29LV033C,大小:4M Bytes,8位数据线,22地址线,接于DSP的CE1空间
1、块擦除函数
/* The Flash Erase function uses * the AMD algorithm to erase the * entire chip. */
void EraseFlash(void) { int i; /* Code to erase AMD29LV033C * 32MBit (4MK X 8) Flash Memory */ *FLASH_PAGE = 0; *(volatile char *)FLASH_START = (char)FLASH_KEY1; *(volatile char *)FLASH_START = (char)FLASH_KEY2; *(volatile char *)FLASH_START = (char)FLASH_KEY4;
*(volatile char *)FLASH_START = (char)FLASH_KEY1; *(volatile char *)FLASH_START = (char)FLASH_KEY2; *(volatile char *)FLASH_START = (char)FLASH_KEY5;
/* Wait until erase is done */ while(GetFlashVal(FLASH_START) != 0xff);
/* Put the Flash in normal mode */ *(volatile char *)FLASH_START = (char)0xf0;
/* Mark all sectors as erased */ for (i = 0; i < FLASH_SECTORS; i++) erasetable[i] = 1; return; }
2、!!!!!!!!
写入函数 /* Burns flash data, starting at flashnext. * This embodies the burning algorithm for the * AMD29LV033C flash memory used on DM642 EVM */
#define FLASH_PAGE ((volatile unsigned char *)0x90080018)
void BurnFlash(u8 *data, u16 nBytes) { u16 timeout; u8 c; volatile u8 *pdata;
/* Put the Flash in normal mode */ *(volatile char *)FLASH_START = (char)0xf0;
flash_erase((u32)flashnext, (u32)nBytes); while(nBytes--) { /* Prep AMD * 32MBit (4M x 8) Flash Memory * for writing a byte. */ *FLASH_PAGE = (u8)(((u32)flashnext & 0x380000) >> 19); *(volatile char *)FLASH_START = (char)FLASH_KEY1; *(volatile char *)FLASH_START = (char)FLASH_KEY2; *(volatile char *)FLASH_START = (char)FLASH_KEY3;
pdata = (volatile u8 *)((u32)flashnext & 0xffc7ffff); *pdata = *data; /* Spin here 'til programming completes */ c = *data++; timeout = 0; do timeout += 1; while(*pdata != c && timeout < (u16)0xffff); flashnext++; } /* Put the Flash in normal mode */ *(volatile char *)FLASH_START = (char)0xf0; }
非常迷惑这里写函数中: pdata = (volatile u8 *)((u32)flashnext & 0xffc7ffff);
这里想把pdata 指向flashnext(扇区首地址,例如0x90000000),然后循环写某个大小。为何传地址给指针pdata 时,flashnext 要和0xffc7ffff进行与操作?还有*FLASH_PAGE = (u8)(((u32)flashnext & 0x380000) >> 19);意义何在?
解答如下:
原因是EVM板的flash地址线连接,比较特殊:
A0 -A18:直接连接到DSP的地址线; A19-A21:连接到FPGA内部的页地址寄存器。
|