diff --git a/inc/decls.h b/inc/decls.h index 3303d052..ca8e87a7 100644 --- a/inc/decls.h +++ b/inc/decls.h @@ -10,6 +10,8 @@ * See the file COPYING for more details, or visit . */ +#define CONFIG_SWD 1 + #include #include #include diff --git a/inc/mcu/stm32f105_regs.h b/inc/mcu/stm32f105_regs.h index d929c20d..3291c7eb 100644 --- a/inc/mcu/stm32f105_regs.h +++ b/inc/mcu/stm32f105_regs.h @@ -191,6 +191,7 @@ struct afio { uint32_t mapr2; /* 1C: AF remap and debug I/O configuration #2 */ }; +#define AFIO_MAPR_SWJ_CFG_ENABLED (2u<<24) #define AFIO_MAPR_SWJ_CFG_DISABLED (4u<<24) #define AFIO_MAPR_TIM4_REMAP_FULL (1u<<12) #define AFIO_MAPR_TIM3_REMAP_FULL (3u<<10) diff --git a/src/gotek/board.c b/src/gotek/board.c index af679ea1..1ef801c1 100644 --- a/src/gotek/board.c +++ b/src/gotek/board.c @@ -97,10 +97,12 @@ unsigned int board_get_buttons(void) unsigned int board_get_rotary(void) { unsigned int x = 3; +#if !defined(CONFIG_SWD) if ((mcu_package != MCU_QFN32) && (ff_cfg.chgrst != CHGRST_pa14)) { /* Alternative location at PA13, PA14. */ x &= gpioa->idr >> 13; } +#endif if (mcu_package == MCU_LQFP64) { /* Original rotary header at PC10, PC11. */ x &= gpioc->idr >> 10; @@ -118,12 +120,14 @@ uint32_t board_rotary_exti_mask; void board_setup_rotary_exti(void) { uint32_t m = 0; +#if !defined(CONFIG_SWD) if ((mcu_package != MCU_QFN32) && (ff_cfg.chgrst != CHGRST_pa14)) { /* Alternative location at PA13, PA14. */ exti_route_pa(13); exti_route_pa(14); m |= m(13) | m(14); } +#endif if (mcu_package == MCU_LQFP64) { /* Original rotary header at PC10, PC11. */ exti_route_pc(10); @@ -181,6 +185,11 @@ void board_init(void) pa_skip |= 0x0600; #endif +#if defined(CONFIG_SWD) + /* PA13-14 (SWD) */ + pa_skip |= 0x6000; +#endif + /* PB0,4,9 (floppy inputs). */ pb_skip = 0x0211; diff --git a/src/mcu_stm32f105.c b/src/mcu_stm32f105.c index 38359dbc..1098750f 100644 --- a/src/mcu_stm32f105.c +++ b/src/mcu_stm32f105.c @@ -109,11 +109,23 @@ static void peripheral_init(void) RCC_APB2ENR_TIM1EN); rcc->ahbenr = RCC_AHBENR_DMA1EN; +#if defined(CONFIG_SWD) + + /* Preserve PA13, PA14 as SWD. */ + afio->mapr = AFIO_MAPR_SWJ_CFG_ENABLED; + gpioa->crl = 0x44444444u; + gpioa->crh = (gpioa->crh & 0x0ff00000u) | 0x40044444u; + +#else + /* Turn off serial-wire JTAG and reclaim the GPIOs. */ afio->mapr = AFIO_MAPR_SWJ_CFG_DISABLED; /* All pins in a stable state. */ gpio_init(gpioa); + +#endif + gpio_init(gpiob); gpio_init(gpioc); }