From 89bcdcc60ab5e3c35e99c4f2cc7d052e831cc563 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 10 Jun 2012 17:34:26 +1200 Subject: Moved stm32 generic platform files out of native platform dir. --- src/platforms/stm32/jtagtap.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/platforms/stm32/jtagtap.c (limited to 'src/platforms/stm32/jtagtap.c') diff --git a/src/platforms/stm32/jtagtap.c b/src/platforms/stm32/jtagtap.c new file mode 100644 index 0000000..8160be8 --- /dev/null +++ b/src/platforms/stm32/jtagtap.c @@ -0,0 +1,81 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* This file implements the low-level JTAG TAP interface. */ + +#include + +#include "general.h" + +#include "jtagtap.h" + +int jtagtap_init(void) +{ + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); + + /* Go to JTAG mode for SWJ-DP */ + for(int i = 0; i <= 50; i++) jtagtap_next(1, 0); /* Reset SW-DP */ + jtagtap_tms_seq(0xE73C, 16); /* SWD to JTAG sequence */ + jtagtap_soft_reset(); + + return 0; +} + +void jtagtap_reset(void) +{ + volatile int i; + gpio_clear(TRST_PORT, TRST_PIN); + for(i = 0; i < 10000; i++) asm("nop"); + gpio_set(TRST_PORT, TRST_PIN); + jtagtap_soft_reset(); +} + +void jtagtap_srst(void) +{ + volatile int i; + gpio_set(SRST_PORT, SRST_PIN); + for(i = 0; i < 10000; i++) asm("nop"); + gpio_clear(SRST_PORT, SRST_PIN); +} + +inline uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDO) +{ + uint16_t ret; + + gpio_set_val(TMS_PORT, TMS_PIN, dTMS); + gpio_set_val(TDI_PORT, TDI_PIN, dTDO); + gpio_set(TCK_PORT, TCK_PIN); + ret = gpio_get(TDO_PORT, TDO_PIN); + gpio_clear(TCK_PORT, TCK_PIN); + + DEBUG("jtagtap_next(TMS = %d, TDO = %d) = %d\n", dTMS, dTDO, ret); + + return ret != 0; +} + + + +#define PROVIDE_GENERIC_JTAGTAP_TMS_SEQ +#define PROVIDE_GENERIC_JTAGTAP_TDI_TDO_SEQ +#define PROVIDE_GENERIC_JTAGTAP_TDI_SEQ + +#include "jtagtap_generic.c" + -- cgit v1.2.3