Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T3W1 PCB bring-up #4350

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ffae78b
fix(core): fix clock setting on U5 for 32 MHz HSE
TychoVrahe Nov 14, 2024
7702173
chore(core): remove old RGB LED driver
TychoVrahe Nov 14, 2024
e357339
feat(core): implement RGB LED driver for T3W1
TychoVrahe Nov 14, 2024
b8daebf
feat(core): add RGB LED syscalls
TychoVrahe Nov 14, 2024
79f720a
feat(core): add power button to T3W1 board rev A
TychoVrahe Nov 14, 2024
8b5f79b
fix(core): fix systick frequency computation by utilizing HSE_VALUE p…
TychoVrahe Nov 15, 2024
2489965
feat(core): support 32MHz HSE in USB driver (HS internal PHY only)
TychoVrahe Nov 15, 2024
69079b4
chore(core): improve T3W1 driver mock so it doesn't crash
TychoVrahe Nov 15, 2024
650daeb
feat(core): allow touchless mode in T3W1 bootloader
TychoVrahe Nov 15, 2024
7dbac51
fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 15, 2024
c538c56
feat(core): add support for SBU on T3W1
TychoVrahe Nov 15, 2024
6aad200
feat(core): support optiga on T3W1
TychoVrahe Nov 15, 2024
c927e91
fixup! feat(core): allow touchless mode in T3W1 bootloader
TychoVrahe Nov 18, 2024
9aa2f2b
fix(core): fix prodtest for 32 bit color models
TychoVrahe Nov 18, 2024
78a1829
fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 18, 2024
7743a1b
fixup! fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 18, 2024
42dcd36
fixup! fixup! fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 18, 2024
c4d30fd
fixup! fix(core): fix systick frequency computation by utilizing HSE_…
TychoVrahe Nov 18, 2024
72413ea
fixup! fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 19, 2024
10e3635
fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 19, 2024
6b3babc
fixup! fix(core): fix MPU kernel sram setting for STM32U5G
TychoVrahe Nov 19, 2024
0be697c
fix(core): separate bootargs from kernel/aux SRAM
TychoVrahe Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FEATURE_FLAGS = {
"AES_GCM": BENCHMARK or THP,
}

FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
if DISABLE_OPTIGA and PYOPT == '0':
FEATURES_WANTED.remove("optiga")

Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FEATURE_FLAGS = {
"AES_GCM": False,
}

FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic"]
if DISABLE_OPTIGA and PYOPT == '0':
FEATURES_WANTED.remove("optiga")

Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if BENCHMARK and PYOPT != '0':
print("BENCHMARK=1 works only with PYOPT=0.")
exit(1)

FEATURES_WANTED = ["input", "sd_card", "dma2d", "optiga", "sbu"]
FEATURES_WANTED = ["input", "sd_card", "dma2d", "optiga"]

if not models.has_emulator(TREZOR_MODEL):
# skip unix build
Expand Down
76 changes: 70 additions & 6 deletions core/embed/io/display/st7785ma/display_driver.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,88 @@

#include <sys/systick.h>
#ifdef KERNEL_MODE

#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>

#include <io/display.h>
#include <sys/mpu.h>
#include <sys/trustzone.h>
#include "../backlight/backlight_pwm.h"

#ifdef KERNEL_MODE
void display_init(display_content_mode_t mode) {}
// Hardware requires physical frame buffer alignment
#ifdef USE_TRUSTZONE
#define PHYSICAL_FRAME_BUFFER_ALIGNMENT TZ_SRAM_ALIGNMENT
#else
#define PHYSICAL_FRAME_BUFFER_ALIGNMENT 32
#endif

// Size of the physical frame buffer in bytes
#define PHYSICAL_FRAME_BUFFER_SIZE \
ALIGN_UP_CONST(DISPLAY_RESX *DISPLAY_RESY * 2, \
PHYSICAL_FRAME_BUFFER_ALIGNMENT)

static
__attribute__((section(".fb1"), aligned(PHYSICAL_FRAME_BUFFER_ALIGNMENT)))
uint8_t physical_frame_buffer_0[PHYSICAL_FRAME_BUFFER_SIZE];

#if (FRAME_BUFFER_COUNT > 1)
static
__attribute__((section(".fb2"), aligned(PHYSICAL_FRAME_BUFFER_ALIGNMENT)))
uint8_t physical_frame_buffer_1[PHYSICAL_FRAME_BUFFER_SIZE];
#endif

void display_init(display_content_mode_t mode) {
__HAL_RCC_GPIOE_CLK_ENABLE();

void display_deinit(display_content_mode_t mode) {}
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Alternate = 0;
GPIO_InitStructure.Pin = GPIO_PIN_2;
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);

GPIO_InitStructure.Pin = GPIO_PIN_0;
// default to keeping display in reset
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);

hal_delay(100);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET);

backlight_pwm_init(mode);
}

void display_deinit(display_content_mode_t mode) { backlight_pwm_deinit(mode); }

void display_set_unpriv_access(bool unpriv) {}

int display_set_backlight(int level) { return level; }
int display_set_backlight(int level) {
return 0;
// return backlight_pwm_set(level);
}

int display_get_backlight(void) { return 0; }
int display_get_backlight(void) { return backlight_pwm_get(); }

int display_set_orientation(int angle) { return angle; }
int display_get_orientation(void) { return 0; }
bool display_get_frame_buffer(display_fb_info_t *fb) { return true; }

// Returns the pointer to the physical frame buffer (0.. FRAME_BUFFER_COUNT-1)
// Returns NULL if the framebuffer index is out of range.
static uint8_t *get_fb_ptr(uint32_t index) { return physical_frame_buffer_0; }

bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->ptr = get_fb_ptr(0);
fb->stride = DISPLAY_RESX * sizeof(uint16_t);
// Enable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(fb->ptr, PHYSICAL_FRAME_BUFFER_SIZE);

return true;
}

void display_refresh(void) {}
void display_fill(const gfx_bitblt_t *bb) {}
Expand Down
6 changes: 6 additions & 0 deletions core/embed/io/rgb_led/inc/io/rgb_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@

#ifdef KERNEL_MODE

// Initialize RGB LED driver
void rgb_led_init(void);

// Deinitialize RGB LED driver
void rgb_led_deinit(void);

#endif

// Set RGB LED color
// color: 24-bit RGB color, 0x00RRGGBB
void rgb_led_set_color(uint32_t color);

#endif // TREZORHAL_RGB_LED_H
96 changes: 96 additions & 0 deletions core/embed/io/rgb_led/stm32/rgb_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#ifdef KERNEL_MODE

#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>

#include <io/rgb_led.h>

#define LED_SWITCHING_FREQUENCY_HZ 20000
#define TIMER_PERIOD (SystemCoreClock / LED_SWITCHING_FREQUENCY_HZ)

typedef struct {
TIM_HandleTypeDef tim;
bool initialized;
} rgb_led_t;

static rgb_led_t g_rgb_led = {0};

void rgb_led_init(void) {
rgb_led_t* drv = &g_rgb_led;
if (drv->initialized) {
return;
}

memset(drv, 0, sizeof(*drv));

__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_TIM4_CLK_ENABLE();
__HAL_RCC_TIM4_FORCE_RESET();
__HAL_RCC_TIM4_RELEASE_RESET();

GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8;
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Alternate = GPIO_AF2_TIM4;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

drv->tim.State = HAL_TIM_STATE_RESET;
drv->tim.Instance = TIM4;
drv->tim.Init.Period = TIMER_PERIOD;
drv->tim.Init.Prescaler = 0;
drv->tim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
drv->tim.Init.CounterMode = TIM_COUNTERMODE_UP;
drv->tim.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&drv->tim);

// OC initialization
TIM_OC_InitTypeDef OC_Init = {0};
OC_Init.OCMode = TIM_OCMODE_PWM2;
OC_Init.Pulse = 0;
OC_Init.OCPolarity = TIM_OCPOLARITY_HIGH;
OC_Init.OCFastMode = TIM_OCFAST_DISABLE;
OC_Init.OCIdleState = TIM_OCIDLESTATE_RESET;
HAL_TIM_PWM_ConfigChannel(&drv->tim, &OC_Init, TIM_CHANNEL_1);
HAL_TIM_PWM_ConfigChannel(&drv->tim, &OC_Init, TIM_CHANNEL_2);
HAL_TIM_PWM_ConfigChannel(&drv->tim, &OC_Init, TIM_CHANNEL_3);

HAL_TIM_Base_Start(&drv->tim);

HAL_TIM_PWM_Start(&drv->tim, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&drv->tim, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&drv->tim, TIM_CHANNEL_3);

drv->initialized = true;
}

void rgb_led_deinit(void) {
rgb_led_t* drv = &g_rgb_led;
if (!drv->initialized) {
return;
}

HAL_TIM_PWM_Stop(&drv->tim, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&drv->tim, TIM_CHANNEL_2);
HAL_TIM_PWM_Stop(&drv->tim, TIM_CHANNEL_3);

HAL_TIM_Base_Stop(&drv->tim);

memset(drv, 0, sizeof(*drv));
drv->initialized = false;
}

void rgb_led_set_color(uint32_t color) {
rgb_led_t* drv = &g_rgb_led;
if (!drv->initialized) {
return;
}

TIM4->CCR1 = ((color >> 16) & 0xFF) * TIMER_PERIOD / 255;
TIM4->CCR2 = ((color >> 8) & 0xFF) * TIMER_PERIOD / 255;
TIM4->CCR3 = (color & 0xFF) * TIMER_PERIOD / 255;
}

#endif
Loading
Loading