fix init order to prevent reset loop in some cases

pull/527/head 4.1.1
Conor Patrick 2021-02-02 22:26:31 -08:00
rodzic e91dff3713
commit a87e1c6d15
2 zmienionych plików z 16 dodań i 13 usunięć

Wyświetl plik

@ -304,12 +304,6 @@ void device_init()
hw_init(LOW_FREQUENCY); hw_init(LOW_FREQUENCY);
#if BOOT_TO_DFU
flash_option_bytes_init(1);
#else
flash_option_bytes_init(0);
#endif
if (! tsc_sensor_exists()) if (! tsc_sensor_exists())
{ {
_NFC_status = nfc_init(); _NFC_status = nfc_init();
@ -329,13 +323,18 @@ void device_init()
device_init_button(); device_init_button();
} }
device_migrate();
#if BOOT_TO_DFU
flash_option_bytes_init(1);
#else
flash_option_bytes_init(0);
#endif
usbhid_init(); usbhid_init();
ctaphid_init(); ctaphid_init();
ctap_init(); ctap_init();
device_migrate();
} }
int device_is_nfc(void) int device_is_nfc(void)

Wyświetl plik

@ -47,7 +47,7 @@ void flash_option_bytes_init(int boot_from_dfu)
val &= ~(1<<25); // SRAM2_RST = 1 (erase sram on reset) val &= ~(1<<25); // SRAM2_RST = 1 (erase sram on reset)
val &= ~(1<<24); // SRAM2_PE = 1 (parity check en) val &= ~(1<<24); // SRAM2_PE = 1 (parity check en)
if (FLASH->OPTR == val) if ((FLASH->OPTR & 0xb3f77ff) == (val & 0xb3f77ff))
{ {
return; return;
} }
@ -68,13 +68,17 @@ void flash_option_bytes_init(int boot_from_dfu)
while (FLASH->SR & (1<<16)) while (FLASH->SR & (1<<16))
; ;
flash_lock(); if (FLASH->CR & (1<<30))
{
FLASH->OPTKEYR = 0x08192A3B;
FLASH->OPTKEYR = 0x4C5D6E7F;
}
/* Perform option byte loading which triggers a device reset. */ /* Perform option byte loading which triggers a device reset. */
FLASH->CR |= FLASH_CR_OBL_LAUNCH; FLASH->CR |= FLASH_CR_OBL_LAUNCH;
while (true); while (true)
;
} }
void flash_erase_page(uint8_t page) void flash_erase_page(uint8_t page)