diff --git a/embed/boardloader/lowlevel.c b/embed/boardloader/lowlevel.c index 18d477163d..f3e41925b6 100644 --- a/embed/boardloader/lowlevel.c +++ b/embed/boardloader/lowlevel.c @@ -5,20 +5,6 @@ #include STM32_HAL_H -// reference RM0090 section 35.12.1 Figure 413 -#define USB_OTG_HS_DATA_FIFO_RAM (USB_OTG_HS_PERIPH_BASE + 0x20000U) -#define USB_OTG_HS_DATA_FIFO_SIZE (4096U) - -void clear_otg_hs_memory(void) -{ - // use the HAL version due to section 2.1.6 of STM32F42xx Errata sheet - __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); // enable USB_OTG_HS peripheral clock so that the peripheral memory is accessible - const uint32_t unpredictable = rng_get(); - memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), unpredictable); - memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), 0); - __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); // disable USB OTG_HS peripheral clock as the peripheral is not needed right now -} - #define WANTED_WRP (OB_WRP_SECTOR_0 | OB_WRP_SECTOR_1 | OB_WRP_SECTOR_2) #define WANTED_RDP (OB_RDP_LEVEL_2) #define WANTED_BOR (OB_BOR_LEVEL3) diff --git a/embed/boardloader/lowlevel.h b/embed/boardloader/lowlevel.h index 977a7af32d..94e5508474 100644 --- a/embed/boardloader/lowlevel.h +++ b/embed/boardloader/lowlevel.h @@ -1,8 +1,6 @@ #ifndef __BOARDLOADER_LOWLEVEL_H__ #define __BOARDLOADER_LOWLEVEL_H__ -void clear_otg_hs_memory(void); - void flash_set_option_bytes(void); #endif diff --git a/embed/trezorhal/common.c b/embed/trezorhal/common.c index 175b899eba..897f0fb093 100644 --- a/embed/trezorhal/common.c +++ b/embed/trezorhal/common.c @@ -28,6 +28,7 @@ void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, #define STR(s) #s display_printf("rev : %s\n", XSTR(GITREV)); #endif + clear_otg_hs_memory(); shutdown(); for (;;); } @@ -74,3 +75,17 @@ void hal_delay(uint32_t ms) { HAL_Delay(ms); } + +// reference RM0090 section 35.12.1 Figure 413 +#define USB_OTG_HS_DATA_FIFO_RAM (USB_OTG_HS_PERIPH_BASE + 0x20000U) +#define USB_OTG_HS_DATA_FIFO_SIZE (4096U) + +void clear_otg_hs_memory(void) +{ + // use the HAL version due to section 2.1.6 of STM32F42xx Errata sheet + __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); // enable USB_OTG_HS peripheral clock so that the peripheral memory is accessible + const uint32_t unpredictable = rng_get(); + memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), unpredictable); + memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), 0); + __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); // disable USB OTG_HS peripheral clock as the peripheral is not needed right now +} diff --git a/embed/trezorhal/common.h b/embed/trezorhal/common.h index d59f15105e..eee0ade4d1 100644 --- a/embed/trezorhal/common.h +++ b/embed/trezorhal/common.h @@ -10,6 +10,8 @@ extern void memset_reg(volatile void *start, volatile void *stop, uint32_t val); +void clear_otg_hs_memory(void); + void periph_init(void); void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);