From 97a9d8e1de6b462d628723ea1f0f1ba806b33b37 Mon Sep 17 00:00:00 2001
From: C-Glick <colton.glick@gmail.com>
Date: Sun, 6 Feb 2022 19:51:16 -0600
Subject: [PATCH] Remap memory before jumping

Still not working
---
 .vscode/settings.json                            |  3 ++-
 .../crazyflie-firmware-2021.06/src/hal/src/usb.c | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0e356f0bb..659a6316b 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,7 @@
 {
     "files.associations": {
         "controller.h": "c",
-        "typeinfo": "c"
+        "typeinfo": "c",
+        "attitude_controller.h": "c"
     }
 }
\ No newline at end of file
diff --git a/crazyflie_software/crazyflie-firmware-2021.06/src/hal/src/usb.c b/crazyflie_software/crazyflie-firmware-2021.06/src/hal/src/usb.c
index 20fb6886e..8de5d6748 100644
--- a/crazyflie_software/crazyflie-firmware-2021.06/src/hal/src/usb.c
+++ b/crazyflie_software/crazyflie-firmware-2021.06/src/hal/src/usb.c
@@ -182,13 +182,23 @@ static uint8_t usbd_cf_Setup(void *pdev , USB_SETUP_REQ  *req)
   } else if(command == 0x02){
     //transition to DFU bootloader mode
 
-    // arm-none-eabi-gcc 4.9.0 does not correctly inline this
-    //     //     // MSP function, so we write it out explicitly here.
+    //shutdown any tasks running
+    RCC_DeInit();
+    SysTick->CTRL = 0;  //reset the Systick timer
+    SysTick->LOAD = 0;
+    SysTick->VAL  = 0;
+
+    __set_PRIMASK(1);   //disable interrupts
+
+    SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SystemFlash);
+
+    //set main stack pointer to its default value
     __set_MSP(*((uint32_t*) 0x00000000));
-    //__ASM volatile ("movs r3, #0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");
 
+    //jump to boot loader (start of system memory plus 4)
     ((void (*)(void)) *((uint32_t*) 0x00000004))();
 
+    while(1);
 
   }
   
-- 
GitLab