aboutsummaryrefslogtreecommitdiff
path: root/projects/bootloader/bootloader.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2016-06-07 11:59:43 -0400
committerPaul Selkirk <paul@psgd.org>2016-06-07 11:59:43 -0400
commit2dd70b171bde90620a631b6ba8d129acc911f93e (patch)
tree11c0c83e21c34dea4f9d6914908d03dce8835add /projects/bootloader/bootloader.c
parentea4eda95284cd3d34b9956bf1e27046a0d8c3cf6 (diff)
Check the HARDWARE_EARLY_DFU_JUMP flag as soon as possible in the boot process.
This avoids the situation where the bootloader systick happens during firmware initialization, and freaks out. Also build the bootloader with the minimum resources needed (no RTOS, no SPI, no I2C).
Diffstat (limited to 'projects/bootloader/bootloader.c')
-rw-r--r--projects/bootloader/bootloader.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/projects/bootloader/bootloader.c b/projects/bootloader/bootloader.c
index ab3c1d9..30cd120 100644
--- a/projects/bootloader/bootloader.c
+++ b/projects/bootloader/bootloader.c
@@ -37,6 +37,8 @@
#include "stm-uart.h"
#include "dfu.h"
+#undef HAL_Delay
+
/* Linker symbols are strange in C. Make regular pointers for sanity. */
__IO uint32_t *dfu_control = &CRYPTECH_DFU_CONTROL;
__IO uint32_t *dfu_firmware = &CRYPTECH_FIRMWARE_START;
@@ -49,16 +51,20 @@ __IO uint32_t *dfu_code_ptr = &CRYPTECH_FIRMWARE_START + 1;
typedef void (*pFunction)(void);
-/* This is it's own function to make it more convenient to set a breakpoint at it in gdb */
-void do_early_dfu_jump(void)
+/* called from Reset_Handler */
+void check_early_dfu_jump(void)
{
- pFunction loaded_app = (pFunction) *dfu_code_ptr;
- /* Set the stack pointer to the correct one for the firmware */
- __set_MSP(*dfu_msp_ptr);
- /* Set the Vector Table Offset Register */
- SCB->VTOR = (uint32_t) dfu_firmware;
- loaded_app();
- while (1);
+ /* Check if we've just rebooted in order to jump to the firmware. */
+ if (*dfu_control == HARDWARE_EARLY_DFU_JUMP) {
+ *dfu_control = 0;
+ pFunction loaded_app = (pFunction) *dfu_code_ptr;
+ /* Set the stack pointer to the correct one for the firmware */
+ __set_MSP(*dfu_msp_ptr);
+ /* Set the Vector Table Offset Register */
+ SCB->VTOR = (uint32_t) dfu_firmware;
+ loaded_app();
+ while (1);
+ }
}
int should_dfu()
@@ -86,12 +92,6 @@ main()
{
int status;
- /* Check if we've just rebooted in order to jump to the firmware. */
- if (*dfu_control == HARDWARE_EARLY_DFU_JUMP) {
- *dfu_control = 0;
- do_early_dfu_jump();
- }
-
stm_init();
uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nThis is the bootloader speaking...");