//
#define FLASHINT_ADDR ((uint32_t)0x08010000) //在60k的位置开始写配置数据
#define FLASHINT_PAGE_COUNT (1)
int FlashInt_Write(uint32_t iAddress, uint8_t *buf, uint32_t iNbrToWrite)
{
uint32_t i;
uint16_t Data;
FLASH_Status FLASHStatus = FLASH_ERROR_WRP;
uint32_t EraseCounter = 0x00, Address = 0x00;
FLASH_UnlockBank1();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
for(EraseCounter = 0; (EraseCounter < FLASHINT_PAGE_COUNT) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++)
{
FLASHStatus = FLASH_ErasePage(FLASHINT_ADDR + (FLASH_PAGE_SIZE * EraseCounter));
}
Address = iAddress + FLASHINT_ADDR;
for(i = 0;i<iNbrToWrite;)
{
if(i==(iNbrToWrite-1)) //最后1个字节
{
Data = *(buf+i) << 8;//奇数的时候,补零
}
else
{
Data = (*(buf+i)) << 8 + (*(buf+i+1));
}
// Data= (i << 8) + (i+1);
FLASH_ProgramHalfWord(Address,Data);
i+=2;
Address += 2;
}
FLASH_LockBank1();
return iNbrToWrite;
}
int FlashInt_Read(uint32_t iAddress, uint8_t *buf, int32_t iNbrToRead)
{
int i = 0;
uint32_t Address = 0x00;
Address = (iAddress + FLASHINT_ADDR);
while(i < iNbrToRead ) {
*(buf + i) = *(__IO uint8_t*) Address++;
i++;
}
return i;
}
一直没对过,奇怪的,这个是hsi有没有什么关系?RCC_HSICmd(ENABLE); |