diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index 0636a40b..127a2c56 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -390,7 +390,11 @@ static const struct usb_config_descriptor config = { .interface = ifaces, }; +#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4) +char serial_no[13]; +#else char serial_no[9]; +#endif static const char *usb_strings[] = { "Black Sphere Technologies", diff --git a/src/platforms/f4discovery/Makefile.inc b/src/platforms/f4discovery/Makefile.inc index a1ec121b..b04cf415 100644 --- a/src/platforms/f4discovery/Makefile.inc +++ b/src/platforms/f4discovery/Makefile.inc @@ -7,7 +7,7 @@ CFLAGS += -Istm32/include -mcpu=cortex-m4 -mthumb \ -DSTM32F4 -DF4DISCOVERY -I../libopencm3/include \ -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,-Map=mapfile -mthumb -mcpu=cortex-m4 -Wl,-gc-sections \ -mfloat-abi=hard -mfpu=fpv4-sp-d16 \ diff --git a/src/platforms/f4discovery/Readme b/src/platforms/f4discovery/Readme index 9bc15578..bbcfc4fb 100644 --- a/src/platforms/f4discovery/Readme +++ b/src/platforms/f4discovery/Readme @@ -1,6 +1,6 @@ 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. Connections: @@ -17,7 +17,7 @@ PC6: TDO/TRACESWO PC1: TRST 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 ============================================== diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index 5d245034..bc781e24 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -34,25 +34,41 @@ #include #include #include +#include +#include jmp_buf fatal_error_jmpbuf; +extern uint32_t _ebss; void platform_init(void) { + volatile uint32_t *magic = (uint32_t *) &_ebss; /* Check the USER button*/ - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); - if(gpio_get(GPIOA, GPIO0)) { - platform_request_boot(); + rcc_periph_clock_enable(RCC_GPIOA); + if (gpio_get(GPIOA, GPIO0) || + ((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(); } rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_48MHZ]); /* Enable peripherals */ - rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_CRCEN); + rcc_periph_clock_enable(RCC_OTGFS); + rcc_periph_clock_enable(RCC_GPIOC); + rcc_periph_clock_enable(RCC_GPIOD); + rcc_periph_clock_enable(RCC_CRC); /* Set up USB Pins and alternate function*/ 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) { - /* Disconnect USB cable */ - usbd_disconnect(usbdev, 1); - nvic_disable_irq(USB_IRQ); - - /* 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; + uint32_t *magic = (uint32_t *) &_ebss; + magic[0] = BOOTMAGIC0; + magic[1] = BOOTMAGIC1; + scb_reset_system(); } diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index e274a38b..971ebc28 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -32,8 +32,8 @@ #include #define PLATFORM_HAS_TRACESWO -#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")" -#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" +#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware " FIRMWARE_VERSION ")" +#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery)" /* Important pin mappings for STM32 implementation: * @@ -42,7 +42,6 @@ * LED2 = PD12 (Red LED : Error) * LED3 = PD15 (Blue LED : Bootloader active) * - * TPWR = XXX (input) -- analogue on mini design ADC1, ch8 * nTRST = PC1 * SRST_OUT = PC8 * TDI = PC2 @@ -51,10 +50,7 @@ * TDO = PC6 (input for TRACESWO * nSRST = * - * USB cable pull-up: PA8 - * USB VBUS detect: PB13 -- New on mini design. - * Enable pull up for compatibility. - * Force DFU mode button: PB12 + * Force DFU mode button: PA0 */ /* Hardware definitions... */ @@ -84,6 +80,8 @@ #define LED_IDLE_RUN GPIO13 #define LED_ERROR GPIO14 #define LED_BOOTLOADER GPIO15 +#define BOOTMAGIC0 0xb007da7a +#define BOOTMAGIC1 0xbaadfeed #define TMS_SET_MODE() \ gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \ diff --git a/src/platforms/f4discovery/usbdfu.c b/src/platforms/f4discovery/usbdfu.c deleted file mode 100644 index 101824f8..00000000 --- a/src/platforms/f4discovery/usbdfu.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2013 Gareth McMullin - * - * 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 . - */ - -#include "general.h" -#include "usbdfu.h" - -#include -#include -#include -#include - -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 */ -} - diff --git a/src/platforms/stm32/serialno.c b/src/platforms/stm32/serialno.c index ef28ed2d..ae02f8a5 100644 --- a/src/platforms/stm32/serialno.c +++ b/src/platforms/stm32/serialno.c @@ -21,11 +21,17 @@ char *serialno_read(char *s) { -#if defined(STM32F4) - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; +#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4) + 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 volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; -#endif uint32_t unique_id = *unique_id_p + *(unique_id_p + 1) + *(unique_id_p + 2); @@ -40,6 +46,7 @@ char *serialno_read(char *s) s[i] += 'A' - '9' - 1; s[8] = 0; +#endif return s; }