Skip to content

Commit

Permalink
swd: Reclaim pins PA13 & PA14 for SWD.
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Apr 30, 2024
1 parent 7cc12ec commit 82e5efd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

#define CONFIG_SWD 1

#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
Expand Down
1 change: 1 addition & 0 deletions inc/mcu/stm32f105_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/gotek/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions src/mcu_stm32f105.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 82e5efd

Please sign in to comment.