From 9e5d61752c53a568853e950f3e1d47d19f416345 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 21 Mar 2017 15:56:50 +0100 Subject: [PATCH] trezorhal: use display_print instead of mp_hal_stdout in our version of stm32_it.c --- Makefile.bootloader | 5 ----- Makefile.loader | 5 ----- micropython/bootloader/main.c | 3 ++- micropython/loader/main.c | 5 ++++- micropython/trezorhal/stm32_it.c | 31 +++++++++++++++---------------- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Makefile.bootloader b/Makefile.bootloader index 86ae89a4..5ac30ff2 100644 --- a/Makefile.bootloader +++ b/Makefile.bootloader @@ -50,12 +50,7 @@ OBJ_MP += $(addprefix $(BUILD_MP)/,\ stmhal/hal/f4/src/stm32f4xx_ll_sdmmc.o \ stmhal/hal/f4/src/stm32f4xx_ll_usb.o \ \ - py/mpstate.o \ - py/nlrthumb.o \ - \ - stmhal/pendsv.o \ stmhal/startup_stm32.o \ - stmhal/systick.o \ ) # OBJ micropython/ diff --git a/Makefile.loader b/Makefile.loader index 73feefbe..c4e38230 100644 --- a/Makefile.loader +++ b/Makefile.loader @@ -50,12 +50,7 @@ OBJ_MP += $(addprefix $(BUILD_MP)/,\ stmhal/hal/f4/src/stm32f4xx_ll_sdmmc.o \ stmhal/hal/f4/src/stm32f4xx_ll_usb.o \ \ - py/mpstate.o \ - py/nlrthumb.o \ - \ - stmhal/pendsv.o \ stmhal/startup_stm32.o \ - stmhal/systick.o \ ) # OBJ micropython/ diff --git a/micropython/bootloader/main.c b/micropython/bootloader/main.c index 9d38fb15..77b9a07f 100644 --- a/micropython/bootloader/main.c +++ b/micropython/bootloader/main.c @@ -16,7 +16,8 @@ #define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0) #define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0) -void mp_hal_stdout_tx_str(const char *str) { +void pendsv_isr_handler(void) { + __fatal_error("pendsv"); } void periph_init(void) diff --git a/micropython/loader/main.c b/micropython/loader/main.c index a69f55bc..f0103bf5 100644 --- a/micropython/loader/main.c +++ b/micropython/loader/main.c @@ -3,7 +3,10 @@ #include "common.h" #include "display.h" -void mp_hal_stdout_tx_str(const char *str) { +#define FIRMWARE_START 0x08020000 + +void pendsv_isr_handler(void) { + __fatal_error("pendsv"); } void periph_init(void) diff --git a/micropython/trezorhal/stm32_it.c b/micropython/trezorhal/stm32_it.c index fe852b20..8727ebbb 100644 --- a/micropython/trezorhal/stm32_it.c +++ b/micropython/trezorhal/stm32_it.c @@ -65,14 +65,13 @@ ****************************************************************************** */ -#include - #include STM32_HAL_H -#include "py/mphal.h" #include "pendsv.h" #include "gccollect.h" +#include "display.h" + #define IRQ_ENTER(irq) #define IRQ_EXIT(irq) @@ -86,7 +85,7 @@ extern void __fatal_error(const char*); // More information about decoding the fault registers can be found here: // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0646a/Cihdjcfc.html -STATIC char *fmt_hex(uint32_t val, char *buf) { +static char *fmt_hex(uint32_t val, char *buf) { const char *hexDig = "0123456789abcdef"; buf[0] = hexDig[(val >> 28) & 0x0f]; @@ -102,21 +101,21 @@ STATIC char *fmt_hex(uint32_t val, char *buf) { return buf; } -STATIC void print_reg(const char *label, uint32_t val) { +static void print_reg(const char *label, uint32_t val) { char hexStr[9]; - mp_hal_stdout_tx_str(label); - mp_hal_stdout_tx_str(fmt_hex(val, hexStr)); - mp_hal_stdout_tx_str("\r\n"); + display_print(label, -1); + display_print(fmt_hex(val, hexStr), -1); + display_print("\n", 1); } -STATIC void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { +static void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { char hex_str[9]; - mp_hal_stdout_tx_str(label); - mp_hal_stdout_tx_str(fmt_hex(val1, hex_str)); - mp_hal_stdout_tx_str(" "); - mp_hal_stdout_tx_str(fmt_hex(val2, hex_str)); - mp_hal_stdout_tx_str("\r\n"); + display_print(label, -1 ); + display_print(fmt_hex(val1, hex_str), -1); + display_print(" ", 2); + display_print(fmt_hex(val2, hex_str), -1); + display_print("\n", 1); } // The ARMv7M Architecture manual (section B.1.5.6) says that upon entry @@ -138,7 +137,7 @@ void HardFault_C_Handler(ExceptionRegisters_t *regs) { // the VCP and then block indefinitely waiting for the buffer to drain. // pyb_usb_flags = 0; - mp_hal_stdout_tx_str("HardFault\r\n"); + display_print("HardFault\n", -1); print_reg("R0 ", regs->r0); print_reg("R1 ", regs->r1); @@ -162,7 +161,7 @@ void HardFault_C_Handler(ExceptionRegisters_t *regs) { } if ((void*)&_ram_start <= (void*)regs && (void*)regs < (void*)&_ram_end) { - mp_hal_stdout_tx_str("Stack:\r\n"); + display_print("Stack:\n", -1); uint32_t *stack_top = &_estack; if ((void*)regs < (void*)&_heap_end) { // stack not in static stack area so limit the amount we print