FLASH_STM32-四、FLASH配置

时间:2024-01-26 07:00:06
uint32_t MyFlash_ReadWord(uint32_t Address)
{
	return *((__IO uint32_t *)(Address));
}

uint16_t MyFlash_ReadHalfWord(uint32_t Address)
{
	return *((__IO uint16_t *)(Address));
}

uint8_t MyFlash_ReadByte(uint32_t Address)
{
	return *((__IO uint8_t *)(Address));
}

void MyFlash_EraseAllPages(void)
{
	FLASH_Unlock();				// 解锁
	FLASH_EraseAllPages();		// 全擦除
	FLASH_Lock();				// 加锁
}

void MyFlash_EraseAPage(uint32_t PageAddress)
{
	FLASH_Unlock();					// 解锁
	FLASH_ErasePage(PageAddress);	// 页擦除
	FLASH_Lock();					// 加锁	
}

void MyFlash_ProgramWord(uint32_t Address, uint32_t Data)
{
	FLASH_Unlock();						// 解锁
	FLASH_ProgramWord(Address, Data);	// 写入字
	FLASH_Lock();						// 加锁	
}

void MyFlash_ProgramWord(uint32_t Address, uint32_t Data)
{
	FLASH_Unlock();							// 解锁
	FLASH_ProgramHalfWord(Address, Data);	// 写入半字
	FLASH_Lock();							// 加锁	

'对闪存读写的基本逻辑是:上电时将闪存读取到SRAM内存中,下电前再写回闪存,避免频繁的读写闪存'
'因为在读写FLASH闪存时,CPU会停止,会可能导致中断程序无法按时执行'
}