improved flash error indication

This commit is contained in:
King Kévin 2022-07-11 18:46:19 +02:00
parent 5bbe2eb5c7
commit ba1752a409
1 changed files with 12 additions and 5 deletions

17
main.c
View File

@ -391,13 +391,14 @@ i2c_end:
}
}
if (edid_equal) {
LED_PORT->ODR.reg |= LED_PIN; // switch LED off to indicate EDID is same
puts("EDID not changed\r\n");
} else {
LED_PORT->ODR.reg &= ~LED_PIN; // switch LED on to indicate we are saving EDID
puts("saving EDID: ");
// note: the STM8S103 does not support RWW
// try to make fast small operations to not stall I²C communication
eeprom_valid = false; // invalidate saved EDID while re-programming it
bool flash_success = true;
// disable DATA (e.g. EEPROM) write protection
if (0 == (FLASH_IAPSR & FLASH_IAPSR_DUL)) {
FLASH_DUKR = FLASH_DUKR_KEY1;
@ -414,12 +415,13 @@ i2c_end:
// we don't check for WR_PG_DIS (while checking EOP) because EEPROM isn't (and can't be) write protected
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) {
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
flash_success = false; // remember we had a flashing error
puts("failed\r\n");
break;
}
}
// save need EDID
for (uint16_t i = 0; i < edid_len; i += 4U) { // go through word
for (uint16_t i = 0; i < edid_len && flash_success; i += 4U) { // go through word
IWDG_KR = IWDG_KR_KEY_REFRESH; // reset watchdog
FLASH_CR2 |= FLASH_CR2_WPRG; // set word programming
FLASH_NCR2 &= ~FLASH_NCR2_NWPRG; // set word programming
@ -429,14 +431,19 @@ i2c_end:
// we don't check for WR_PG_DIS (while checking EOP) because EEPROM isn't (and can't be) write protected
if (!(FLASH_IAPSR & FLASH_IAPSR_EOP)) {
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
flash_success = false; // remember we had a flashing error
puts("failed\r\n");
break;
}
}
FLASH_IAPSR &= ~FLASH_IAPSR_DUL; // re-enable write protection
eeprom_valid = true; // re-enable EDID reading
LED_PORT->ODR.reg |= LED_PIN; // switch LED off to indicate we are completed saving EDID
puts("done\r\n");
if (flash_success) {
eeprom_valid = true; // re-enable EDID reading
LED_PORT->ODR.reg |= LED_PIN; // switch LED off to indicate we are completed saving EDID
puts("done\r\n");
} else {
puts("flashing error\r\n");
}
// indicate there is a new EDID
if (!hpd_fwd) { // we have to pull up
/*