From 2f96878427efede782c179ae2e0f3a5d5d348252 Mon Sep 17 00:00:00 2001 From: bm16ton Date: Sun, 31 Jul 2022 01:42:30 -0400 Subject: [PATCH] blackboard dfu stuff --- src/platforms/blackpillv2/platform.c | 15 +++++++++++---- src/platforms/common/cdcacm.c | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/platforms/blackpillv2/platform.c b/src/platforms/blackpillv2/platform.c index 207ad932e3f..04001275be4 100644 --- a/src/platforms/blackpillv2/platform.c +++ b/src/platforms/blackpillv2/platform.c @@ -49,9 +49,11 @@ void platform_init(void) rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_GPIOB); - + gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, + GPIO_PUPD_PULLUP, GPIO0); /* Check the USER button*/ - if (gpio_get(GPIOA, GPIO0) || + /*blackpillv2 userkey is active low but wo the pullup acts crazy and seemed..sorta active high*/ + if (!gpio_get(GPIOA, GPIO0) || ((magic[0] == BOOTMAGIC0) && (magic[1] == BOOTMAGIC1))) { magic[0] = 0; @@ -74,8 +76,9 @@ void platform_init(void) rcc_periph_clock_enable(RCC_CRC); /* Set up USB Pins and alternate function*/ - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO11 | GPIO12); - gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO10 | GPIO11 | GPIO12); + /*not using PA9 for vbus on blackpillv2 so leavem alone */ + gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12); + gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12); GPIOA_OSPEEDR &= 0x3C00000C; GPIOA_OSPEEDR |= 0x28000008; @@ -105,6 +108,8 @@ void platform_init(void) GPIO_PUPD_NONE, PWR_BR_PIN); #endif + /* for dfu-util to boot directly into the newly flashed app*/ + SCB_VTOR = (uint32_t) 0x08000000; platform_timing_init(); usbuart_init(); @@ -128,6 +133,8 @@ void platform_request_boot(void) uint32_t *magic = (uint32_t *)&_ebss; magic[0] = BOOTMAGIC0; magic[1] = BOOTMAGIC1; + /* Reset core to enter bootloader */ + scb_reset_system(); } diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index fe90c495885..9e8f4603670 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -419,7 +419,8 @@ static const char *usb_strings[] = { serial_no, "Black Magic GDB Server", "Black Magic UART Port", - "Black Magic DFU", + /* Required, the line for stm32f1s is "@Internal Flash /0x08000000/8*001Ka,56*001Kg" maybe use an if statement? */ + "@Internal Flash /0x08000000/04*016Kg,01*064Kg,03*128Kg", #if defined(PLATFORM_HAS_TRACESWO) "Black Magic Trace Capture", #endif