Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Speed up bus turnaround for blackpill-f4 like other platforms #1690

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 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,31 @@
#define SWDIO_PORT TMS_PORT
#define SWDIO_PIN TMS_PIN

#define SWDIO_MODE_REG_MULT_PB9 (1U << (9U << 1U))
#define SWDIO_MODE_REG_MULT_PB8 (1U << (8U << 1U))
/* 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 &= ~(3U * 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 |= (1U * SWDIO_MODE_REG_MULT); \
SWDIO_MODE_REG = mode_reg; \
} while (0)

#define TRST_PORT PINOUT_SWITCH(GPIOA, GPIOB)
#define TRST_PIN PINOUT_SWITCH(GPIO6, GPIO3)

Expand Down Expand Up @@ -221,10 +246,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