12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include <string.h>
- #include <stdbool.h>
- #include "flash_stm32.h"
- uint8_t FlashBuf[MOCK_FLASH_SIZE] = {0};
- static bool flash_locked = true;
- FLASH_Status FLASH_ErasePage(uint32_t Page_Address) {
- if (flash_locked) return FLASH_ERROR_WRP;
- Page_Address -= (uintptr_t)FlashBuf;
- Page_Address -= (Page_Address % FEE_PAGE_SIZE);
- if (Page_Address >= MOCK_FLASH_SIZE) return FLASH_BAD_ADDRESS;
- memset(&FlashBuf[Page_Address], '\xff', FEE_PAGE_SIZE);
- return FLASH_COMPLETE;
- }
- FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) {
- if (flash_locked) return FLASH_ERROR_WRP;
- Address -= (uintptr_t)FlashBuf;
- if (Address >= MOCK_FLASH_SIZE) return FLASH_BAD_ADDRESS;
- uint16_t oldData = *(uint16_t*)&FlashBuf[Address];
- if (oldData == 0xFFFF || Data == 0) {
- *(uint16_t*)&FlashBuf[Address] = Data;
- return FLASH_COMPLETE;
- } else {
- return FLASH_ERROR_PG;
- }
- }
- FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) {
- return FLASH_COMPLETE;
- }
- void FLASH_Unlock(void) {
- flash_locked = false;
- }
- void FLASH_Lock(void) {
- flash_locked = true;
- }
|