1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

feat(core): add support for T3T1 rev. E HW

[no changelog]
This commit is contained in:
tychovrahe 2024-02-20 14:54:37 +01:00 committed by TychoVrahe
parent bfacd07ed7
commit 8ccd2cb048
4 changed files with 256 additions and 1 deletions

View File

@ -0,0 +1,107 @@
#ifndef _TREZOR_T3T1_H
#define _TREZOR_T3T1_H
#define DISPLAY_RESX 240
#define DISPLAY_RESY 240
#define VDD_1V8 1
#define HSE_16MHZ 1
#define USE_SD_CARD 1
#define USE_I2C 1
#define USE_TOUCH 1
#define USE_SBU 1
#define USE_RGB_COLORS 1
#define USE_DISP_I8080_8BIT_DW 1
#define USE_HAPTIC 1
#define USE_BACKLIGHT 1
#define USE_HASH_PROCESSOR 1
#include "displays/panels/lx154a2422.h"
#include "displays/st7789v.h"
#define DISPLAY_IDENTIFY 1
#define DISPLAY_TE_PORT GPIOD
#define DISPLAY_TE_PIN GPIO_PIN_12
#define DISPLAY_TE_INTERRUPT_HANDLER EXTI12_IRQHandler
#define DISPLAY_TE_INTERRUPT_NUM EXTI12_IRQn
#define DISPLAY_TE_INTERRUPT_GPIOSEL EXTI_GPIOD
#define DISPLAY_TE_INTERRUPT_EXTI_LINE EXTI_LINE_12
#define DISPLAY_PANEL_INIT_SEQ lx154a2422_init_seq
#define DISPLAY_PANEL_ROTATE lx154a2422_rotate
#define TRANSFORM_TOUCH_COORDS lx154a2422_transform_touch_coords
#define BACKLIGHT_PWM_FREQ 12500
#define BACKLIGHT_PWM_TIM TIM17
#define BACKLIGHT_PWM_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
#define BACKLIGHT_PWM_TIM_AF GPIO_AF14_TIM17
#define BACKLIGHT_PWM_TIM_OCMODE TIM_OCMODE_PWM1
#define BACKLIGHT_PWM_TIM_CHANNEL TIM_CHANNEL_1
#define BACKLIGHT_PWM_TIM_CCR CCR1
#define BACKLIGHT_PWM_PIN GPIO_PIN_1
#define BACKLIGHT_PWM_PORT GPIOE
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOE_CLK_ENABLE
#define I2C_COUNT 3
#define I2C_INSTANCE_0 I2C1
#define I2C_INSTANCE_0_CLK_EN __HAL_RCC_I2C1_CLK_ENABLE
#define I2C_INSTANCE_0_CLK_DIS __HAL_RCC_I2C1_CLK_DISABLE
#define I2C_INSTANCE_0_PIN_AF GPIO_AF4_I2C1
#define I2C_INSTANCE_0_SDA_PORT GPIOB
#define I2C_INSTANCE_0_SDA_PIN GPIO_PIN_7
#define I2C_INSTANCE_0_SDA_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_0_SCL_PORT GPIOB
#define I2C_INSTANCE_0_SCL_PIN GPIO_PIN_6
#define I2C_INSTANCE_0_SCL_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_0_RESET_REG &RCC->APB1RSTR1
#define I2C_INSTANCE_0_RESET_BIT RCC_APB1RSTR1_I2C1RST
#define I2C_INSTANCE_1 I2C2
#define I2C_INSTANCE_1_CLK_EN __HAL_RCC_I2C2_CLK_ENABLE
#define I2C_INSTANCE_1_CLK_DIS __HAL_RCC_I2C2_CLK_DISABLE
#define I2C_INSTANCE_1_PIN_AF GPIO_AF4_I2C2
#define I2C_INSTANCE_1_SDA_PORT GPIOB
#define I2C_INSTANCE_1_SDA_PIN GPIO_PIN_14
#define I2C_INSTANCE_1_SDA_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_1_SCL_PORT GPIOB
#define I2C_INSTANCE_1_SCL_PIN GPIO_PIN_13
#define I2C_INSTANCE_1_SCL_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_1_RESET_REG &RCC->APB1RSTR1
#define I2C_INSTANCE_1_RESET_BIT RCC_APB1RSTR1_I2C2RST
#define I2C_INSTANCE_2 I2C3
#define I2C_INSTANCE_2_CLK_EN __HAL_RCC_I2C3_CLK_ENABLE
#define I2C_INSTANCE_2_CLK_DIS __HAL_RCC_I2C3_CLK_DISABLE
#define I2C_INSTANCE_2_PIN_AF GPIO_AF4_I2C3
#define I2C_INSTANCE_2_SDA_PORT GPIOC
#define I2C_INSTANCE_2_SDA_PIN GPIO_PIN_1
#define I2C_INSTANCE_2_SDA_CLK_EN __HAL_RCC_GPIOC_CLK_ENABLE
#define I2C_INSTANCE_2_SCL_PORT GPIOC
#define I2C_INSTANCE_2_SCL_PIN GPIO_PIN_0
#define I2C_INSTANCE_2_SCL_CLK_EN __HAL_RCC_GPIOC_CLK_ENABLE
#define I2C_INSTANCE_2_RESET_REG &RCC->APB3RSTR
#define I2C_INSTANCE_2_RESET_BIT RCC_APB3RSTR_I2C3RST
#define TOUCH_SENSITIVITY 0x40
#define TOUCH_I2C_INSTANCE 0
#define TOUCH_RST_PORT GPIOC
#define TOUCH_RST_PIN GPIO_PIN_5
#define TOUCH_INT_PORT GPIOC
#define TOUCH_INT_PIN GPIO_PIN_4
#define TOUCH_ON_PORT GPIOB
#define TOUCH_ON_PIN GPIO_PIN_0
#define DRV2625_I2C_INSTANCE 1
#define HAPTIC_ACTUATOR "actuators/vg1040003d.h"
#define OPTIGA_I2C_INSTANCE 2
#define OPTIGA_RST_PORT GPIOB
#define OPTIGA_RST_PIN GPIO_PIN_1
#define OPTIGA_RST_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define SD_DETECT_PORT GPIOC
#define SD_DETECT_PIN GPIO_PIN_13
#define SD_ENABLE_PORT GPIOC
#define SD_ENABLE_PIN GPIO_PIN_3
#endif //_TREZOR_T_H

View File

@ -41,6 +41,18 @@ i2c_instance_t i2c_defs[I2C_COUNT] = {
.ResetBit = I2C_INSTANCE_1_RESET_BIT, .ResetBit = I2C_INSTANCE_1_RESET_BIT,
}, },
#endif #endif
#ifdef I2C_INSTANCE_2
{
.Instance = I2C_INSTANCE_2,
.SclPort = I2C_INSTANCE_2_SCL_PORT,
.SdaPort = I2C_INSTANCE_2_SDA_PORT,
.SclPin = I2C_INSTANCE_2_SCL_PIN,
.SdaPin = I2C_INSTANCE_2_SDA_PIN,
.PinAF = I2C_INSTANCE_2_PIN_AF,
.ResetReg = I2C_INSTANCE_2_RESET_REG,
.ResetBit = I2C_INSTANCE_2_RESET_BIT,
},
#endif
}; };
@ -101,6 +113,13 @@ void i2c_init(void) {
I2C_INSTANCE_1_SDA_CLK_EN(); I2C_INSTANCE_1_SDA_CLK_EN();
i2c_init_instance(1, &i2c_defs[1]); i2c_init_instance(1, &i2c_defs[1]);
#endif #endif
#ifdef I2C_INSTANCE_2
I2C_INSTANCE_2_CLK_EN();
I2C_INSTANCE_2_SCL_CLK_EN();
I2C_INSTANCE_2_SDA_CLK_EN();
i2c_init_instance(2, &i2c_defs[2]);
#endif
} }
void i2c_deinit(uint16_t idx) { void i2c_deinit(uint16_t idx) {

View File

@ -0,0 +1,119 @@
from __future__ import annotations
from . import get_hw_model_as_number
from .stm32u5_common import stm32u5_common_files
def configure(
env: dict,
features_wanted: list[str],
defines: list[str | tuple[str, str]],
sources: list[str],
paths: list[str],
) -> list[str]:
features_available: list[str] = []
board = "trezor_t3t1_revE.h"
display = "st7789v.c"
hw_model = get_hw_model_as_number("T3T1")
hw_revision = 0
features_available.append("disp_i8080_8bit_dw")
features_available.append("framebuffer")
defines += ["FRAMEBUFFER"]
mcu = "STM32U585xx"
linker_script = "stm32u58"
stm32u5_common_files(env, defines, sources, paths)
env.get("ENV")[
"CPU_ASFLAGS"
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 "
env.get("ENV")[
"CPU_CCFLAGS"
] = "-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mtune=cortex-m33 -mcmse "
env.get("ENV")["RUST_TARGET"] = "thumbv8m.main-none-eabihf"
defines += [mcu]
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
defines += [f"HW_MODEL={hw_model}"]
defines += [f"HW_REVISION={hw_revision}"]
sources += [
"embed/models/model_T3T1_layout.c",
]
sources += [f"embed/trezorhal/stm32u5/displays/{display}"]
sources += ["embed/trezorhal/stm32u5/backlight_pwm.c"]
sources += [
"embed/trezorhal/stm32u5/displays/panels/lx154a2422.c",
]
env_constraints = env.get("CONSTRAINTS")
if not (env_constraints and "limited_util_s" in env_constraints):
sources += ["embed/trezorhal/stm32u5/bg_copy.c"]
features_available.append("backlight")
if "input" in features_wanted:
sources += ["embed/trezorhal/stm32u5/i2c.c"]
sources += ["embed/trezorhal/stm32u5/touch/ft6x36.c"]
sources += ["embed/lib/touch.c"]
features_available.append("touch")
if "haptic" in features_wanted:
sources += [
"embed/trezorhal/stm32u5/haptic/drv2625/drv2625.c",
]
sources += [
"vendor/stm32u5xx_hal_driver/Src/stm32u5xx_hal_tim.c",
"vendor/stm32u5xx_hal_driver/Src/stm32u5xx_hal_tim_ex.c",
]
features_available.append("haptic")
if "sd_card" in features_wanted:
sources += ["embed/trezorhal/stm32u5/sdcard.c"]
sources += ["embed/trezorhal/stm32u5/stm32u5xx_hal_sd.c"]
sources += ["embed/extmod/modtrezorio/ff.c"]
sources += ["embed/extmod/modtrezorio/ffunicode.c"]
features_available.append("sd_card")
sources += ["vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_sdmmc.c"]
if "sbu" in features_wanted:
sources += ["embed/trezorhal/stm32u5/sbu.c"]
features_available.append("sbu")
if "usb" in features_wanted:
sources += [
"embed/trezorhal/stm32u5/usb.c",
"embed/trezorhal/stm32u5/usbd_conf.c",
"embed/trezorhal/stm32u5/usbd_core.c",
"embed/trezorhal/stm32u5/usbd_ctlreq.c",
"embed/trezorhal/stm32u5/usbd_ioreq.c",
"vendor/stm32u5xx_hal_driver/Src/stm32u5xx_ll_usb.c",
]
features_available.append("usb")
if "dma2d" in features_wanted:
defines += ["USE_DMA2D"]
sources += ["embed/trezorhal/stm32u5/dma2d.c"]
features_available.append("dma2d")
if "optiga" in features_wanted:
defines += ["USE_OPTIGA=1"]
sources += ["embed/trezorhal/stm32u5/optiga_hal.c"]
sources += ["embed/trezorhal/optiga/optiga.c"]
sources += ["embed/trezorhal/optiga/optiga_commands.c"]
sources += ["embed/trezorhal/optiga/optiga_transport.c"]
sources += ["vendor/trezor-crypto/hash_to_curve.c"]
features_available.append("optiga")
env.get("ENV")["TREZOR_BOARD"] = board
env.get("ENV")["MCU_TYPE"] = mcu
env.get("ENV")["LINKER_SCRIPT"] = linker_script
defs = env.get("CPPDEFINES_IMPLICIT")
defs += ["__ARM_FEATURE_CMSE=3"]
rust_defs = env.get("ENV")["RUST_INCLUDES"]
rust_defs += "-DFRAMEBUFFER;"
env.get("ENV")["RUST_INCLUDES"] = rust_defs
return features_available

View File

@ -13,6 +13,7 @@ from boards import (
trezor_r_v6, trezor_r_v6,
trezor_r_v10, trezor_r_v10,
trezor_t, trezor_t,
trezor_t3t1_revE,
trezor_t3t1_v4, trezor_t3t1_v4,
) )
@ -44,6 +45,7 @@ def configure_board(
paths: list[str], paths: list[str],
) -> list[str]: ) -> list[str]:
model_r_version = 10 model_r_version = 10
model_t3t1_version = "E"
if model in ("1",): if model in ("1",):
return trezor_1.configure(env, features_wanted, defines, sources, paths) return trezor_1.configure(env, features_wanted, defines, sources, paths)
@ -60,7 +62,15 @@ def configure_board(
return trezor_r_v10.configure(env, features_wanted, defines, sources, paths) return trezor_r_v10.configure(env, features_wanted, defines, sources, paths)
raise Exception("Unknown model_r_version") raise Exception("Unknown model_r_version")
elif model in ("T3T1",): elif model in ("T3T1",):
return trezor_t3t1_v4.configure(env, features_wanted, defines, sources, paths) if model_t3t1_version == 4:
return trezor_t3t1_v4.configure(
env, features_wanted, defines, sources, paths
)
elif model_t3t1_version == "E":
return trezor_t3t1_revE.configure(
env, features_wanted, defines, sources, paths
)
raise Exception("Unknown model_t3t1_version")
elif model in ("DISC1",): elif model in ("DISC1",):
return discovery.configure(env, features_wanted, defines, sources, paths) return discovery.configure(env, features_wanted, defines, sources, paths)
elif model in ("DISC2",): elif model in ("DISC2",):