Skip to content

Commit

Permalink
blackpill-f4: Speed up bus turnaround like on other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Nov 27, 2023
1 parent 39cb6d6 commit 5fa711e
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/platforms/common/blackpill-f4/blackpill-f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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); \
Expand Down

0 comments on commit 5fa711e

Please sign in to comment.