diff --git a/core/embed/gfx/bitblt/dma2d_bitblt.h b/core/embed/gfx/bitblt/dma2d_bitblt.h index b09786f8cc..2f6bca6871 100644 --- a/core/embed/gfx/bitblt/dma2d_bitblt.h +++ b/core/embed/gfx/bitblt/dma2d_bitblt.h @@ -25,6 +25,9 @@ // Initializes DMA2D peripheral void dma2d_init(void); +// Deinitializes DMA2D peripheral +void dma2d_deinit(void); + // Waits until any pending DMA2D operation is finished void dma2d_wait(void); diff --git a/core/embed/gfx/bitblt/gfx_bitblt.c b/core/embed/gfx/bitblt/gfx_bitblt.c index 268a6924fa..00f7eb83b9 100644 --- a/core/embed/gfx/bitblt/gfx_bitblt.c +++ b/core/embed/gfx/bitblt/gfx_bitblt.c @@ -25,6 +25,12 @@ void gfx_bitblt_init(void) { #endif } +void gfx_bitblt_deinit(void) { +#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR) + dma2d_deinit(); +#endif +} + void gfx_bitblt_wait(void) { #if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR) dma2d_wait(); diff --git a/core/embed/gfx/bitblt/stm32/dma2d_bitblt.c b/core/embed/gfx/bitblt/stm32/dma2d_bitblt.c index 7d14f4620c..a3910845df 100644 --- a/core/embed/gfx/bitblt/stm32/dma2d_bitblt.c +++ b/core/embed/gfx/bitblt/stm32/dma2d_bitblt.c @@ -40,7 +40,19 @@ static inline bool dma2d_accessible(const void* ptr) { #endif } -void dma2d_init(void) { __HAL_RCC_DMA2D_CLK_ENABLE(); } +void dma2d_init(void) { + __HAL_RCC_DMA2D_FORCE_RESET(); + __HAL_RCC_DMA2D_RELEASE_RESET(); + + __HAL_RCC_DMA2D_CLK_ENABLE(); +} + +void dma2d_deinit(void) { + __HAL_RCC_DMA2D_CLK_DISABLE(); + + __HAL_RCC_DMA2D_FORCE_RESET(); + __HAL_RCC_DMA2D_RELEASE_RESET(); +} void dma2d_wait(void) { while (HAL_DMA2D_PollForTransfer(&dma2d_handle, 10) != HAL_OK) diff --git a/core/embed/gfx/inc/gfx/gfx_bitblt.h b/core/embed/gfx/inc/gfx/gfx_bitblt.h index 7595a25eaf..27ddaa2557 100644 --- a/core/embed/gfx/inc/gfx/gfx_bitblt.h +++ b/core/embed/gfx/inc/gfx/gfx_bitblt.h @@ -78,6 +78,9 @@ typedef struct { // Initializes bitblt operations void gfx_bitblt_init(void); +// Deinitializes bitblt operations +void gfx_bitblt_deinit(void); + // If the bitblt operation is asynchronous, waits until it's finished void gfx_bitblt_wait(void); diff --git a/core/embed/projects/boardloader/main.c b/core/embed/projects/boardloader/main.c index 222c7052c7..106bdb1cc0 100644 --- a/core/embed/projects/boardloader/main.c +++ b/core/embed/projects/boardloader/main.c @@ -103,6 +103,7 @@ static void drivers_deinit(void) { #ifdef FIXED_HW_DEINIT // TODO #endif + gfx_bitblt_deinit(); display_deinit(DISPLAY_JUMP_BEHAVIOR); #ifdef USE_POWERCTL powerctl_deinit(); diff --git a/core/embed/projects/bootloader/main.c b/core/embed/projects/bootloader/main.c index 8205ec80b8..564a35fb06 100644 --- a/core/embed/projects/bootloader/main.c +++ b/core/embed/projects/bootloader/main.c @@ -136,6 +136,7 @@ static void drivers_deinit(void) { #ifdef FIXED_HW_DEINIT // TODO #endif + gfx_bitblt_deinit(); display_deinit(DISPLAY_JUMP_BEHAVIOR); ensure_compatible_settings(); }