From b59e28a96aca4b7e11fa9fb1c1a9112283b1ba85 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 14 Sep 2023 11:16:04 +0200 Subject: [PATCH] refactor(core): add flexible HSE settings [no changelog] --- .../embed/trezorhal/boards/stm32f429i-disc1.h | 2 ++ core/embed/trezorhal/boards/trezor_1.h | 2 ++ core/embed/trezorhal/boards/trezor_r_v10.h | 2 ++ core/embed/trezorhal/boards/trezor_r_v3.h | 2 ++ core/embed/trezorhal/boards/trezor_r_v4.h | 2 ++ core/embed/trezorhal/boards/trezor_r_v6.h | 2 ++ core/embed/trezorhal/boards/trezor_t.h | 2 ++ core/embed/trezorhal/stm32f4/platform.c | 20 +++++++++++++------ 8 files changed, 28 insertions(+), 6 deletions(-) diff --git a/core/embed/trezorhal/boards/stm32f429i-disc1.h b/core/embed/trezorhal/boards/stm32f429i-disc1.h index 0b5cef9bd..a12ad1a05 100644 --- a/core/embed/trezorhal/boards/stm32f429i-disc1.h +++ b/core/embed/trezorhal/boards/stm32f429i-disc1.h @@ -1,6 +1,8 @@ #ifndef _STM32F429I_DISC1_H #define _STM32F429I_DISC1_H +#define HSE_8MHZ + #define MAX_DISPLAY_RESX 240 #define MAX_DISPLAY_RESY 320 #define DISPLAY_RESX 240 diff --git a/core/embed/trezorhal/boards/trezor_1.h b/core/embed/trezorhal/boards/trezor_1.h index 43f058aeb..4f126a720 100644 --- a/core/embed/trezorhal/boards/trezor_1.h +++ b/core/embed/trezorhal/boards/trezor_1.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_1_H #define _TREZOR_1_H +#define HSE_8MHZ + #define USE_BUTTON 1 #include "displays/vg-2864ksweg01.h" diff --git a/core/embed/trezorhal/boards/trezor_r_v10.h b/core/embed/trezorhal/boards/trezor_r_v10.h index ccf4d3b9e..798d37964 100644 --- a/core/embed/trezorhal/boards/trezor_r_v10.h +++ b/core/embed/trezorhal/boards/trezor_r_v10.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_R_V10_H #define _TREZOR_R_V10_H +#define HSE_8MHZ + #define USE_BUTTON 1 #define USE_SBU 1 #define USE_I2C 1 diff --git a/core/embed/trezorhal/boards/trezor_r_v3.h b/core/embed/trezorhal/boards/trezor_r_v3.h index c71ec01d6..242a3f541 100644 --- a/core/embed/trezorhal/boards/trezor_r_v3.h +++ b/core/embed/trezorhal/boards/trezor_r_v3.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_R_V3_H #define _TREZOR_R_V3_H +#define HSE_8MHZ + #define USE_BUTTON 1 #define USE_SBU 1 diff --git a/core/embed/trezorhal/boards/trezor_r_v4.h b/core/embed/trezorhal/boards/trezor_r_v4.h index ff012584f..29054d200 100644 --- a/core/embed/trezorhal/boards/trezor_r_v4.h +++ b/core/embed/trezorhal/boards/trezor_r_v4.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_R_V4_H #define _TREZOR_R_V4_H +#define HSE_8MHZ + #define USE_BUTTON 1 #define USE_SBU 1 diff --git a/core/embed/trezorhal/boards/trezor_r_v6.h b/core/embed/trezorhal/boards/trezor_r_v6.h index 5ca485d5b..72a7cedea 100644 --- a/core/embed/trezorhal/boards/trezor_r_v6.h +++ b/core/embed/trezorhal/boards/trezor_r_v6.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_R_V6_H #define _TREZOR_R_V6_H +#define HSE_8MHZ + #define USE_BUTTON 1 #define USE_SBU 1 diff --git a/core/embed/trezorhal/boards/trezor_t.h b/core/embed/trezorhal/boards/trezor_t.h index e08fdc96b..950df8157 100644 --- a/core/embed/trezorhal/boards/trezor_t.h +++ b/core/embed/trezorhal/boards/trezor_t.h @@ -1,6 +1,8 @@ #ifndef _TREZOR_T_H #define _TREZOR_T_H +#define HSE_8MHZ + #define DISPLAY_RESX 240 #define DISPLAY_RESY 240 diff --git a/core/embed/trezorhal/stm32f4/platform.c b/core/embed/trezorhal/stm32f4/platform.c index 1bf44e4e8..e7323d403 100644 --- a/core/embed/trezorhal/stm32f4/platform.c +++ b/core/embed/trezorhal/stm32f4/platform.c @@ -35,25 +35,33 @@ typedef struct { uint32_t plln; } clock_conf_t; +#ifdef HSE_16MHZ +#define PLLM_COEF 2U +#elif defined HSE_8MHZ +#define PLLM_COEF 1U +#else +#error Unsupported HSE frequency +#endif + #if defined STM32F427xx || defined STM32F429xx #ifdef TREZOR_MODEL_T #define DEFAULT_FREQ 168U #define DEFAULT_PLLQ 7U #define DEFAULT_PLLP 0U // P = 2 (two bits, 00 means PLLP = 2) -#define DEFAULT_PLLM 4U +#define DEFAULT_PLLM (4U * PLLM_COEF) #define DEFAULT_PLLN 168U #else #define DEFAULT_FREQ 180U #define DEFAULT_PLLQ 15U #define DEFAULT_PLLP 1U // P = 4 (two bits, 01 means PLLP = 4) -#define DEFAULT_PLLM 4U +#define DEFAULT_PLLM (4U * PLLM_COEF) #define DEFAULT_PLLN 360U #endif #elif STM32F405xx #define DEFAULT_FREQ 120U #define DEFAULT_PLLQ 5U #define DEFAULT_PLLP 0U // P = 2 (two bits, 00 means PLLP = 2) -#define DEFAULT_PLLM 8U +#define DEFAULT_PLLM (8U * PLLM_COEF) #define DEFAULT_PLLN 240U #else #error Unsupported MCU @@ -70,7 +78,7 @@ clock_conf_t clock_conf[3] = { 180, 15, 1, - 4, + 4 * PLLM_COEF, 360, }, { @@ -80,7 +88,7 @@ clock_conf_t clock_conf[3] = { 168, 7, 0, - 4, + 4 * PLLM_COEF, 168, }, { @@ -90,7 +98,7 @@ clock_conf_t clock_conf[3] = { 120, 5, 0, - 8, + 8 * PLLM_COEF, 240, }, };