Skip to content

Commit

Permalink
fix(core): reset peripherals in emergency mode
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
cepetr committed Jan 14, 2025
1 parent 2426e63 commit 280b1e9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions core/embed/io/display/ltdc_dsi/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
46 changes: 44 additions & 2 deletions core/embed/sys/task/stm32/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 280b1e9

Please sign in to comment.