Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From ea411bd77fcec6c19b2cd80c554d68bc24451b64 Mon Sep 17 00:00:00 2001
- From: Denis Tolstov <dtolstov@vniir.ru>
- Date: Tue, 6 Jun 2023 20:02:40 +0300
- Subject: [PATCH 1/3] platforms/blackpill-f4: Allow external debugging
- * Dispatch newlib/libgloss as nosys or rdimon
- * Enable nano.specs to reduce firmware size
- * Declare debugging available as on native
- ---
- src/platforms/common/blackpill-f4/Makefile.inc | 9 ++++++++-
- src/platforms/common/blackpill-f4/blackpill-f4.h | 5 +++++
- 2 files changed, 13 insertions(+), 1 deletion(-)
- diff --git a/src/platforms/common/blackpill-f4/Makefile.inc b/src/platforms/common/blackpill-f4/Makefile.inc
- index 62a6cf6..e552036 100644
- --- a/src/platforms/common/blackpill-f4/Makefile.inc
- +++ b/src/platforms/common/blackpill-f4/Makefile.inc
- @@ -15,11 +15,11 @@ CFLAGS += \
- -Iplatforms/common/blackpill-f4
- LDFLAGS_BOOT = \
- + --specs=nano.specs \
- -lopencm3_stm32f4 \
- -Wl,-T,$(LINKER_SCRIPT) \
- -nostartfiles \
- -lc \
- - -lnosys \
- -Wl,-Map=mapfile \
- -mthumb \
- -mcpu=cortex-m4 \
- @@ -37,6 +37,13 @@ LDFLAGS += $(LDFLAGS_BOOT)
- CFLAGS += -DDFU_SERIAL_LENGTH=13
- endif
- +ifeq ($(ENABLE_DEBUG), 1)
- +# Use rdimon when there is another JTAG adapter on our BMP adapter
- +LDFLAGS += --specs=rdimon.specs
- +else
- +LDFLAGS += --specs=nosys.specs
- +endif
- +
- ifdef ALTERNATIVE_PINOUT
- CFLAGS += -DALTERNATIVE_PINOUT=$(ALTERNATIVE_PINOUT)
- endif
- diff --git a/src/platforms/common/blackpill-f4/blackpill-f4.h b/src/platforms/common/blackpill-f4/blackpill-f4.h
- index 0342d3f..ec98775 100644
- --- a/src/platforms/common/blackpill-f4/blackpill-f4.h
- +++ b/src/platforms/common/blackpill-f4/blackpill-f4.h
- @@ -27,6 +27,11 @@
- #include "timing.h"
- #include "timing_stm32.h"
- +#ifdef ENABLE_DEBUG
- +#define PLATFORM_HAS_DEBUG
- +extern bool debug_bmp;
- +#endif
- +
- #define PLATFORM_HAS_TRACESWO
- /* Error handling for ALTERNATIVE_PINOUT
- --
- 2.34.1
- From 9095f29cf6759d7dea5e2d0c1e26e126b62b1f9b Mon Sep 17 00:00:00 2001
- From: Denis Tolstov <dtolstov@vniir.ru>
- Date: Tue, 6 Jun 2023 20:11:35 +0300
- Subject: [PATCH 2/3] platforms/blackpill-f4: Enable BMP DFU build variant
- * BMP DFU uploads are ~2.4x faster than STM32F411 BootROM DFU
- * Use 96MHz clocks in DFU (and in APP), revisit for F401 & 84MHz
- * Use the PA0 pushbutton active-low and pulled-up to control DFU entry
- ---
- src/platforms/common/blackpill-f4/Makefile.inc | 1 +
- src/platforms/common/blackpill-f4/blackpill-f4.c | 13 +++++++++++--
- src/platforms/common/blackpill-f4/usbdfu.c | 11 ++++++++---
- 3 files changed, 20 insertions(+), 5 deletions(-)
- diff --git a/src/platforms/common/blackpill-f4/Makefile.inc b/src/platforms/common/blackpill-f4/Makefile.inc
- index e552036..a231b20 100644
- --- a/src/platforms/common/blackpill-f4/Makefile.inc
- +++ b/src/platforms/common/blackpill-f4/Makefile.inc
- @@ -31,6 +31,7 @@ LDFLAGS_BOOT = \
- ifeq ($(BMP_BOOTLOADER), 1)
- $(info Load address 0x08004000 for BMPBootloader)
- LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8004000
- +CFLAGS += -DAPP_START=0x08004000
- CFLAGS += -DDFU_SERIAL_LENGTH=9
- else
- LDFLAGS += $(LDFLAGS_BOOT)
- diff --git a/src/platforms/common/blackpill-f4/blackpill-f4.c b/src/platforms/common/blackpill-f4/blackpill-f4.c
- index 0824dd9..dd53be1 100644
- --- a/src/platforms/common/blackpill-f4/blackpill-f4.c
- +++ b/src/platforms/common/blackpill-f4/blackpill-f4.c
- @@ -42,16 +42,23 @@ extern uint32_t _ebss; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-
- void platform_init(void)
- {
- +#ifdef USE_STM32F4_MASKROM
- volatile uint32_t *magic = (uint32_t *)&_ebss;
- +#endif
- /* Enable GPIO peripherals */
- rcc_periph_clock_enable(RCC_GPIOA);
- rcc_periph_clock_enable(RCC_GPIOC);
- rcc_periph_clock_enable(RCC_GPIOB);
- +#ifdef USE_STM32F4_MASKROM
- +
- + /* Blackpill board has a floating button on PA0. Pull it up and use as active-low. */
- + gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO0);
- +
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Warray-bounds"
- /* Check the USER button */
- - if (gpio_get(GPIOA, GPIO0) || (magic[0] == BOOTMAGIC0 && magic[1] == BOOTMAGIC1)) {
- + 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 */
- @@ -67,7 +74,9 @@ void platform_init(void)
- scb_reset_core();
- }
- #pragma GCC diagnostic pop
- - rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_84MHZ]);
- +
- +#endif
- + rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_96MHZ]);
- /* Enable peripherals */
- rcc_periph_clock_enable(RCC_OTGFS);
- diff --git a/src/platforms/common/blackpill-f4/usbdfu.c b/src/platforms/common/blackpill-f4/usbdfu.c
- index 24a96fe..1883b2d 100644
- --- a/src/platforms/common/blackpill-f4/usbdfu.c
- +++ b/src/platforms/common/blackpill-f4/usbdfu.c
- @@ -22,6 +22,7 @@
- #include <libopencm3/stm32/rcc.h>
- #include <libopencm3/stm32/gpio.h>
- #include <libopencm3/cm3/scb.h>
- +#include <libopencm3/usb/dwc/otg_fs.h>
- #include "usbdfu.h"
- #include "general.h"
- @@ -43,19 +44,22 @@ int main(void)
- volatile uint32_t *magic = (uint32_t *)&_ebss;
- rcc_periph_clock_enable(RCC_GPIOA);
- + /* Blackpill board has a floating button on PA0. Pull it up and use as active-low. */
- + gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO0);
- +
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Warray-bounds"
- - if (gpio_get(GPIOA, GPIO0) || (magic[0] == BOOTMAGIC0 && magic[1] == BOOTMAGIC1)) {
- + if (!gpio_get(GPIOA, GPIO0) || (magic[0] == BOOTMAGIC0 && magic[1] == BOOTMAGIC1)) {
- magic[0] = 0;
- magic[1] = 0;
- } else
- dfu_jump_app_if_valid();
- #pragma GCC diagnostic pop
- - rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
- + rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_96MHZ]);
- /* Assert blue LED as indicator we are in the bootloader */
- - rcc_periph_clock_enable(RCC_GPIOD);
- + rcc_periph_clock_enable(RCC_GPIOC);
- gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_BOOTLOADER);
- gpio_set(LED_PORT, LED_BOOTLOADER);
- @@ -68,6 +72,7 @@ int main(void)
- dfu_protect(false);
- dfu_init(&USB_DRIVER);
- +
- dfu_main();
- }
- --
- 2.34.1
- From ce791cd20e6f183162f26083e0ea7fc6a57a1550 Mon Sep 17 00:00:00 2001
- From: Denis Tolstov <dtolstov@vniir.ru>
- Date: Tue, 6 Jun 2023 20:18:16 +0300
- Subject: [PATCH 3/3] platforms/blackpill-f4: Fix DWC USB init
- ---
- src/platforms/common/blackpill-f4/blackpill-f4.c | 6 ++++++
- src/platforms/common/blackpill-f4/usbdfu.c | 6 ++++++
- 2 files changed, 12 insertions(+)
- diff --git a/src/platforms/common/blackpill-f4/blackpill-f4.c b/src/platforms/common/blackpill-f4/blackpill-f4.c
- index dd53be1..83fa603 100644
- --- a/src/platforms/common/blackpill-f4/blackpill-f4.c
- +++ b/src/platforms/common/blackpill-f4/blackpill-f4.c
- @@ -82,9 +82,15 @@ void platform_init(void)
- rcc_periph_clock_enable(RCC_OTGFS);
- rcc_periph_clock_enable(RCC_CRC);
- +#if 0
- /* 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);
- +#else
- + /* PA9/PA10 are not routed to USB on Blackpill-F4 */
- + gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12);
- + gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12);
- +#endif
- GPIOA_OSPEEDR &= 0x3c00000cU;
- GPIOA_OSPEEDR |= 0x28000008U;
- diff --git a/src/platforms/common/blackpill-f4/usbdfu.c b/src/platforms/common/blackpill-f4/usbdfu.c
- index 1883b2d..107c71a 100644
- --- a/src/platforms/common/blackpill-f4/usbdfu.c
- +++ b/src/platforms/common/blackpill-f4/usbdfu.c
- @@ -73,6 +73,12 @@ int main(void)
- dfu_protect(false);
- dfu_init(&USB_DRIVER);
- +#if 0
- + /* https://github.com/libopencm3/libopencm3/pull/1256#issuecomment-779424001 */
- + OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS | OTG_GCCFG_PWRDWN;
- + OTG_FS_GCCFG &= ~(OTG_GCCFG_VBUSBSEN | OTG_GCCFG_VBUSASEN);
- +#endif
- +
- dfu_main();
- }
- --
- 2.34.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement