#define EEPROM_BASE_ADDR 0x08000000
#define EEPROM_BYTE_SIZE 0x0800 //¶¨ÒåEEPROMµÄÆðʼλÖúʹóС
#define PEKEY1 0x89ABCDEF //FLASH_PEKEYR
#define PEKEY2 0x02030405 //FLASH_PEKEYR ½âËøÃüÁî
#define EN_INT __enable_irq(); //ϵͳ¿ª¾ÖÖжÏ
#define DIS_INT __disable_irq(); //ϵͳ¹Ø±ÕÈ«¾Ö
void EEPROM_ReadBytes(unsigned int Addr,char *Buffer, short Length)//°´ÕÕ×Ö½Ú¶Á³öEEPROMµÄÊý¾Ý
{
char *wAddr;
wAddr=(char *)(EEPROM_BASE_ADDR+Addr);
while(Length--)
{
*Buffer++=*wAddr++;
}
}
void EEPROM_WriteBytes(unsigned int Addr,char *Buffer,short Length)//°´ÕÕ×Ö½ÚÊý¾Ýдµ½EEPROM
{
char *wAddr;
wAddr=(char *)(EEPROM_BASE_ADDR+Addr);
DIS_INT
FLASH->PEKEYR=PEKEY1; //unlock
FLASH->PEKEYR=PEKEY2;
while(Length--)
{
*wAddr++=*Buffer++;
while(FLASH->SR&FLASH_SR_BSY);
}
FLASH->PECR|=FLASH_PECR_PELOCK;
EN_INT
}
为什么写不进去啊? |