From c1dd88ba532bdc87d73eb82cd926a5cfc7848787 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 15 Jun 2020 15:22:52 +0300 Subject: [PATCH] Allow SWD debugging when built with swd_enable=1 --- workspace/TS100/Core/BSP/Miniware/Setup.c | 24 +++++++++++++++++------ workspace/TS100/Makefile | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/workspace/TS100/Core/BSP/Miniware/Setup.c b/workspace/TS100/Core/BSP/Miniware/Setup.c index 2d7f2c15..9f50feec 100644 --- a/workspace/TS100/Core/BSP/Miniware/Setup.c +++ b/workspace/TS100/Core/BSP/Miniware/Setup.c @@ -33,9 +33,13 @@ static void MX_ADC2_Init(void); void Setup_HAL() { SystemClock_Config(); - __HAL_AFIO_REMAP_SWJ_DISABLE() - ; -// __HAL_AFIO_REMAP_SWJ_NOJTAG(); + +#ifndef SWD_ENABLE + __HAL_AFIO_REMAP_SWJ_DISABLE(); +#else + __HAL_AFIO_REMAP_SWJ_NOJTAG(); +#endif + MX_GPIO_Init(); MX_DMA_Init(); MX_I2C1_Init(); @@ -244,7 +248,7 @@ static void MX_IWDG_Init(void) { hiwdg.Instance = IWDG; hiwdg.Init.Prescaler = IWDG_PRESCALER_256; hiwdg.Init.Reload = 100; -#ifndef LOCAL_BUILD +#ifndef SWD_ENABLE HAL_IWDG_Init(&hiwdg); #endif } @@ -425,8 +429,10 @@ static void MX_GPIO_Init(void) { HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); #ifdef MODEL_TS100 - /* Pull USB lines low to disable, pull down debug too*/ - GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; +#ifndef SWD_ENABLE + /* Pull USB and SWD lines low to prevent enumeration attempts and EMI affecting + * the debug core */ + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); @@ -434,6 +440,12 @@ static void MX_GPIO_Init(void) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET); +#else + /* Make all lines affecting SWD floating to allow debugging */ + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +#endif #else /* TS80 */ /* Leave USB lines open circuit*/ diff --git a/workspace/TS100/Makefile b/workspace/TS100/Makefile index 222aea12..1d4af101 100644 --- a/workspace/TS100/Makefile +++ b/workspace/TS100/Makefile @@ -55,6 +55,10 @@ bootldr_size=0x4000 # global defines --------------------------------------------------------------- GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) -DVECT_TAB_OFFSET=$(bootldr_size)U +ifdef swd_enable + GLOBAL_DEFINES += -DSWD_ENABLE +endif + # Enable debug code generation DEBUG=-g3 # Without debug code