f4discovery: Compile time option to compile with ST bootloader
Just to keep things active. Prepare for F72 bootloader.
This commit is contained in:
parent
636bcee355
commit
139e5d7e22
@ -1,4 +1,5 @@
|
|||||||
CROSS_COMPILE ?= arm-none-eabi-
|
CROSS_COMPILE ?= arm-none-eabi-
|
||||||
|
BMP_BOOTLOADER ?=
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC = $(CROSS_COMPILE)gcc
|
||||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||||
|
|
||||||
@ -7,12 +8,20 @@ CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \
|
|||||||
-DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \
|
-DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \
|
||||||
-Iplatforms/stm32
|
-Iplatforms/stm32
|
||||||
|
|
||||||
LDFLAGS = -lopencm3_stm32f4 \
|
LDFLAGS_BOOT = -lopencm3_stm32f4 \
|
||||||
-Wl,-T,platforms/stm32/f4discovery.ld -nostartfiles -lc -lnosys \
|
-Wl,-T,platforms/stm32/f4discovery.ld -nostartfiles -lc -lnosys \
|
||||||
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m4 -Wl,-gc-sections \
|
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m4 -Wl,-gc-sections \
|
||||||
-mfloat-abi=hard -mfpu=fpv4-sp-d16 \
|
-mfloat-abi=hard -mfpu=fpv4-sp-d16 \
|
||||||
-L../libopencm3/lib
|
-L../libopencm3/lib
|
||||||
|
|
||||||
|
ifeq ($(BMP_BOOTLOADER), 1)
|
||||||
|
$(info Load address 0x08004000 for BMPBootloader)
|
||||||
|
LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000
|
||||||
|
CFLAGS += -DUSE_BMP_SERIAL
|
||||||
|
else
|
||||||
|
LDFLAGS = $(LDFLAGS_BOOT)
|
||||||
|
endif
|
||||||
|
|
||||||
VPATH += platforms/stm32
|
VPATH += platforms/stm32
|
||||||
|
|
||||||
SRC += cdcacm.c \
|
SRC += cdcacm.c \
|
||||||
@ -23,7 +32,18 @@ SRC += cdcacm.c \
|
|||||||
timing.c \
|
timing.c \
|
||||||
timing_stm32.c \
|
timing_stm32.c \
|
||||||
|
|
||||||
|
ifneq ($(BMP_BOOTLOADER), 1)
|
||||||
all: blackmagic.bin
|
all: blackmagic.bin
|
||||||
|
else
|
||||||
|
all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex
|
||||||
|
blackmagic_dfu: usbdfu.o dfucore.o dfu_f4.o
|
||||||
|
$(CC) $^ -o $@ $(LDFLAGS_BOOT)
|
||||||
|
|
||||||
|
blackmagic_dfu.bin: blackmagic_dfu
|
||||||
|
$(OBJCOPY) -O binary $^ $@
|
||||||
|
|
||||||
|
blackmagic_dfu.hex: blackmagic_dfu
|
||||||
|
$(OBJCOPY) -O ihex $^ $@
|
||||||
|
endif
|
||||||
host_clean:
|
host_clean:
|
||||||
-$(Q)$(RM) blackmagic.bin
|
-$(Q)$(RM) blackmagic.bin
|
||||||
|
@ -71,8 +71,8 @@ void platform_init(void)
|
|||||||
rcc_periph_clock_enable(RCC_CRC);
|
rcc_periph_clock_enable(RCC_CRC);
|
||||||
|
|
||||||
/* Set up USB Pins and alternate function*/
|
/* Set up USB Pins and alternate function*/
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
|
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO11 | GPIO12);
|
||||||
gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12);
|
gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO10 | GPIO11 | GPIO12);
|
||||||
|
|
||||||
GPIOC_OSPEEDR &=~0xF30;
|
GPIOC_OSPEEDR &=~0xF30;
|
||||||
GPIOC_OSPEEDR |= 0xA20;
|
GPIOC_OSPEEDR |= 0xA20;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#define PLATFORM_HAS_TRACESWO
|
#define PLATFORM_HAS_TRACESWO
|
||||||
#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")"
|
#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")"
|
||||||
|
#define BOARD_IDENT_DFU "Black Magic Firmware Upgrade (F4Discovery)"
|
||||||
#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery)"
|
#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery)"
|
||||||
|
|
||||||
/* Important pin mappings for STM32 implementation:
|
/* Important pin mappings for STM32 implementation:
|
||||||
|
73
src/platforms/f4discovery/usbdfu.c
Normal file
73
src/platforms/f4discovery/usbdfu.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Black Magic Debug project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||||
|
*
|
||||||
|
* 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, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <libopencm3/cm3/systick.h>
|
||||||
|
#include <libopencm3/stm32/rcc.h>
|
||||||
|
#include <libopencm3/stm32/gpio.h>
|
||||||
|
#include <libopencm3/cm3/scb.h>
|
||||||
|
|
||||||
|
#include "usbdfu.h"
|
||||||
|
#include "general.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
uint32_t app_address = 0x08004000;
|
||||||
|
extern char _ebss[];
|
||||||
|
|
||||||
|
void dfu_detach(void)
|
||||||
|
{
|
||||||
|
scb_reset_system();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
volatile uint32_t *magic = (uint32_t *)_ebss;
|
||||||
|
rcc_periph_clock_enable(RCC_GPIOA);
|
||||||
|
if (gpio_get(GPIOA, GPIO0) ||
|
||||||
|
((magic[0] == BOOTMAGIC0) && (magic[1] == BOOTMAGIC1))) {
|
||||||
|
magic[0] = 0;
|
||||||
|
magic[1] = 0;
|
||||||
|
} else {
|
||||||
|
dfu_jump_app_if_valid();
|
||||||
|
}
|
||||||
|
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
|
||||||
|
|
||||||
|
/* Assert blue LED as indicator we are in the bootloader */
|
||||||
|
rcc_periph_clock_enable(RCC_GPIOD);
|
||||||
|
gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT,
|
||||||
|
GPIO_PUPD_NONE, LED_BOOTLOADER);
|
||||||
|
gpio_set(LED_PORT, LED_BOOTLOADER);
|
||||||
|
|
||||||
|
/* Enable peripherals */
|
||||||
|
rcc_periph_clock_enable(RCC_OTGFS);
|
||||||
|
|
||||||
|
/* Set up USB Pins and alternate function*/
|
||||||
|
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
|
||||||
|
gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12);
|
||||||
|
|
||||||
|
dfu_protect(false);
|
||||||
|
dfu_init(&USB_DRIVER);
|
||||||
|
dfu_main();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dfu_event(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -53,15 +53,14 @@ static void get_sector_num(uint32_t addr)
|
|||||||
void dfu_check_and_do_sector_erase(uint32_t addr)
|
void dfu_check_and_do_sector_erase(uint32_t addr)
|
||||||
{
|
{
|
||||||
if(addr == sector_addr[sector_num]) {
|
if(addr == sector_addr[sector_num]) {
|
||||||
flash_erase_sector((sector_num & 0x1f)<<3, FLASH_PROGRAM_X32);
|
flash_erase_sector((sector_num & 0x1f)<<3, FLASH_CR_PROGRAM_X32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len)
|
void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < len; i += 4)
|
for(int i = 0; i < len; i += 4)
|
||||||
flash_program_word(baseaddr + i, *(uint32_t*)(buf+i),
|
flash_program_word(baseaddr + i, *(uint32_t*)(buf+i));
|
||||||
FLASH_PROGRAM_X32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum)
|
uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum)
|
||||||
@ -78,14 +77,16 @@ uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum)
|
|||||||
return 26;
|
return 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dfu_protect_enable(void)
|
void dfu_protect(bool enable)
|
||||||
{
|
{
|
||||||
|
if (enable) {
|
||||||
#ifdef DFU_SELF_PROTECT
|
#ifdef DFU_SELF_PROTECT
|
||||||
if ((FLASH_OPTCR & 0x10000) != 0) {
|
if ((FLASH_OPTCR & 0x10000) != 0) {
|
||||||
flash_program_option_bytes(FLASH_OPTCR & ~0x10000);
|
flash_program_option_bytes(FLASH_OPTCR & ~0x10000);
|
||||||
flash_lock_option_bytes();
|
flash_lock_option_bytes();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dfu_jump_app_if_valid(void)
|
void dfu_jump_app_if_valid(void)
|
||||||
@ -93,14 +94,17 @@ void dfu_jump_app_if_valid(void)
|
|||||||
/* Boot the application if it's valid */
|
/* Boot the application if it's valid */
|
||||||
/* Vector table may be anywhere in 128 kByte RAM
|
/* Vector table may be anywhere in 128 kByte RAM
|
||||||
CCM not handled*/
|
CCM not handled*/
|
||||||
if((*(volatile uint32_t*)APP_ADDRESS & 0x2FFC0000) == 0x20000000) {
|
if((*(volatile uint32_t*)app_address & 0x2FFC0000) == 0x20000000) {
|
||||||
/* Set vector table base address */
|
#if defined(STM32F7) /* Set vector table base address */
|
||||||
SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/
|
SCB_VTOR = app_address & 0xFFFFFF00;
|
||||||
|
#else
|
||||||
|
SCB_VTOR = app_address & 0x1FFFFF; /* Max 2 MByte Flash*/
|
||||||
|
#endif
|
||||||
/* Initialise master stack pointer */
|
/* Initialise master stack pointer */
|
||||||
asm volatile ("msr msp, %0"::"g"
|
asm volatile ("msr msp, %0"::"g"
|
||||||
(*(volatile uint32_t*)APP_ADDRESS));
|
(*(volatile uint32_t*)app_address));
|
||||||
/* Jump to application */
|
/* Jump to application */
|
||||||
(*(void(**)())(APP_ADDRESS + 4))();
|
(*(void(**)())(app_address + 4))();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,11 @@
|
|||||||
# define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,000*001Kg"
|
# define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,000*001Kg"
|
||||||
# define DFU_IFACE_STRING_OFFSET 38
|
# define DFU_IFACE_STRING_OFFSET 38
|
||||||
# define DFU_IFACE_PAGESIZE 1
|
# define DFU_IFACE_PAGESIZE 1
|
||||||
#elif defined(STM32F4)
|
#elif defined(STM32F4) || defined(STM32F7)
|
||||||
# define DFU_IFACE_STRING "/0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg"
|
# define FLASH_BASE 0x08000000U
|
||||||
#elif defined(STM32F7)
|
# define DFU_IFACE_PAGESIZE 128
|
||||||
# define DFU_IFACE_STRING "/0x08000000/1*016Ka,3*016Kg,1*064Kg,3*128Kg"
|
# define DFU_IFACE_STRING_OFFSET 54
|
||||||
|
# define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,000*128Kg"
|
||||||
#endif
|
#endif
|
||||||
#include <libopencm3/stm32/flash.h>
|
#include <libopencm3/stm32/flash.h>
|
||||||
|
|
||||||
@ -329,7 +330,7 @@ static void set_dfu_iface_string(uint32_t size)
|
|||||||
*p++ = size + '0';
|
*p++ = size + '0';
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define set_dfu_iface_string()
|
# define set_dfu_iface_string(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *get_dev_unique_id(char *s)
|
static char *get_dev_unique_id(char *s)
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
char *serial_no_read(char *s, int max)
|
char *serial_no_read(char *s, int max)
|
||||||
{
|
{
|
||||||
#if defined(STM32F1)
|
#if defined(STM32F1) || defined(USE_BMP_SERIAL)
|
||||||
/* Only STM32F103 has no DFU Bootloader. Generate a ID comatible
|
/* Only STM32F103 has no DFU Bootloader. Generate a ID comatible
|
||||||
* with the BMP Bootloader since ages.
|
* with the BMP Bootloader since ages.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user