From 8773085d7f9776920657f742267c332d4b26e58e Mon Sep 17 00:00:00 2001 From: Sid Price Date: Sun, 14 Jul 2024 10:50:34 -0600 Subject: [PATCH] ctxlink: Optimize the calling of the bootloader and update readme with correct DFU options --- src/platforms/ctxlink/README.md | 4 +-- src/platforms/ctxlink/platform.c | 42 +++----------------------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/src/platforms/ctxlink/README.md b/src/platforms/ctxlink/README.md index 25f1cdd298c..ddc25de762f 100644 --- a/src/platforms/ctxlink/README.md +++ b/src/platforms/ctxlink/README.md @@ -23,9 +23,7 @@ After build: 1) `apt install dfu-util` 2) Force ctxLink into system bootloader mode by holding down the Mode switch while pressing reset. Release reset followed by Mode. System bootloader should appear. -3) `dfu-util -a 0 --dfuse-address 0x08000000 -D blackmagic_ctxlink_firmware.bin` - -To exit from DFU mode press and release Reset on ctxLink. +3) `dfu-util -a 0 --dfuse-address 0x08000000:leave -D blackmagic_ctxlink_firmware.bin` ## 10 pin male from pins diff --git a/src/platforms/ctxlink/platform.c b/src/platforms/ctxlink/platform.c index 6f704034af7..32fc71057b1 100644 --- a/src/platforms/ctxlink/platform.c +++ b/src/platforms/ctxlink/platform.c @@ -221,44 +221,10 @@ const char *platform_target_voltage(void) void platform_request_boot(void) { - const uint32_t application_address = 0x1fff0000; - register uint32_t jump_address = 0; - register uint32_t addr = 0; - register irq_function_t jump_to_application; - - /* We start here */ - cm_disable_interrupts(); - uint32_t value = UINT32_MAX; - NVIC_ICER(0) = value; - NVIC_ICER(1) = value; - NVIC_ICER(2) = value; - NVIC_ICPR(0) = value; - NVIC_ICPR(1) = value; - NVIC_ICPR(2) = value; - - STK_CSR = 0; - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Reset value of 0x83 includes Set HSION bit */ - RCC_CR |= (uint32_t)0x00000082; - /* Reset CFGR register */ - RCC_CFGR = 0x00000000; - - /* Disable all interrupts */ - RCC_CIR = 0x00000000; - - FLASH_ACR = 0; - __asm__ volatile("isb"); - __asm__ volatile("dsb"); - cm_enable_interrupts(); - addr = *((uint32_t *)application_address); - jump_address = *((uint32_t *)(application_address + 4)); - jump_to_application = (irq_function_t)jump_address; - /* - set up the stack for the bootloader - */ - __asm__("mov sp,%[v]" : : [v] "r"(addr)); - - jump_to_application(); + /* Switch mapping at 0x0 from internal Flash to MaskROM and reboot CM4 into it */ + rcc_periph_clock_enable(RCC_SYSCFG); + SYSCFG_MEMRM = (SYSCFG_MEMRM & ~3U) | 1U; + scb_reset_core(); } #pragma GCC diagnostic pop