Skip to content

Commit

Permalink
common/blackpill-f4: Refresh voodoo
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ALTracer authored and dragonmux committed Jan 14, 2024
1 parent af30241 commit b9969de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/platforms/common/blackpill-f4/blackpill-f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/platforms/common/blackpill-f4/usbdfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
Expand Down

0 comments on commit b9969de

Please sign in to comment.