Skip to content
Snippets Groups Projects
Commit 5476234c authored by C-Glick's avatar C-Glick
Browse files

Cleaned up dfu bootloader files

parent 44ac35a7
No related branches found
No related tags found
1 merge request!69Streamlined USB flashing
......@@ -48,8 +48,6 @@
#include "crtp.h"
#include "static_mem.h"
#include "debug.h"
#include "bootloader.h"
......@@ -183,15 +181,9 @@ static uint8_t usbd_cf_Setup(void *pdev , USB_SETUP_REQ *req)
}
} else if(command == 0x02){
//restart system and transition to DFU bootloader mode
//enter bootloader specific to STM32f4xx
enter_bootloader(0, 0x00000000);
}
else {
} else {
crtpSetLink(radiolinkGetLink());
}
return USBD_OK;
......
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie Firmware
*
* Copyright (C) Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @file bootloader.h
* Functions to handle transitioning from the firmware to bootloader (DFU) mode on startup
*
*/
/* FreeRtos includes */
#include "FreeRTOS.h"
/* ST includes */
#include "stm32f4xx.h"
void branch_to_bootloader(uint32_t r0, uint32_t bl_addr);
/**
* @brief Check if memory is set after software
* reboot indicating we need to branch to the bootloader.
* Run everytime on startup.
*/
void check_enter_bootloader();
/**
* @brief Initiate the procedure to reboot into the bootloader.
*
* This function does not return, instead setting a flag to
* jump to the bootloader on the next start and
* issuing a software reset.
*
* @param r0 The register to utilize when jumping
* @param bl_addr The bootloader address to jump to
*/
void enter_bootloader(uint32_t r0, uint32_t bl_addr);
\ No newline at end of file
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie Firmware
*
* Copyright (C) Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @file bootloader.c
* Functions to handle transitioning from the firmware to bootloader (DFU) mode on startup
*
*/
#include "bootloader.h"
//bootloader code used from micropython machine_bootloader
// bootloader code based from micropython machine_bootloader function
// STM32H7 has ECC and writes to RAM must be 64-bit so they are fully committed
// to actual SRAM before a system reset occurs.
......@@ -15,7 +43,15 @@
#define BL_STATE_GET_ADDR(s) (((s) >> BL_STATE_KEY_SHIFT) & ~BL_STATE_KEY_MASK)
void branch_to_bootloader(uint32_t r0, uint32_t bl_addr){
/**
* @brief Branch directly to the bootloader address, setting the
* stack pointer and destination address first.
* Based from the micropython machine_bootloader function.
*
* @param r0 The register to utilize
* @param bl_addr The bootloader address to jump to
*/
static void branch_to_bootloader(uint32_t r0, uint32_t bl_addr){
__asm volatile (
"ldr r2, [r1, #0]\n" // get address of stack pointer
"msr msp, r2\n" // get stack pointer
......@@ -26,15 +62,13 @@ void branch_to_bootloader(uint32_t r0, uint32_t bl_addr){
while(1);
}
//check if memory is set after software reboot indicating we need to branch to the bootloader
void check_enter_bootloader(){
uint64_t bl_state = *BL_STATE_PTR;
//set to invalid for next boot
*BL_STATE_PTR = BL_STATE_INVALID;
//TODO test if statement
if(BL_STATE_GET_KEY(bl_state) == BL_STATE_KEY && (RCC->CSR & RCC_CSR_SFTRSTF)){
//botloader data valid and was just reset with NVIC_SystemReset
//if botloader data valid and was just reset with NVIC_SystemReset
//remap memory to system flash
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SystemFlash);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment