From b9969de3b484b8dfdfb53111ba239031a092dba6 Mon Sep 17 00:00:00 2001 From: ALTracer Date: Sun, 7 Jan 2024 14:28:56 +0300 Subject: [PATCH] common/blackpill-f4: Refresh voodoo * Drop RCC_OTGFS enabling because it happens in stm32f107_usbd_init, and move RCC_CRC up to GPIOs * Drop GPIO_OSPEEDR setting of PA1/13/14 because that mapping is obsolete * Bump OSPEEDR setting from 2MHz to 25MHz for GPIO TAP pins * Reduce default "max" frequency for robust UX --- .../common/blackpill-f4/blackpill-f4.c | 21 ++++++++----------- src/platforms/common/blackpill-f4/usbdfu.c | 4 +--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/platforms/common/blackpill-f4/blackpill-f4.c b/src/platforms/common/blackpill-f4/blackpill-f4.c index 6080f1eb6e4..d5aaf747aba 100644 --- a/src/platforms/common/blackpill-f4/blackpill-f4.c +++ b/src/platforms/common/blackpill-f4/blackpill-f4.c @@ -45,10 +45,11 @@ volatile uint32_t magic[2] __attribute__((section(".noinit"))); void platform_init(void) { - /* Enable GPIO peripherals */ + /* Enable peripherals */ rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_GPIOB); + rcc_periph_clock_enable(RCC_CRC); #ifndef BMP_BOOTLOADER /* Blackpill board has a floating button on PA0. Pull it up and use as active-low. */ @@ -73,26 +74,19 @@ void platform_init(void) #endif rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[PLATFORM_CLOCK_FREQ]); - /* Enable peripherals */ - rcc_periph_clock_enable(RCC_OTGFS); - rcc_periph_clock_enable(RCC_CRC); - /* Set up DM/DP pins. PA9/PA10 are not routed to USB-C. */ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12); gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12); - GPIOA_OSPEEDR &= 0x3c00000cU; - GPIOA_OSPEEDR |= 0x28000008U; - /* Set up TDI, TDO, TCK and TMS pins */ gpio_mode_setup(TDI_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TDI_PIN); gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, TDO_PIN); gpio_mode_setup(TCK_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TCK_PIN); gpio_mode_setup(TMS_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, TMS_PIN); - gpio_set_output_options(TDI_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, TDI_PIN); - gpio_set_output_options(TDO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, TDO_PIN); - gpio_set_output_options(TCK_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, TCK_PIN); - gpio_set_output_options(TMS_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, TMS_PIN); + gpio_set_output_options(TDI_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, TDI_PIN); + gpio_set_output_options(TDO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, TDO_PIN); + gpio_set_output_options(TCK_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, TCK_PIN); + gpio_set_output_options(TMS_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, TMS_PIN); /* Set up LED pins */ gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_IDLE_RUN | LED_ERROR | LED_BOOTLOADER); @@ -114,6 +108,9 @@ void platform_init(void) /* 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); + + /* By default, do not drive the SWD bus too fast. */ + platform_max_frequency_set(3000000); } void platform_nrst_set_val(bool assert) diff --git a/src/platforms/common/blackpill-f4/usbdfu.c b/src/platforms/common/blackpill-f4/usbdfu.c index b6f5cfa8991..d5d205ea968 100644 --- a/src/platforms/common/blackpill-f4/usbdfu.c +++ b/src/platforms/common/blackpill-f4/usbdfu.c @@ -42,6 +42,7 @@ void dfu_detach(void) int main(void) { + /* Enable GPIO peripherals */ rcc_periph_clock_enable(RCC_GPIOA); /* Blackpill board has a floating button on PA0. Pull it up and use as active-low. */ @@ -63,9 +64,6 @@ int main(void) /* Run heartbeat on blue LED */ sys_tick_init(); - /* Enable peripherals */ - rcc_periph_clock_enable(RCC_OTGFS); - /* Set up USB Pins and alternate function*/ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO11 | GPIO12); gpio_set_af(GPIOA, GPIO_AF10, GPIO11 | GPIO12);