1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 16:25:16 +03:00

Flash only unlocked when needed

This commit is contained in:
Andre Bernet 2014-04-11 11:18:58 +02:00
parent d442fa77e0
commit ac1dbf81f4
5 changed files with 25 additions and 2 deletions

View file

@ -137,6 +137,8 @@ UINT BlockCount;
uint32_t memoryType;
uint32_t unlocked = 0;
#if defined(PCBSKY9X)
extern int32_t EblockAddress;
#endif
@ -520,7 +522,6 @@ int main()
#if defined(PCBTARANIS)
// SD card detect pin
sdInit();
unlockFlash();
usbInit();
usbStart();
#endif
@ -714,7 +715,12 @@ int main()
else if (state == ST_FLASHING) {
// commit to flashing
lcd_putsLeft(4*FH, "\032Writing...");
if (!unlocked && (memoryType == MEM_FLASH)) {
unlocked = 1;
unlockFlash();
}
int progress;
if (memoryType == MEM_FLASH) {
writeFlashBlock();
@ -745,6 +751,10 @@ int main()
}
if (state == ST_FLASH_DONE) {
if (unlocked) {
lockFlash();
unlocked = 0;
}
lcd_putsLeft(4*FH, "\024Writing Complete");
if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT) || event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
state = ST_START;

View file

@ -773,6 +773,11 @@ void flashBootloader(const char * filename)
}
}
if (unlocked) {
lockFlash();
unlocked = 0;
}
f_close(&file);
}
#endif

View file

@ -674,6 +674,7 @@ void RCC_LSEConfig(uint8_t RCC_LSE) { }
FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG) { return RESET; }
ErrorStatus RTC_WaitForSynchro(void) { return SUCCESS; }
void unlockFlash() { }
void lockFlash() { }
void writeFlash(uint32_t *address, uint32_t *buffer) { SIMU_SLEEP(100); }
uint32_t isBootloaderStart(const void *block) { return 1; }
#endif

View file

@ -144,6 +144,7 @@ void delay_01us(uint16_t nb);
// Flash Write driver
#define FLASH_PAGESIZE 256
void unlockFlash();
void lockFlash();
void writeFlash(uint32_t * address, uint32_t * buffer);
uint32_t isFirmwareStart(const void * buffer);
uint32_t isBootloaderStart(const void * buffer);

View file

@ -16,6 +16,12 @@ void unlockFlash()
FLASH->KEYR = 0xCDEF89AB;
}
void lockFlash()
{
while (!FLASH->SR & FLASH_SR_BSY);
FLASH->CR |= FLASH_CR_LOCK;
}
void waitFlashIdle()
{
while (FLASH->SR & FLASH_FLAG_BSY) {