diff --git a/src/stm32/cdcacm.c b/src/stm32/cdcacm.c index f704a27a..232ce78d 100644 --- a/src/stm32/cdcacm.c +++ b/src/stm32/cdcacm.c @@ -499,6 +499,13 @@ static void cdcacm_data_rx_cb(u8 ep) char buf[CDCACM_PACKET_SIZE]; int len = usbd_ep_read_packet(0x03, buf, CDCACM_PACKET_SIZE); + + /* Don't bother if uart is disabled. + * This will be the case on mini while we're being debugged. + */ + if(!(RCC_APB2ENR & RCC_APB2ENR_USART1EN)) + return; + for(int i = 0; i < len; i++) usart_send_blocking(USART1, buf[i]); } diff --git a/src/stm32/platform.c b/src/stm32/platform.c index 8ab99cd8..930ffd50 100644 --- a/src/stm32/platform.c +++ b/src/stm32/platform.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "platform.h" #include "jtag_scan.h" @@ -46,6 +47,23 @@ static void morse_update(void); static void uart_init(void); #endif +/* Pins PB[7:5] are used to detect hardware revision. + * 000 - Original production build. + * 001 - Mini production build. + */ +int platform_hwversion(void) +{ + static int hwversion = -1; + if (hwversion == -1) { + gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_INPUT_PULL_UPDOWN, + GPIO7 | GPIO6 | GPIO5); + gpio_clear(GPIOB, GPIO7 | GPIO6 | GPIO5); + hwversion = gpio_get(GPIOB, GPIO7 | GPIO6 | GPIO5) >> 5; + } + return hwversion; +} + int platform_init(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); @@ -84,7 +102,11 @@ int platform_init(void) systick_counter_enable(); #ifdef INCLUDE_UART_INTERFACE - uart_init(); + /* On mini hardware, UART and SWD share connector pins. + * Don't enable UART if we're being debugged. */ + if ((platform_hwversion() == 0) || + !(SCS_DEMCR & SCS_DEMCR_TRCENA)) + uart_init(); #endif SCB_VTOR = 0x2000; // Relocate interrupt vector table here