Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ if PRODUCTION_MODEL == 'H':
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dcmi.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c',
Expand Down Expand Up @@ -223,6 +224,7 @@ SOURCE_TREZORHAL = [
'embed/trezorhal/camera.c',
'embed/trezorhal/gt911.c',
'embed/trezorhal/sdram.c',
'embed/trezorhal/stm32_it_handler.c',

]

Expand Down
1 change: 1 addition & 0 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ if PRODUCTION_MODEL == 'H':
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dcmi.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c',
'vendor/micropython/lib/stm32lib/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c',
Expand Down
7 changes: 7 additions & 0 deletions core/embed/bootloader/memory.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ MEMORY {
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 256K
AXIRAM (wal) : ORIGIN = 0x24000000, LENGTH = 512K
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 128K
/* SRAM3 is used for DMA */
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 32K
}

main_stack_base = ORIGIN(SRAM) + LENGTH(SRAM); /* 8-byte aligned full descending stack */
Expand Down Expand Up @@ -55,6 +57,11 @@ SECTIONS {
. = 4K; /* this acts as a build time assertion that at least this much memory is available for stack use */
} >SRAM

.sram3 : ALIGN(4) {
*(.sram3*);
. = ALIGN(4);
} >SRAM3

/* this is needed, otherwise will have "undefined reference to `end'" error */
.heap : ALIGN(4) {
PROVIDE ( end = . );
Expand Down
84 changes: 13 additions & 71 deletions core/embed/extmod/modtrezorio/modtrezorio-poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "spi_legacy.h"
#include "usart.h"

#define SPI_IFACE (6)
#define FINGERPRINT_IFACE (7)
#define USB_DATA_IFACE (253)
#define BUTTON_IFACE (254)
Expand All @@ -37,8 +36,9 @@
#define UART_IFACE (127)
#define USB_STATE_IFACE (128)
#define LOCAL_IFACE (99)
#define SPI_IFACE (100)
#define SPI_FIDO_IFACE (101)

extern bool usb_connected_previously;
extern bool local_interface_ready;

/// package: trezorio.__init__
Expand Down Expand Up @@ -90,72 +90,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
#endif

if (false) {
}
#if defined TREZOR_MODEL_T
else if (iface == TOUCH_IFACE) {
const uint32_t evt = touch_read();
if (evt) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
const uint32_t etype = (evt >> 24) & 0xFFU; // event type
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
const uint32_t ey = evt & 0xFFFU; // y position
uint32_t exr; // rotated x position
uint32_t eyr; // rotated y position
switch (display_orientation(-1)) {
case 90:
exr = ey;
eyr = DISPLAY_RESX - ex;
break;
case 180:
exr = DISPLAY_RESX - ex;
eyr = DISPLAY_RESY - ey;
break;
case 270:
exr = DISPLAY_RESY - ey;
eyr = ex;
break;
default:
exr = ex;
eyr = ey;
break;
}
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(etype);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(exr);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(eyr);
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
return mp_const_true;
}
} else if (iface == USB_DATA_IFACE) {
bool usb_connected = usb_configured() == sectrue ? true : false;
if (usb_connected != usb_connected_previously) {
usb_connected_previously = usb_connected;
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = usb_connected ? mp_const_true : mp_const_false;
return mp_const_true;
}
}
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
else if (iface == BUTTON_IFACE) {
const uint32_t evt = button_read();
if (evt & (BTN_EVT_DOWN | BTN_EVT_UP)) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
uint32_t etype = (evt >> 24) & 0x3U; // button down/up
uint32_t en = evt & 0xFFFF; // button number
if (display_orientation(-1) == 180) {
en = (en == BTN_LEFT) ? BTN_RIGHT : BTN_LEFT;
}
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(etype);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(en);
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
return mp_const_true;
}
}
#else
#error Unknown Trezor model
#endif
else if (iface == USB_STATE_IFACE) {
} else if (iface == USB_STATE_IFACE) {
static bool usb_connect = false, usb_connect_bak = false;
static bool usb_open = false, usb_open_bak = false;
static int counter0 = 0, counter1 = 0;
Expand Down Expand Up @@ -237,15 +172,22 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
local_interface_ready = false;
return mp_const_true;
}
} // TODO:FIX IT
else if (iface == SPI_IFACE) {
} else if (iface == SPI_IFACE) {
uint8_t buf[64] = {0};
int len = spi_slave_poll(buf);
if (len > 0) {
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = mp_obj_new_bytes(buf, len);
return mp_const_true;
}
} else if (iface == SPI_FIDO_IFACE) {
uint8_t buf[1024] = {0};
int len = spi_slave_poll_fido(buf);
if (len > 0) {
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = mp_obj_new_bytes(buf, len);
return mp_const_true;
}
}
} else if (mode == POLL_WRITE) {
int res = usb_webusb_can_write(iface);
Expand All @@ -261,7 +203,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = mp_const_false;
return mp_const_true;
} else if (iface == SPI_IFACE) {
} else if (iface == SPI_IFACE || iface == SPI_FIDO_IFACE) {
if (sectrue == spi_can_write()) {
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = mp_const_true;
Expand Down
2 changes: 1 addition & 1 deletion core/embed/extmod/modtrezorio/modtrezorio-spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_SPI_iface_num_obj,
STATIC mp_obj_t mod_trezorio_SPI_write(mp_obj_t self, mp_obj_t msg) {
mp_buffer_info_t buf = {0};
mp_get_buffer_raise(msg, &buf, MP_BUFFER_READ);
ssize_t r = spi_slave_send(buf.buf, buf.len, 100);
ssize_t r = spi_slave_send(buf.buf, buf.len, 500);
return MP_OBJ_NEW_SMALL_INT(r);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_SPI_write_obj,
Expand Down
9 changes: 6 additions & 3 deletions core/embed/extmod/modtrezorio/modtrezorio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#include "touch.h"
#include "usb.h"

// Whether USB data pins were connected on last check (USB configured)
bool usb_connected_previously = true;

bool local_interface_ready = false;

#define CHECK_PARAM_RANGE(value, minimum, maximum) \
Expand Down Expand Up @@ -83,6 +80,9 @@ bool local_interface_ready = false;
/// BUTTON_LEFT: int # button number of left button
/// BUTTON_RIGHT: int # button number of right button

/// SPI_FACE: int # interface id of the spi events
/// SPI_FIDO_FACE: int # interface id of the spi fido events

/// WireInterface = Union[HID, WebUSB, SPI]
/// USB_CHECK: int # interface id for check of USB data connection
/// FINGERPRINT_STATE: int # interface id of the fingerprint state events
Expand Down Expand Up @@ -134,6 +134,9 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_LOCAL_CTL), MP_ROM_PTR(&mod_trezorio_LOCAL_CTL_type)},

{MP_ROM_QSTR(MP_QSTR_USB_CHECK), MP_ROM_INT(USB_DATA_IFACE)},

{MP_ROM_QSTR(MP_QSTR_SPI_FACE), MP_ROM_INT(SPI_IFACE)},
{MP_ROM_QSTR(MP_QSTR_SPI_FIDO_FACE), MP_ROM_INT(SPI_FIDO_IFACE)},
};

STATIC MP_DEFINE_CONST_DICT(mp_module_trezorio_globals,
Expand Down
7 changes: 7 additions & 0 deletions core/embed/firmware/memory_H.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ MEMORY {
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 128K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 128K
SRAM2 (wal) : ORIGIN = 0x30020000, LENGTH = 128K
/* SRAM3 is used for DMA */
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 32K
EXRAM (wal) : ORIGIN = 0xD1C00000, LENGTH = 2048K
}

Expand Down Expand Up @@ -80,6 +82,11 @@ SECTIONS {
*(sram1)
} >SRAM1

.sram3 : ALIGN(4) {
*(.sram3*);
. = ALIGN(4);
} >SRAM3

.bss2 : ALIGN(4) {
*(.bss.global_image);
*(.bss.global_feature);
Expand Down
5 changes: 0 additions & 5 deletions core/embed/fp_sensor_wrapper/fpsensor_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ uint8_t fpsensor_gpio_init()
return FPSENSOR_OK;
}

void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);
}

void fpsensor_state_set(bool state)
{
fp_touched = state;
Expand Down
2 changes: 0 additions & 2 deletions core/embed/trezorhal/gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ void gt911_enable_irq(void) {

void gt911_disable_irq(void) { HAL_NVIC_DisableIRQ(EXTI2_IRQn); }

void EXTI2_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); }

void gt911_test(void) {
while (1) {
gt911_read_location();
Expand Down
Loading
Loading