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 all 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
2 changes: 1 addition & 1 deletion core/embed/io/display/st-7789/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void display_deinit(display_content_mode_t mode) {
#endif
#endif

mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

backlight_pwm_deinit(mode == DISPLAY_RESET_CONTENT ? BACKLIGHT_RESET
: BACKLIGHT_RETAIN);
Expand Down
9 changes: 7 additions & 2 deletions core/embed/io/display/st-7789/display_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ static uint8_t *get_fb_ptr(uint32_t index) {

void display_physical_fb_clear(void) {
for (int i = 0; i < FRAME_BUFFER_COUNT; i++) {
mpu_set_active_fb(get_fb_ptr(i), PHYSICAL_FRAME_BUFFER_SIZE);
memset(get_fb_ptr(i), 0, PHYSICAL_FRAME_BUFFER_SIZE);
}
mpu_set_active_fb(NULL, 0);
}

#ifndef BOARDLOADER
Expand Down Expand Up @@ -198,7 +200,7 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->ptr = get_fb_ptr(drv->queue.wix);
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);
mpu_set_active_fb(fb->ptr, PHYSICAL_FRAME_BUFFER_SIZE);

return true;
}
Expand All @@ -208,12 +210,15 @@ static void copy_fb_to_display(uint8_t index) {
uint16_t *fb = (uint16_t *)get_fb_ptr(index);

if (fb != NULL) {
mpu_set_active_fb(fb, PHYSICAL_FRAME_BUFFER_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding this, the copy_fb_to_display function now has the side effect of disabling the frame buffer (for both privileged and unprivileged modes). This slightly impacts the display API behavior - after calling display_set_orientation, the acquired frame buffer is no longer accessible. I believe we don’t need to fix this, but it’s important to be aware of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in person, lets postpone fixing this until needed

display_panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY; i++) {
// 2 bytes per pixel because we're using RGB 5-6-5 format
ISSUE_PIXEL_DATA(fb[i]);
}
}

mpu_set_active_fb(NULL, 0);
}

static void wait_for_te_signal(void) {
Expand All @@ -238,7 +243,7 @@ void display_refresh(void) {
}

// Disable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

#ifndef BOARDLOADER
if (is_mode_exception()) {
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_active_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: 3 additions & 3 deletions core/embed/io/display/stm32f429i-disc1/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void display_init(display_content_mode_t mode) {
void display_deinit(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver;

mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

drv->initialized = false;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->ptr = (void *)drv->framebuf;
fb->stride = DISPLAY_RESX * sizeof(uint16_t);
// Enable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(fb->ptr, FRAME_BUFFER_SIZE);
mpu_set_active_fb(fb->ptr, FRAME_BUFFER_SIZE);
return true;
}
}
Expand All @@ -145,7 +145,7 @@ void display_refresh(void) {
// Do nothing as using just a single frame buffer

// Disable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);
}

void display_fill(const gfx_bitblt_t *bb) {
Expand Down
9 changes: 7 additions & 2 deletions core/embed/io/display/stm32u5a9j-dk/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,21 @@ void display_init(display_content_mode_t mode) {
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

// Clear framebuffers
mpu_set_active_fb(physical_frame_buffer_0, PHYSICAL_FRAME_BUFFER_SIZE);
memset(physical_frame_buffer_0, 0x00, PHYSICAL_FRAME_BUFFER_SIZE);

mpu_set_active_fb(physical_frame_buffer_1, PHYSICAL_FRAME_BUFFER_SIZE);
memset(physical_frame_buffer_1, 0x00, PHYSICAL_FRAME_BUFFER_SIZE);

mpu_set_active_fb(NULL, 0);

BSP_LCD_Init(0, LCD_ORIENTATION_PORTRAIT);
BSP_LCD_SetBrightness(0, 100);
BSP_LCD_DisplayOn(0);
} else {
// Retain display content
BSP_LCD_Reinit(0);
if (current_frame_buffer == 0) {
if (drv->current_frame_buffer == 0) {
BSP_LCD_SetFrameBuffer(0, GFXMMU_VIRTUAL_BUFFER1_BASE_S);
} else {
BSP_LCD_SetFrameBuffer(0, GFXMMU_VIRTUAL_BUFFER0_BASE_S);
Expand Down Expand Up @@ -110,7 +115,7 @@ void display_deinit(display_content_mode_t mode) {
BSP_LCD_DeInit(0);
}

mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

drv->initialized = false;
}
Expand Down
17 changes: 6 additions & 11 deletions core/embed/io/display/stm32u5a9j-dk/display_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ uint8_t physical_frame_buffer_0[PHYSICAL_FRAME_BUFFER_SIZE];
__attribute__((section(".fb2"), aligned(PHYSICAL_FRAME_BUFFER_ALIGNMENT)))
uint8_t physical_frame_buffer_1[PHYSICAL_FRAME_BUFFER_SIZE];

// The current frame buffer selector at fixed memory address
// It's shared between bootloaders and the firmware
__attribute__((section(".framebuffer_select"))) uint32_t current_frame_buffer =
0;

#ifdef USE_TRUSTZONE
void display_set_unpriv_access(bool unpriv) {
// To allow unprivileged access both GFXMMU virtual buffers area and
Expand Down Expand Up @@ -85,7 +80,7 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {

uintptr_t addr;

if (current_frame_buffer == 0) {
if (drv->current_frame_buffer == 0) {
addr = GFXMMU_VIRTUAL_BUFFER1_BASE_S;
} else {
addr = GFXMMU_VIRTUAL_BUFFER0_BASE_S;
Expand All @@ -102,7 +97,7 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->stride = fb_stride;

// Enable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(fb->ptr, VIRTUAL_FRAME_BUFFER_SIZE);
mpu_set_active_fb(fb->ptr, VIRTUAL_FRAME_BUFFER_SIZE);

return true;
}
Expand All @@ -115,13 +110,13 @@ void display_refresh(void) {
}

// Disable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

if (current_frame_buffer == 0) {
current_frame_buffer = 1;
if (drv->current_frame_buffer == 0) {
drv->current_frame_buffer = 1;
BSP_LCD_SetFrameBuffer(0, GFXMMU_VIRTUAL_BUFFER1_BASE_S);
} else {
current_frame_buffer = 0;
drv->current_frame_buffer = 0;
BSP_LCD_SetFrameBuffer(0, GFXMMU_VIRTUAL_BUFFER0_BASE_S);
}
}
Expand Down
9 changes: 3 additions & 6 deletions core/embed/io/display/stm32u5a9j-dk/display_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef struct {
int orientation_angle;
// Current backlight level ranging from 0 to 255
int backlight_level;
// The current frame buffer selector
uint32_t current_frame_buffer;
} display_driver_t;

// Display driver instance
Expand Down Expand Up @@ -64,16 +66,11 @@ extern display_driver_t g_display_driver;

// Physical frame buffers in internal SRAM memory
//
// Both frame buffers layes in the fixed addresses that
// Both frame buffers layers in the fixed addresses that
// are shared between bootloaders and the firmware.
extern uint8_t physical_frame_buffer_0[PHYSICAL_FRAME_BUFFER_SIZE];
extern uint8_t physical_frame_buffer_1[PHYSICAL_FRAME_BUFFER_SIZE];

// The current frame buffer selector at fixed memory address
//
// The variable address is shared between bootloaders and the firmware
extern uint32_t current_frame_buffer;

// LCD orientations
#define LCD_ORIENTATION_PORTRAIT 0U
#define LCD_ORIENTATION_LANDSCAPE 1U
Expand Down
6 changes: 1 addition & 5 deletions core/embed/io/display/stm32u5a9j-dk/display_ltdc_dsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ LTDC_HandleTypeDef hlcd_ltdc = {0};
DSI_HandleTypeDef hlcd_dsi = {0};
static DSI_VidCfgTypeDef DSIVidCfg = {0};

__attribute__((section(".gfxmmu_table")))
uint32_t gfxmmu_lut[2 * GFXMMU_LUT_SIZE];

/**
* @}
*/
Expand Down Expand Up @@ -207,7 +204,6 @@ int32_t BSP_LCD_Init(uint32_t Instance, uint32_t Orientation) {
memset(&hlcd_ltdc, 0, sizeof(hlcd_ltdc));
memset(&hlcd_dsi, 0, sizeof(hlcd_dsi));
memset(&DSIVidCfg, 0, sizeof(DSIVidCfg));
memcpy(gfxmmu_lut, gfxmmu_lut_config, sizeof(gfxmmu_lut));

int32_t status = BSP_ERROR_NONE;

Expand Down Expand Up @@ -989,7 +985,7 @@ static int32_t LCD_Init(void) {
}
/* Initialize LUT */
else if (HAL_GFXMMU_ConfigLut(&hlcd_gfxmmu, 0, LCD_WIDTH,
(uint32_t)&gfxmmu_lut) != HAL_OK) {
(uint32_t)&gfxmmu_lut_config) != HAL_OK) {
status = BSP_ERROR_PERIPH_FAILURE;
} else {
/* Disable non visible lines : from line 480 to 1023 */
Expand Down
9 changes: 6 additions & 3 deletions core/embed/io/display/vg-2864/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ static void display_sync_with_fb(display_driver_t *drv) {

// Send whole framebuffer to the display

mpu_set_active_fb(drv->framebuf, FRAME_BUFFER_SIZE);

if (drv->orientation_angle == 0) {
for (int y = DISPLAY_RESY / 8 - 1; y >= 0; y--) {
uint8_t buff[DISPLAY_RESX];
Expand Down Expand Up @@ -233,6 +235,7 @@ static void display_sync_with_fb(display_driver_t *drv) {

while (HAL_SPI_STATE_READY != HAL_SPI_GetState(&drv->spi)) {
}
mpu_set_active_fb(NULL, 0);

// SPI deselect
HAL_GPIO_WritePin(OLED_CS_PORT, OLED_CS_PIN, GPIO_PIN_SET);
Expand Down Expand Up @@ -321,7 +324,7 @@ void display_init(display_content_mode_t mode) {
void display_deinit(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver;

mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

drv->initialized = false;
}
Expand Down Expand Up @@ -391,7 +394,7 @@ bool display_get_frame_buffer(display_fb_info_t *fb) {
fb->ptr = &drv->framebuf[0];
fb->stride = DISPLAY_RESX;
// Enable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(fb->ptr, FRAME_BUFFER_SIZE);
mpu_set_active_fb(fb->ptr, FRAME_BUFFER_SIZE);
return true;
}
}
Expand All @@ -410,7 +413,7 @@ void display_refresh(void) {
#endif

// Disable access to the frame buffer from the unprivileged code
mpu_set_unpriv_fb(NULL, 0);
mpu_set_active_fb(NULL, 0);

// Copy the frame buffer to the display
display_sync_with_fb(drv);
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
Loading
Loading