Merge pull request #210 from UweBonnes/f4_discovery

F4 discovery
This commit is contained in:
Gareth McMullin 2017-05-12 09:15:55 +12:00 committed by GitHub
commit 261be9864c
7 changed files with 49 additions and 109 deletions

View File

@ -390,7 +390,11 @@ static const struct usb_config_descriptor config = {
.interface = ifaces, .interface = ifaces,
}; };
#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
char serial_no[13];
#else
char serial_no[9]; char serial_no[9];
#endif
static const char *usb_strings[] = { static const char *usb_strings[] = {
"Black Sphere Technologies", "Black Sphere Technologies",

View File

@ -7,7 +7,7 @@ CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \
-DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \ -DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \
-Iplatforms/stm32 -Iplatforms/stm32
LDFLAGS = -lopencm3_stm32f4 -Wl,--defsym,_stack=0x20006000 \ LDFLAGS = -lopencm3_stm32f4 -Wl,--defsym,_stack=0x20010000 \
-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 \

View File

@ -1,6 +1,6 @@
System vs BMP Bootloader System vs BMP Bootloader
======================== ========================
For the BMP bootloader, flashing qas not reliable. So we use the system For the BMP bootloader, flashing was not reliable. So we use the system
bootloder unconditional. bootloder unconditional.
Connections: Connections:
@ -17,7 +17,7 @@ PC6: TDO/TRACESWO
PC1: TRST PC1: TRST
PC8: SRST PC8: SRST
Blue Led: Indicator that system bootloader is entered via BMP PD15/Blue Led: Indicator that system bootloader is entered via BMP
Bootstrapping the F4Discovery on-board ST-Link Bootstrapping the F4Discovery on-board ST-Link
============================================== ==============================================

View File

@ -34,25 +34,41 @@
#include <libopencm3/stm32/usart.h> #include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/syscfg.h> #include <libopencm3/stm32/syscfg.h>
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/cortex.h>
jmp_buf fatal_error_jmpbuf; jmp_buf fatal_error_jmpbuf;
extern uint32_t _ebss;
void platform_init(void) void platform_init(void)
{ {
volatile uint32_t *magic = (uint32_t *) &_ebss;
/* Check the USER button*/ /* Check the USER button*/
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); rcc_periph_clock_enable(RCC_GPIOA);
if(gpio_get(GPIOA, GPIO0)) { if (gpio_get(GPIOA, GPIO0) ||
platform_request_boot(); ((magic[0] == BOOTMAGIC0) && (magic[1] == BOOTMAGIC1))) {
magic[0] = 0;
magic[1] = 0;
/* 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);
/* Jump to the built in bootloader by mapping System flash.
As we just come out of reset, no other deinit is needed!*/
rcc_periph_clock_enable(RCC_SYSCFG);
SYSCFG_MEMRM &= ~3;
SYSCFG_MEMRM |= 1;
scb_reset_core(); scb_reset_core();
} }
rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_48MHZ]); rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_48MHZ]);
/* Enable peripherals */ /* Enable peripherals */
rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN); rcc_periph_clock_enable(RCC_OTGFS);
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); rcc_periph_clock_enable(RCC_GPIOC);
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); rcc_periph_clock_enable(RCC_GPIOD);
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_CRCEN); 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, GPIO11 | GPIO12);
@ -87,18 +103,8 @@ const char *platform_target_voltage(void)
void platform_request_boot(void) void platform_request_boot(void)
{ {
/* Disconnect USB cable */ uint32_t *magic = (uint32_t *) &_ebss;
usbd_disconnect(usbdev, 1); magic[0] = BOOTMAGIC0;
nvic_disable_irq(USB_IRQ); magic[1] = BOOTMAGIC1;
scb_reset_system();
/* Assert blue LED as indicator we are in the bootloader */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE, LED_BOOTLOADER);
gpio_set(LED_PORT, LED_BOOTLOADER);
/* Jump to the built in bootloader by mapping System flash */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_SYSCFGEN);
SYSCFG_MEMRM &= ~3;
SYSCFG_MEMRM |= 1;
} }

View File

@ -32,8 +32,8 @@
#include <setjmp.h> #include <setjmp.h>
#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 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:
* *
@ -42,7 +42,6 @@
* LED2 = PD12 (Red LED : Error) * LED2 = PD12 (Red LED : Error)
* LED3 = PD15 (Blue LED : Bootloader active) * LED3 = PD15 (Blue LED : Bootloader active)
* *
* TPWR = XXX (input) -- analogue on mini design ADC1, ch8
* nTRST = PC1 * nTRST = PC1
* SRST_OUT = PC8 * SRST_OUT = PC8
* TDI = PC2 * TDI = PC2
@ -51,10 +50,7 @@
* TDO = PC6 (input for TRACESWO * TDO = PC6 (input for TRACESWO
* nSRST = * nSRST =
* *
* USB cable pull-up: PA8 * Force DFU mode button: PA0
* USB VBUS detect: PB13 -- New on mini design.
* Enable pull up for compatibility.
* Force DFU mode button: PB12
*/ */
/* Hardware definitions... */ /* Hardware definitions... */
@ -84,6 +80,8 @@
#define LED_IDLE_RUN GPIO13 #define LED_IDLE_RUN GPIO13
#define LED_ERROR GPIO14 #define LED_ERROR GPIO14
#define LED_BOOTLOADER GPIO15 #define LED_BOOTLOADER GPIO15
#define BOOTMAGIC0 0xb007da7a
#define BOOTMAGIC1 0xbaadfeed
#define TMS_SET_MODE() \ #define TMS_SET_MODE() \
gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \ gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \

View File

@ -1,75 +0,0 @@
/*
* 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 "general.h"
#include "usbdfu.h"
#include <libopencm3/cm3/systick.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/cm3/scb.h>
void dfu_detach(void)
{
/* USB device must detach, we just reset... */
scb_reset_system();
}
int main(void)
{
/* Check the force bootloader pin*/
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
if(!gpio_get(GPIOA, GPIO0))
dfu_jump_app_if_valid();
dfu_protect_enable();
/* Set up clock*/
rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
systick_set_reload(2100000);
systick_interrupt_enable();
systick_counter_enable();
/* Handle LEDs */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
gpio_clear(GPIOD, GPIO12 | GPIO13 | GPIO14 |GPIO15);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
GPIO12 | GPIO13 | GPIO14 |GPIO15);
/* Set up USB*/
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
/* Set up USB Pins and alternate function*/
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
GPIO10 | GPIO11 | GPIO12);
gpio_set_af(GPIOA, GPIO_AF10, GPIO10 | GPIO11 | GPIO12);
dfu_init(&stm32f107_usb_driver);
dfu_main();
}
void sys_tick_handler(void)
{
gpio_toggle(GPIOD, GPIO12); /* Green LED on/off */
}

View File

@ -21,11 +21,17 @@
char *serialno_read(char *s) char *serialno_read(char *s)
{ {
#if defined(STM32F4) #if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; volatile uint16_t *uid = (volatile uint16_t *)DESIG_UNIQUE_ID_BASE;
# if defined(STM32F4)
int offset = 3;
# elif defined(STM32L0) || defined(STM32F4)
int offset = 5;
#endif
sprintf(s, "%04X%04X%04X",
uid[1] + uid[5], uid[0] + uid[4], uid[offset]);
#else #else
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8;
#endif
uint32_t unique_id = *unique_id_p + uint32_t unique_id = *unique_id_p +
*(unique_id_p + 1) + *(unique_id_p + 1) +
*(unique_id_p + 2); *(unique_id_p + 2);
@ -40,6 +46,7 @@ char *serialno_read(char *s)
s[i] += 'A' - '9' - 1; s[i] += 'A' - '9' - 1;
s[8] = 0; s[8] = 0;
#endif
return s; return s;
} }