stlink: Add option to turn SWIM/RST into UART RX/TX

Building for `stlink` with `SWIM_AS_UART=1` now enables the use of the
SWIM and RST ports as RX and TX on cheap ST-Link V2 clones.

This is done by using USART1 on the alternative port instead of USART2.
This commit is contained in:
Silke Hofstra 2018-09-29 20:23:09 +02:00 committed by Piotr Esden-Tempski
parent f2c59b052c
commit a95e2e80bc
3 changed files with 20 additions and 3 deletions

View File

@ -25,6 +25,10 @@ else
LDFLAGS += --specs=nosys.specs
endif
ifeq ($(SWIM_AS_UART), 1)
CFLAGS += -DSWIM_AS_UART=1
endif
VPATH += platforms/stm32
SRC += cdcacm.c \
@ -47,4 +51,3 @@ blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o stlink_common.o serialno.o
host_clean:
-$(Q)$(RM) *.bin *elf *hex

View File

@ -81,6 +81,12 @@ void platform_init(void)
if (rev > 1) /* Reconnect USB */
gpio_set(GPIOA, GPIO15);
cdcacm_init();
#ifdef SWIM_AS_UART
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_FULL_SWJ,
AFIO_MAPR_USART1_REMAP);
#endif
/* Don't enable UART if we're being debugged. */
if (!(SCS_DEMCR & SCS_DEMCR_TRCENA))
usbuart_init();

View File

@ -105,15 +105,24 @@ int usbuart_debug_write(const char *buf, size_t len);
#define IRQ_PRI_USB_VBUS (14 << 4)
#define IRQ_PRI_SWO_DMA (0 << 4)
#ifdef SWIM_AS_UART
#define USBUSART USART1
#define USBUSART_CR1 USART1_CR1
#define USBUSART_DR USART1_DR
#define USBUSART_IRQ NVIC_USART1_IRQ
#define USBUSART_CLK RCC_USART1
#define USBUSART_ISR(x) usart1_isr(x)
#else
#define USBUSART USART2
#define USBUSART_CR1 USART2_CR1
#define USBUSART_DR USART2_DR
#define USBUSART_IRQ NVIC_USART2_IRQ
#define USBUSART_CLK RCC_USART2
#define USBUSART_ISR(x) usart2_isr(x)
#endif
#define USBUSART_PORT GPIOA
#define USBUSART_TX_PIN GPIO2
#define USBUSART_RX_PIN GPIO3
#define USBUSART_ISR(x) usart2_isr(x)
#define USBUSART_DMA_BUS DMA1
#define USBUSART_DMA_CLK RCC_DMA1
@ -179,5 +188,4 @@ extern uint32_t detect_rev(void);
#define snprintf sniprintf
#endif
#endif