1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-28 16:21:03 +00:00

fix(core): reset peripherals in emergency mode

[no changelog]
This commit is contained in:
cepetr 2025-01-13 19:08:16 +01:00 committed by cepetr
parent 2426e637b3
commit 280b1e9b79
2 changed files with 49 additions and 2 deletions

View File

@ -230,6 +230,11 @@ static bool display_dsi_init(display_driver_t *drv) {
goto cleanup;
}
// The LTDC clock must be disabled before enabling the DSI host.
// If the LTDC clock remains enabled, the display colors may appear
// incorrectly or randomly swapped.
__HAL_RCC_LTDC_CLK_DISABLE();
/* Enable the DSI host */
__HAL_DSI_ENABLE(&drv->hlcd_dsi);

View File

@ -79,7 +79,49 @@ void system_exit_fatal_ex(const char* message, size_t message_len,
}
__attribute__((used)) static void emergency_reset(void) {
// TODO: reset peripherals (at least DMA, DMA2D)
// Reset peripherals
#ifdef __HAL_RCC_DMA2D_FORCE_RESET
__HAL_RCC_DMA2D_CLK_DISABLE();
__HAL_RCC_DMA2D_FORCE_RESET();
__HAL_RCC_DMA2D_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DSI_FORCE_RESET
__HAL_RCC_DSI_CLK_DISABLE();
__HAL_RCC_DSI_FORCE_RESET();
__HAL_RCC_DSI_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_GFXMMU_FORCE_RESET
__HAL_RCC_GFXMMU_CLK_DISABLE();
__HAL_RCC_GFXMMU_FORCE_RESET();
__HAL_RCC_GFXMMU_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_LTDC_FORCE_RESET
__HAL_RCC_LTDC_CLK_DISABLE();
__HAL_RCC_LTDC_FORCE_RESET();
__HAL_RCC_LTDC_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_GPDMA1_FORCE_RESET
__HAL_RCC_GPDMA1_CLK_DISABLE();
__HAL_RCC_GPDMA1_FORCE_RESET();
__HAL_RCC_GPDMA1_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DMA1_FORCE_RESET
__HAL_RCC_DMA1_CLK_DISABLE();
__HAL_RCC_DMA1_FORCE_RESET();
__HAL_RCC_DMA1_RELEASE_RESET();
#endif
#ifdef __HAL_RCC_DMA2_FORCE_RESET
__HAL_RCC_DMA2_CLK_DISABLE();
__HAL_RCC_DMA2_FORCE_RESET();
__HAL_RCC_DMA2_RELEASE_RESET();
#endif
// Disable all NVIC interrupts and clear pending flags
// so later the global interrupt can be re-enabled without
@ -270,7 +312,7 @@ __attribute((naked, no_stack_protector)) void system_emergency_rescue(
"STR R0, [SP, #8] \n" // future R2 = 0
"STR R0, [SP, #12] \n" // future R3 = 0
"STR R0, [SP, #16] \n" // future R12 = 0
"LDR R1, =secure_shutdown\n"
"LDR R0, =secure_shutdown\n"
"STR R0, [SP, #20] \n" // future LR = secure_shutdown()
"BIC R6, R6, #1 \n"
"STR R6, [SP, #24] \n" // return address = error_handler()