Permalink
Browse files

Bootloader: Implemented jump to system memory

  • Loading branch information...
matthiasbock committed Mar 19, 2018
1 parent 696e331 commit 59b2813fcc6d78db6323947f1cb96c9d86f24de0
Showing with 63 additions and 3 deletions.
  1. +6 −0 Inc/bootloader.h
  2. +2 −2 Inc/config.h
  3. +1 −0 Inc/slcan.h
  4. +50 −0 Src/bootloader.c
  5. +4 −1 Src/slcan.c
@@ -0,0 +1,6 @@
#ifndef BOOTLOADER_H
void jump_to_st_usb_bootloader();
#endif
@@ -25,8 +25,8 @@
#endif
#ifdef PLATFORM_CANTACT
#define CAN_RX_BUFFER_SIZE 350
#define CAN_TX_BUFFER_SIZE 350
#define CAN_RX_BUFFER_SIZE 340
#define CAN_TX_BUFFER_SIZE 340
#endif
#define CAN_TX_TIMEOUT 20
@@ -77,6 +77,7 @@ enum slcan_message_type {
CANTACT_SET_MODE2 = 'M',
CANTACT_SET_FILTER = 'F',
CANTACT_SET_MASK = 'K',
CANTACT_START_BOOTLOADER = 'B',
USBTIN_OPEN_LOOPBACK = 'I',
USBTIN_OPEN_LISTEN_ONLY = 'L',
@@ -0,0 +1,50 @@
#include <bootloader.h>
#include <platform.h>
#include <config.h>
#include <led.h>
void jump_to_st_usb_bootloader()
{
// Disable interrupts
__disable_irq();
// Disable RCC and reset it to default values
RCC->CFGR = 0;
RCC->CR = 0x83;
//Disable systick timer and reset it to default values
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Disable USB
USB->CNTR = USB_CNTR_PDWN;
// Disable CAN
CAN->MCR = CAN_MCR_SLEEP;
// Disable LEDs
// TODO: Surprisingly, this doesn't switch off the LED.
// HAL_GPIO_WritePin(LED_ACTIVITY_PORT, LED_ACTIVITY_PIN, GPIO_PIN_RESET);
// Enable interrupts
// __enable_irq();
__DSB();
// Re-map system memory to address 0x0
SYSCFG->CFGR1 = (SYSCFG->CFGR1 & ~SYSCFG_CFGR1_MEM_MODE) | SYSCFG_CFGR1_MEM_MODE_0;
// Fetch and apply bootloader's stack pointer
__set_MSP(*(uint32_t*)(0x00));
__DSB();
__ISB();
// Invoke bootloader's reset handler
void (*SysMemBootJump)(void);
SysMemBootJump = (void (*)(void)) (*((uint32_t*)(4)));
SysMemBootJump();
}
@@ -7,7 +7,8 @@
#include "can.h"
#include "fifo.h"
#include "slcan.h"
#include <error.h>
#include "error.h"
#include "bootloader.h"
int8_t slcan_parse_frame(CanRxMsgTypeDef* frame, uint8_t* buf) {
@@ -184,6 +185,8 @@ int8_t slcan_parse_command(uint8_t* buf, uint8_t len) {
return SUCCESS;
// error
return ERROR_TX_FIFO_OVERRUN;
} else if (buf[0] == CANTACT_START_BOOTLOADER) {
jump_to_st_usb_bootloader();
}
return ERROR_SLCAN_COMMAND_NOT_RECOGNIZED;

0 comments on commit 59b2813

Please sign in to comment.