From 099540cccbfce07ad39288d1d88f359022c7eaf0 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Thu, 18 Aug 2022 22:53:23 +0100 Subject: [PATCH] usb_serial: Moved the "SemiHosting" init into a more suitable spot in bringup --- src/platforms/common/usb_serial.c | 20 +++++++++++++++++--- src/platforms/native/platform.c | 4 ---- src/platforms/stlink/platform.c | 4 ---- src/platforms/swlink/platform.c | 4 ---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index ad4f1f7..6f7439d 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -41,8 +41,8 @@ #include "general.h" #include "gdb_if.h" #include "usb_serial.h" -#if defined(PLATFORM_HAS_TRACESWO) -# include "traceswo.h" +#ifdef PLATFORM_HAS_TRACESWO +#include "traceswo.h" #endif #include "usbuart.h" @@ -52,6 +52,16 @@ static bool gdb_uart_dtr = true; static void usb_serial_set_state(usbd_device *dev, uint16_t iface, uint8_t ep); +#ifdef ENABLE_DEBUG +/* + * This call initialises "SemiHosting", only we then do our own SVC interrupt things to + * route all output through to the debug USB serial interface if debug_bmp is true. + * + * https://github.com/mirror/newlib-cygwin/blob/master/newlib/libc/sys/arm/syscalls.c#L115 + */ +void initialise_monitor_handles(void); +#endif + static enum usbd_request_return_codes gdb_uart_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *const len, void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { @@ -140,7 +150,7 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value) dev, CDCACM_UART_ENDPOINT | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, usbuart_usb_in_cb); usbd_ep_setup(dev, (CDCACM_UART_ENDPOINT + 1) | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); -#if defined(PLATFORM_HAS_TRACESWO) +#ifdef PLATFORM_HAS_TRACESWO /* Trace interface */ usbd_ep_setup(dev, TRACE_ENDPOINT | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_BULK, 64, trace_buf_drain); #endif @@ -155,4 +165,8 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value) */ usb_serial_set_state(dev, GDB_IF_NO, CDCACM_GDB_ENDPOINT); usb_serial_set_state(dev, UART_IF_NO, CDCACM_UART_ENDPOINT); + +#ifdef ENABLE_DEBUG + initialise_monitor_handles(); +#endif } diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 512fe2b..9cf2be9 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -138,10 +138,6 @@ int platform_hwversion(void) void platform_init(void) { SCS_DEMCR |= SCS_DEMCR_VC_MON_EN; -#ifdef ENABLE_DEBUG - void initialise_monitor_handles(void); - initialise_monitor_handles(); -#endif rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]); diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 779b079..4501b0d 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -48,10 +48,6 @@ void platform_init(void) { rev = detect_rev(); SCS_DEMCR |= SCS_DEMCR_VC_MON_EN; -#ifdef ENABLE_DEBUG - void initialise_monitor_handles(void); - initialise_monitor_handles(); -#endif rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]); if (rev == 0) { led_idle_run = GPIO8; diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 8d43476..70bac0e 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -50,10 +50,6 @@ void platform_init(void) { uint32_t data; SCS_DEMCR |= SCS_DEMCR_VC_MON_EN; -#ifdef ENABLE_DEBUG - void initialise_monitor_handles(void); - initialise_monitor_handles(); -#endif rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]); rev = detect_rev(); /* Enable peripherals */