From c9857a756cf47b3aee807722ecb56df634c9519f Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Thu, 29 Sep 2016 14:38:31 +0200 Subject: [PATCH] bootloader: added systick handler --- Makefile | 4 ++-- bootloader/bootloader.c | 50 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f8fef56c9c..22e5d50c99 100644 --- a/Makefile +++ b/Makefile @@ -89,10 +89,10 @@ openocd: ## start openocd which connects to the device openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg gdb: ## start remote gdb session which connects to the openocd - gdb $(STMHAL_BUILD_DIR)/firmware.elf -ex 'target remote localhost:3333' + arm-none-eabi-gdb $(STMHAL_BUILD_DIR)/firmware.elf -ex 'target remote localhost:3333' gdb_bootloader: ## start remote gdb session which connects to the openocd - gdb $(STMHAL_BUILD_DIR)/bootloader.elf -ex 'target remote localhost:3333' + arm-none-eabi-gdb $(STMHAL_BUILD_DIR)/bootloader.elf -ex 'target remote localhost:3333' load: ## load contents of src into mass storage of trezor rm -rf /run/media/${USER}/PYBFLASH/* diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index ff4a86e8cd..a3c5a2bb02 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -28,7 +28,44 @@ void nlr_jump_fail(void *val) { void SystemClock_Config(void); -// ### +// ### from stm32_it.c + +/** + * @brief This function handles SysTick Handler. + * @param None + * @retval None + */ +void SysTick_Handler(void) { + // Instead of calling HAL_IncTick we do the increment here of the counter. + // This is purely for efficiency, since SysTick is called 1000 times per + // second at the highest interrupt priority. + // Note: we don't need uwTick to be declared volatile here because this is + // the only place where it can be modified, and the code is more efficient + // without the volatile specifier. + extern uint32_t uwTick; + uwTick += 1; + + // Read the systick control regster. This has the side effect of clearing + // the COUNTFLAG bit, which makes the logic in sys_tick_get_microseconds + // work properly. + SysTick->CTRL; + +#if 0 + // Right now we have the storage and DMA controllers to process during + // this interrupt and we use custom dispatch handlers. If this needs to + // be generalised in the future then a dispatch table can be used as + // follows: ((void(*)(void))(systick_dispatch[uwTick & 0xf]))(); + + if (STORAGE_IDLE_TICK(uwTick)) { + NVIC->STIR = FLASH_IRQn; + } + + if (DMA_IDLE_ENABLED() && DMA_IDLE_TICK(uwTick)) { + dma_idle_handler(uwTick); + } +#endif +} + // ### from timer.c @@ -65,7 +102,16 @@ int main(void) { display_init(); display_clear(); - display_text(0, 0, "TREZOR", 6, FONT_MONO, 0xFFFF, 0x0000); + display_text(100, 120, "TREZOR", 6, FONT_MONO, 0xFFFF, 0x0000); + display_text(90, 140, "bootloader", 10, FONT_MONO, 0xFFFF, 0x0000); + display_backlight(255); + HAL_Delay(250); + display_backlight(0); + HAL_Delay(250); + display_backlight(100); + HAL_Delay(250); + display_backlight(0); + HAL_Delay(250); display_backlight(255); __fatal_error("end");