From 5fa711e46f83a81c6aea727791e2ab0536a74e4d Mon Sep 17 00:00:00 2001 From: ALTracer Date: Mon, 27 Nov 2023 22:06:35 +0300 Subject: [PATCH] blackpill-f4: Speed up bus turnaround like on other platforms --- .../common/blackpill-f4/blackpill-f4.h | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/platforms/common/blackpill-f4/blackpill-f4.h b/src/platforms/common/blackpill-f4/blackpill-f4.h index eb77e4fbffa..95bd1d16fce 100644 --- a/src/platforms/common/blackpill-f4/blackpill-f4.h +++ b/src/platforms/common/blackpill-f4/blackpill-f4.h @@ -115,6 +115,41 @@ #define SWDIO_PORT TMS_PORT #define SWDIO_PIN TMS_PIN +#if 0 +#define TMS_SET_MODE() gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN); +#define SWDIO_MODE_FLOAT() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SWDIO_PIN); + +#define SWDIO_MODE_DRIVE() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, SWDIO_PIN); + +#else + +#define SWDIO_MODE_REG_MULT_PB9 (1 << (9 << 1)) +#define SWDIO_MODE_REG_MULT_PB8 (1 << (8 << 1)) +/* Update when adding more alternative pinouts */ +#define SWDIO_MODE_REG_MULT PINOUT_SWITCH(SWDIO_MODE_REG_MULT_PB9, SWDIO_MODE_REG_MULT_PB8) +#define SWDIO_MODE_REG GPIO_MODER(TMS_PORT) + +#define TMS_SET_MODE() \ + gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN); \ + gpio_set_output_options(TMS_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, TMS_PIN); + +/* Perform SWDIO bus turnaround faster than a gpio_mode_setup() call */ +#define SWDIO_MODE_FLOAT() \ + do { \ + uint32_t mode_reg = SWDIO_MODE_REG; \ + mode_reg &= ~(0x3 * SWDIO_MODE_REG_MULT); \ + SWDIO_MODE_REG = mode_reg; \ + } while (0) + +#define SWDIO_MODE_DRIVE() \ + do { \ + uint32_t mode_reg = SWDIO_MODE_REG; \ + mode_reg |= (1 * SWDIO_MODE_REG_MULT); \ + SWDIO_MODE_REG = mode_reg; \ + } while (0) + +#endif + #define TRST_PORT PINOUT_SWITCH(GPIOA, GPIOB) #define TRST_PIN PINOUT_SWITCH(GPIO6, GPIO3) @@ -221,10 +256,6 @@ #define BOOTMAGIC0 UINT32_C(0xb007da7a) #define BOOTMAGIC1 UINT32_C(0xbaadfeed) -#define TMS_SET_MODE() gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN); -#define SWDIO_MODE_FLOAT() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SWDIO_PIN); - -#define SWDIO_MODE_DRIVE() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, SWDIO_PIN); #define UART_PIN_SETUP() \ do { \ gpio_mode_setup(USBUSART_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, USBUSART_TX_PIN); \