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:
parent
f2c59b052c
commit
a95e2e80bc
|
@ -25,6 +25,10 @@ else
|
||||||
LDFLAGS += --specs=nosys.specs
|
LDFLAGS += --specs=nosys.specs
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(SWIM_AS_UART), 1)
|
||||||
|
CFLAGS += -DSWIM_AS_UART=1
|
||||||
|
endif
|
||||||
|
|
||||||
VPATH += platforms/stm32
|
VPATH += platforms/stm32
|
||||||
|
|
||||||
SRC += cdcacm.c \
|
SRC += cdcacm.c \
|
||||||
|
@ -47,4 +51,3 @@ blackmagic_dfu.elf: usbdfu.o dfucore.o dfu_f1.o stlink_common.o serialno.o
|
||||||
|
|
||||||
host_clean:
|
host_clean:
|
||||||
-$(Q)$(RM) *.bin *elf *hex
|
-$(Q)$(RM) *.bin *elf *hex
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,12 @@ void platform_init(void)
|
||||||
if (rev > 1) /* Reconnect USB */
|
if (rev > 1) /* Reconnect USB */
|
||||||
gpio_set(GPIOA, GPIO15);
|
gpio_set(GPIOA, GPIO15);
|
||||||
cdcacm_init();
|
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. */
|
/* Don't enable UART if we're being debugged. */
|
||||||
if (!(SCS_DEMCR & SCS_DEMCR_TRCENA))
|
if (!(SCS_DEMCR & SCS_DEMCR_TRCENA))
|
||||||
usbuart_init();
|
usbuart_init();
|
||||||
|
|
|
@ -105,15 +105,24 @@ int usbuart_debug_write(const char *buf, size_t len);
|
||||||
#define IRQ_PRI_USB_VBUS (14 << 4)
|
#define IRQ_PRI_USB_VBUS (14 << 4)
|
||||||
#define IRQ_PRI_SWO_DMA (0 << 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 USART2
|
||||||
#define USBUSART_CR1 USART2_CR1
|
#define USBUSART_CR1 USART2_CR1
|
||||||
#define USBUSART_DR USART2_DR
|
#define USBUSART_DR USART2_DR
|
||||||
#define USBUSART_IRQ NVIC_USART2_IRQ
|
#define USBUSART_IRQ NVIC_USART2_IRQ
|
||||||
#define USBUSART_CLK RCC_USART2
|
#define USBUSART_CLK RCC_USART2
|
||||||
|
#define USBUSART_ISR(x) usart2_isr(x)
|
||||||
|
#endif
|
||||||
#define USBUSART_PORT GPIOA
|
#define USBUSART_PORT GPIOA
|
||||||
#define USBUSART_TX_PIN GPIO2
|
#define USBUSART_TX_PIN GPIO2
|
||||||
#define USBUSART_RX_PIN GPIO3
|
#define USBUSART_RX_PIN GPIO3
|
||||||
#define USBUSART_ISR(x) usart2_isr(x)
|
|
||||||
|
|
||||||
#define USBUSART_DMA_BUS DMA1
|
#define USBUSART_DMA_BUS DMA1
|
||||||
#define USBUSART_DMA_CLK RCC_DMA1
|
#define USBUSART_DMA_CLK RCC_DMA1
|
||||||
|
@ -179,5 +188,4 @@ extern uint32_t detect_rev(void);
|
||||||
#define snprintf sniprintf
|
#define snprintf sniprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue