Skip to content

Commit 44585f5

Browse files
authored
Merge pull request #52 from twelho/fix-usbpullup
Disable SWD if PA13/PA14 are used for another purpose
2 parents 9af0f05 + 1cd9417 commit 44585f5

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/stm32f103/target_stm32f103.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,26 @@ void target_clock_setup(void) {
7777

7878
void target_gpio_setup(void) {
7979
/* Enable GPIO clocks */
80-
if (USES_GPIOA) {
81-
rcc_periph_clock_enable(RCC_GPIOA);
82-
}
83-
if (USES_GPIOB) {
84-
rcc_periph_clock_enable(RCC_GPIOB);
85-
}
86-
if (USES_GPIOC) {
87-
rcc_periph_clock_enable(RCC_GPIOC);
80+
#if USES_GPIOA
81+
rcc_periph_clock_enable(RCC_GPIOA);
82+
#endif
83+
#if USES_GPIOB
84+
rcc_periph_clock_enable(RCC_GPIOB);
85+
#endif
86+
#if USES_GPIOC
87+
rcc_periph_clock_enable(RCC_GPIOC);
88+
#endif
89+
90+
/* Disable SWD if PA13 and/or PA14 are used for another purpose */
91+
#if ((HAVE_LED && LED_GPIO_PORT == GPIOA && (LED_GPIO_PORT == GPIO13 || LED_GPIO_PORT == GPIO14)) || \
92+
(HAVE_BUTTON && BUTTON_GPIO_PORT == GPIOA && (BUTTON_GPIO_PIN == GPIO13 || BUTTON_GPIO_PIN == GPIO14)) || \
93+
(HAVE_USB_PULLUP_CONTROL && USB_PULLUP_GPIO_PORT == GPIOA && \
94+
(USB_PULLUP_GPIO_PIN == GPIO13 || USB_PULLUP_GPIO_PIN == GPIO14)))
95+
{
96+
rcc_periph_clock_enable(RCC_AFIO);
97+
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF, 0);
8898
}
99+
#endif
89100

90101
/* Setup LEDs */
91102
#if HAVE_LED

0 commit comments

Comments
 (0)