diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index a261cbc..59d6908 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -108,20 +108,27 @@ #define LED_IDLE_RUN LED_1 #define LED_ERROR LED_2 +# define SWD_CR GPIO_CRL(SWDIO_PORT) +# define SWD_CR_MULT (1 << (4 << 2)) + #define TMS_SET_MODE() do { \ gpio_set(TMS_DIR_PORT, TMS_DIR_PIN); \ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); \ } while(0) #define SWDIO_MODE_FLOAT() do { \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); \ - gpio_clear(SWDIO_DIR_PORT, SWDIO_DIR_PIN); \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x4 * SWD_CR_MULT); \ + GPIO_BRR(SWDIO_DIR_PORT) = SWDIO_DIR_PIN; \ + SWD_CR = cr; \ } while(0) #define SWDIO_MODE_DRIVE() do { \ - gpio_set(SWDIO_DIR_PORT, SWDIO_DIR_PIN); \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x1 * SWD_CR_MULT); \ + GPIO_BSRR(SWDIO_DIR_PORT) = SWDIO_DIR_PIN; \ + SWD_CR = cr; \ } while(0) #define UART_PIN_SETUP() do { \ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index cadb5d8..548a4c1 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -71,16 +71,24 @@ #define PLATFORM_HAS_TRACESWO 1 #define NUM_TRACE_PACKETS (128) /* This is an 8K buffer */ +# define SWD_CR GPIO_CRH(SWDIO_PORT) +# define SWD_CR_MULT (1 << ((14 - 8) << 2)) + #define TMS_SET_MODE() \ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); -#define SWDIO_MODE_FLOAT() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); - +#define SWDIO_MODE_FLOAT() do { \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x4 * SWD_CR_MULT); \ + SWD_CR = cr; \ +} while(0) +#define SWDIO_MODE_DRIVE() do { \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x1 * SWD_CR_MULT); \ + SWD_CR = cr; \ +} while(0) #define UART_PIN_SETUP() \ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 748c31f..436dd24 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -58,16 +58,24 @@ #define LED_PORT_UART GPIOC #define LED_UART GPIO14 +# define SWD_CR GPIO_CRH(SWDIO_PORT) +# define SWD_CR_MULT (1 << ((13 - 8) << 2)) + #define TMS_SET_MODE() \ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); -#define SWDIO_MODE_FLOAT() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); - +#define SWDIO_MODE_FLOAT() do { \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x4 * SWD_CR_MULT); \ + SWD_CR = cr; \ +} while(0) +#define SWDIO_MODE_DRIVE() do { \ + uint32_t cr = SWD_CR; \ + cr &= ~(0xf * SWD_CR_MULT); \ + cr |= (0x1 * SWD_CR_MULT); \ + SWD_CR = cr; \ +} while(0) #define UART_PIN_SETUP() do { \ AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; \ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \