2024-01-20 13:19:09 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2024-01-24 22:08:32 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
2024-01-20 13:19:09 +08:00
|
|
|
|
|
|
|
#include "flash.h"
|
|
|
|
|
2024-01-24 22:08:32 +08:00
|
|
|
u16 Flash_ReadHalfWord(u32 faddr)
|
|
|
|
{
|
2024-01-20 13:19:09 +08:00
|
|
|
uint16_t val = 0;
|
|
|
|
faddr = faddr + FLASH_SAVE_ADDR;
|
2024-01-24 22:08:32 +08:00
|
|
|
val = *(uint16_t *)faddr;
|
2024-01-20 13:19:09 +08:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2024-01-24 22:08:32 +08:00
|
|
|
u32 Flash_ReadWord(u32 faddr)
|
|
|
|
{
|
2024-01-20 13:19:09 +08:00
|
|
|
uint16_t val = 0;
|
|
|
|
faddr = faddr + FLASH_SAVE_ADDR;
|
2024-01-24 22:08:32 +08:00
|
|
|
val = *(uint32_t *)faddr;
|
2024-01-20 13:19:09 +08:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2024-01-24 22:08:32 +08:00
|
|
|
|
|
|
|
#define PageSize 0x400
|
|
|
|
|
|
|
|
void Flash_EnableWrite()
|
|
|
|
{
|
2024-01-20 13:19:09 +08:00
|
|
|
/*FLASH_Unlock();
|
|
|
|
FLASH_ErasePage(FLASH_SAVE_ADDR);
|
|
|
|
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);*/
|
2024-01-24 22:08:32 +08:00
|
|
|
FLASH_Unlock();
|
|
|
|
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
|
2024-01-20 13:19:09 +08:00
|
|
|
FLASH_ErasePage(FLASH_SAVE_ADDR);
|
2024-01-24 22:08:32 +08:00
|
|
|
// FLASH_ErasePage(FLASH_SAVE_ADDR + PageSize);
|
2024-01-20 13:19:09 +08:00
|
|
|
}
|
|
|
|
|
2024-01-24 22:08:32 +08:00
|
|
|
void Flash_DisableWrite()
|
|
|
|
{
|
2024-01-20 13:19:09 +08:00
|
|
|
FLASH_Lock();
|
|
|
|
}
|
|
|
|
|
2024-01-24 22:08:32 +08:00
|
|
|
u32 Flash_WriteHalfWord(u32 faddr, u16 data)
|
|
|
|
{
|
|
|
|
faddr = faddr + FLASH_SAVE_ADDR;
|
2024-01-20 13:19:09 +08:00
|
|
|
|
|
|
|
return FLASH_ProgramHalfWord(faddr, data);
|
|
|
|
}
|
|
|
|
|
2024-01-24 22:08:32 +08:00
|
|
|
u32 Flash_WriteWord(u32 faddr, u32 data)
|
|
|
|
{
|
|
|
|
faddr = faddr + FLASH_SAVE_ADDR;
|
2024-01-20 13:19:09 +08:00
|
|
|
return FLASH_ProgramWord(faddr, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2024-01-24 22:08:32 +08:00
|
|
|
#endif
|