f4_discovery: Clean up platform.h and Readme.
This commit is contained in:
parent
814eb0e3a2
commit
a0e47c392b
|
@ -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
|
||||||
==============================================
|
==============================================
|
||||||
|
|
|
@ -42,7 +42,7 @@ jmp_buf fatal_error_jmpbuf;
|
||||||
void platform_init(void)
|
void platform_init(void)
|
||||||
{
|
{
|
||||||
/* 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();
|
platform_request_boot();
|
||||||
scb_reset_core();
|
scb_reset_core();
|
||||||
|
@ -51,10 +51,10 @@ void platform_init(void)
|
||||||
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);
|
||||||
|
@ -93,17 +93,16 @@ void platform_request_boot(void)
|
||||||
if (RCC_AHB2ENR & RCC_AHB2ENR_OTGFSEN) {
|
if (RCC_AHB2ENR & RCC_AHB2ENR_OTGFSEN) {
|
||||||
usbd_disconnect(usbdev, 1);
|
usbd_disconnect(usbdev, 1);
|
||||||
nvic_disable_irq(USB_IRQ);
|
nvic_disable_irq(USB_IRQ);
|
||||||
rcc_peripheral_disable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
|
rcc_periph_clock_disable(RCC_OTGFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assert blue LED as indicator we are in the bootloader */
|
/* 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_mode_setup(LED_PORT, GPIO_MODE_OUTPUT,
|
||||||
GPIO_PUPD_NONE, LED_BOOTLOADER);
|
GPIO_PUPD_NONE, LED_BOOTLOADER);
|
||||||
gpio_set(LED_PORT, LED_BOOTLOADER);
|
gpio_set(LED_PORT, LED_BOOTLOADER);
|
||||||
/* Disable used ports beside PORTD.*/
|
/* Disable used ports beside PORTD.*/
|
||||||
rcc_peripheral_disable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
|
rcc_periph_clock_disable(RCC_GPIOA);
|
||||||
rcc_peripheral_disable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN);
|
rcc_periph_clock_disable(RCC_GPIOC);
|
||||||
rcc_periph_clock_disable(USBUSART_CLK);
|
rcc_periph_clock_disable(USBUSART_CLK);
|
||||||
/* Reset Systick.*/
|
/* Reset Systick.*/
|
||||||
systick_interrupt_disable();
|
systick_interrupt_disable();
|
||||||
|
@ -119,7 +118,7 @@ void platform_request_boot(void)
|
||||||
RCC_CFGR &= ~(RCC_CFGR_SWS_HSE | RCC_CFGR_SWS_PLL);
|
RCC_CFGR &= ~(RCC_CFGR_SWS_HSE | RCC_CFGR_SWS_PLL);
|
||||||
|
|
||||||
/* Map System flash at 0.*/
|
/* Map System flash at 0.*/
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_SYSCFGEN);
|
rcc_periph_clock_enable(RCC_SYSCFG);
|
||||||
SYSCFG_MEMRM &= ~3;
|
SYSCFG_MEMRM &= ~3;
|
||||||
SYSCFG_MEMRM |= 1;
|
SYSCFG_MEMRM |= 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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... */
|
||||||
|
|
|
@ -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 */
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue