123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include "flash_if.h"
- #include "httpserver.h"
- #include "common_config.h"
- #include "wdg.h"
- #include "tinystdio.h"
- uint32_t flash_read(uint32_t address)
- {
- return (*(__IO uint32_t*) address);
- }
- void FLASH_If_Init(void)
- {
- FLASH_Unlock();
- }
- int8_t FLASH_If_Erase(uint32_t StartSector)
- {
- uint32_t FlashAddress;
-
- FlashAddress = StartSector;
-
-
-
- if (FlashAddress <= (uint32_t) USER_FLASH_LAST_PAGE_ADDRESS)
- {
- FLASH_Unlock();
- GPIOE->ODR ^= WDT_PIN;
- FLASH_EraseSector(FLASH_Sector_5, VoltageRange_3);
- GPIOE->ODR ^= WDT_PIN;
- FLASH_EraseSector(FLASH_Sector_6, VoltageRange_3);
- GPIOE->ODR ^= WDT_PIN;
- FLASH_EraseSector(FLASH_Sector_7, VoltageRange_3);
- GPIOE->ODR ^= WDT_PIN;
-
- if (USER_FLASH_END_ADDRESS > 0x08000000 + 0x7FFFF) {
- FLASH_EraseSector(FLASH_Sector_8, VoltageRange_3);
- GPIOE->ODR ^= WDT_PIN;
- FLASH_EraseSector(FLASH_Sector_9, VoltageRange_3);
- GPIOE->ODR ^= WDT_PIN;
- }
- FLASH_Lock();
- }
- else
- {
- return (1);
- }
- return (0);
- }
- uint32_t FLASH_If_Write(__IO uint32_t* FlashAddress, uint32_t* Data ,uint16_t DataLength)
- {
- uint32_t i = 0;
- uint32_t delta;
-
- for (i = 0; (i < DataLength) && (*FlashAddress <= (USER_FLASH_END_ADDRESS)); i++)
- {
-
-
- if (FLASH_ProgramWord(*FlashAddress, *(uint32_t*)(Data+i)) == FLASH_COMPLETE)
- {
-
- if (*(uint32_t*)*FlashAddress != *(uint32_t*)(Data+i))
- {
-
- return(2);
- }
-
- *FlashAddress += 4;
- }
- else
- {
-
- return (1);
- }
- }
- return (0);
- }
|