#define EEPROM_BASE_ADDR 0x08000000
#define EEPROM_BYTE_SIZE 0x0800
#define PEKEY1 0x89ABCDEF
#define PEKEY2 0x02030405
#define EN_INT __enable_irq();
#define DIS_INT __disable_irq();
void EEPROM_ReadBytes(unsigned int Addr,char *Buffer, short Length)//
{
char *wAddr;
wAddr=(char *)(EEPROM_BASE_ADDR+Addr);
while(Length--)
{
*Buffer++=*wAddr++;
}
}
void EEPROM_WriteBytes(unsigned int Addr,char *Buffer,short Length)
{
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
}
为什么写不进去啊?
此帖出自
小平头技术问答
一周热门 更多>