Skip to content

Instantly share code, notes, and snippets.

@cyber-murmel
Created January 28, 2022 20:26
Show Gist options
  • Save cyber-murmel/1bdb66818e05535c85565206915a52ef to your computer and use it in GitHub Desktop.
Save cyber-murmel/1bdb66818e05535c85565206915a52ef to your computer and use it in GitHub Desktop.
Patch to add RTS on PB8 and DTR on PB9 to the Black Magic Probe UART
diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c
index 399dd3d..d56d10e 100644
--- a/src/platforms/common/cdcacm.c
+++ b/src/platforms/common/cdcacm.c
@@ -451,12 +451,17 @@ static enum usbd_request_return_codes cdcacm_control_request(usbd_device *dev,
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
cdcacm_set_modem_state(dev, req->wIndex, true, true);
/* Ignore if not for GDB interface */
- if(req->wIndex != GDB_IF_NO)
+ switch(req->wIndex) {
+ case UART_IF_NO:
+ gpio_set_val(USBUSART_PORT, USBUSART_DTR_PIN, !(req->wValue & 1));
+ gpio_set_val(USBUSART_PORT, USBUSART_RTS_PIN, !((req->wValue >> 1) & 1));
return USBD_REQ_HANDLED;
-
- cdcacm_gdb_dtr = req->wValue & 1;
-
- return USBD_REQ_HANDLED;
+ case GDB_IF_NO:
+ cdcacm_gdb_dtr = req->wValue & 1;
+ return USBD_REQ_HANDLED;
+ default:
+ return USBD_REQ_HANDLED;
+ }
case USB_CDC_REQ_SET_LINE_CODING:
if(*len < sizeof(struct usb_cdc_line_coding))
return USBD_REQ_NOTSUPP;
diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h
index 36cab71..611fd72 100644
--- a/src/platforms/swlink/platform.h
+++ b/src/platforms/swlink/platform.h
@@ -88,6 +88,8 @@ int usbuart_debug_write(const char *buf, size_t len);
gpio_set_mode(USBUSART_PORT, GPIO_MODE_INPUT, \
GPIO_CNF_INPUT_PULL_UPDOWN, USBUSART_RX_PIN); \
gpio_set(USBUSART_PORT, USBUSART_RX_PIN); \
+ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_50_MHZ, \
+ GPIO_CNF_OUTPUT_PUSHPULL, USBUSART_RTS_PIN | USBUSART_DTR_PIN); \
} while(0)
#define USB_DRIVER st_usbfs_v1_usb_driver
@@ -110,6 +112,8 @@ int usbuart_debug_write(const char *buf, size_t len);
#define USBUSART_PORT GPIOB
#define USBUSART_TX_PIN GPIO6
#define USBUSART_RX_PIN GPIO7
+#define USBUSART_RTS_PIN GPIO8
+#define USBUSART_DTR_PIN GPIO9
#define USBUSART_ISR(x) usart1_isr(x)
#define USBUSART_DMA_BUS DMA1
#define USBUSART_DMA_CLK RCC_DMA1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment