From 377733b191abeaef7a6424de71646a6b9493d032 Mon Sep 17 00:00:00 2001 From: sys64738 Date: Tue, 28 Sep 2021 19:52:33 +0200 Subject: [PATCH] getting further. IR/DR shifting definitely works, TCLK handling probably broken --- CMakeLists.txt | 1 + src/main.c | 23 +++++++++++------------ src/pio_sbw.c | 13 +++++++------ src/pio_sbw.h | 1 + src/tap.c | 38 +++++++++++++++++++++++++++----------- src/tap.h | 2 ++ 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27efd79..79fde3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/pio_sbw.c ${CMAKE_CURRENT_SOURCE_DIR}/src/tap.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msp430dbg.c ) # Example include diff --git a/src/main.c b/src/main.c index 1ba5eb7..2e8978d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. - * - * SPDX-License-Identifier: BSD-3-Clause - */ #include @@ -12,6 +7,7 @@ #include "pio_sbw.h" #include "tap.h" +#include "msp430dbg.h" void printbuf(const uint8_t* buf, size_t size) { for (size_t i = 0; i < size; ++i) @@ -26,11 +22,11 @@ int main() { stdio_init_all(); - sbw_preinit(); + /*sbw_preinit(); printf("%s\n", "preinited"); bool s = sbw_init(); - printf("%s\n", s ? "inited" : "failure"); + printf("%s\n", s ? "inited" : "failure");*/ /*uint8_t tdi = 0x0f, tdo = 0; sbw_sequence(8, true, &tdi, &tdo); @@ -53,12 +49,15 @@ int main() { sbw_tclk_burst(16); printf("done.\n");*/ - sbw_tap_reset(); - sbw_check_fuse(); +// sbw_tap_reset(); +// sbw_check_fuse(); +// +// uint8_t id = sbw_tap_shift_ir(0xff/*IR_BYPASS*/); +// +// printf("JTAG ID=%02x\n", id); - uint8_t id = sbw_tap_shift_ir(0xff/*IR_BYPASS*/); - - printf("JTAG ID=%02x\n", id); + uint32_t initv = msp430_device_get(200e3); + printf("init -> %08lx\n", initv); return 0; } diff --git a/src/pio_sbw.c b/src/pio_sbw.c index 365f6f4..d95e72f 100644 --- a/src/pio_sbw.c +++ b/src/pio_sbw.c @@ -1,8 +1,3 @@ -/** - * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. - * - * SPDX-License-Identifier: BSD-3-Clause - */ #include #include @@ -88,7 +83,12 @@ bool sbw_init(void) { return false; } - sbw_pio_init(PINOUT_SBW_PIO, sbw_piosm, sbw_offset, 200e3, + // need to start at 50 kHz: fuse check needs TMS cycles with a low phase + // of at least 5us. 50 kHz is below the required time (the actual maximum + // frequency would be around 80 kHz), but the exact frequency doesn't + // matter much as we'll switch to a higher one once the check has been + // completed + sbw_pio_init(PINOUT_SBW_PIO, sbw_piosm, sbw_offset, 50e3, PINOUT_SBW_TCK, PINOUT_SBW_TDIO); last_tdi = last_tms = 0xff; @@ -133,6 +133,7 @@ static uint8_t bitswap(uint8_t in) { bool sbw_get_last_tms(void) { return last_tms; } bool sbw_get_last_tdi(void) { return last_tdi; } +bool sbw_get_last_tclk(void) { return last_tclk; } void sbw_sequence(uint32_t ncyc, bool tms, const uint8_t* tdi, uint8_t* tdo) { if (ncyc == 0) return; diff --git a/src/pio_sbw.h b/src/pio_sbw.h index 050bd83..36ce0a4 100644 --- a/src/pio_sbw.h +++ b/src/pio_sbw.h @@ -26,6 +26,7 @@ void sbw_set_freq(bool tclk, float freq); bool sbw_get_last_tms(void); bool sbw_get_last_tdi(void); +bool sbw_get_last_tclk(void); void sbw_sequence(uint32_t ncyc, bool tms, const uint8_t* tdi, uint8_t* tdo); void sbw_tms_sequence(uint32_t ncyc, bool tdi, const uint8_t* tms); diff --git a/src/tap.c b/src/tap.c index 6dd6139..42bf84d 100644 --- a/src/tap.c +++ b/src/tap.c @@ -1,4 +1,6 @@ +#include + #include "pio_sbw.h" #include "tap.h" @@ -33,17 +35,25 @@ static uint8_t bitswap(uint8_t in) { return (lut[in&0xf] << 4) | lut[in>>4]; } static inline uint16_t bitswap16(uint16_t in) { + //printf("bitswap in=%04x\n", in); return ((uint16_t)bitswap(in & 0xff) << 8) | bitswap(in >> 8); } +// IR in = OK +// IR out = OK +// DR out = OK +// DR in = BAD! + uint16_t sbw_tap_shift_dr(uint16_t newdr) { // DR content is MSB-first instead of LSB-first (IR is the latter) // except the PIO already does bitswaps, so we need to do it for the IR instead - newdr = /*bitswap16(*/newdr/*)*/; + newdr = bitswap16(newdr); // 100: run-test/idle -> select-dr-scan -> capture-dr -> shift-dr - const uint8_t tms_seq = 0x01; - sbw_tms_sequence(3, true, &tms_seq); + const uint8_t tms_seqa = 0x01; + const uint8_t tms_seqb = 0x01 >> 1; + sbw_tms_sequence(1, sbw_get_last_tclk(), &tms_seqa); + sbw_tms_sequence(2, true, &tms_seqb); // 15 data bits with TMS=0 // 1 data bit with TMS=1 (to exit1-dr) @@ -55,18 +65,22 @@ uint16_t sbw_tap_shift_dr(uint16_t newdr) { // TMS=1 (to update-dr) // TMS=0 (to run-test/idle) - const uint8_t tms_seq_2 = 0x01; - sbw_tms_sequence(2, true, &tms_seq_2); + const uint8_t tms_seq_2a = 0x01; + const uint8_t tms_seq_2b = 0x01 >> 1; + sbw_tms_sequence(1, true, &tms_seq_2a); + sbw_tms_sequence(1, sbw_get_last_tclk(), &tms_seq_2b); - return /*bitswap16(*/res/*)*/; + return bitswap16(res); } uint8_t sbw_tap_shift_ir(uint8_t newir) { - newir = bitswap(newir); + newir = /*bitswap(*/newir/*)*/; // 1100: run-test/idle -> select-dr-scan -> select-ir-scan -> capture-ir -> shift-ir - const uint8_t tms_seq = 0x03; - sbw_tms_sequence(4, true, &tms_seq); + const uint8_t tms_seqa = 0x03; + const uint8_t tms_seqb = 0x03 >> 1; + sbw_tms_sequence(1, sbw_get_last_tclk(), &tms_seqa); + sbw_tms_sequence(3, true, &tms_seqb); // 7 data bits with TMS=0 // 1 data bit with TMS=1 (to exit1-ir) @@ -77,8 +91,10 @@ uint8_t sbw_tap_shift_ir(uint8_t newir) { // TMS=1 (to update-ir) // TMS=0 (to run-test/idle) - const uint8_t tms_seq_2 = 0x01; - sbw_tms_sequence(2, true, &tms_seq_2); + const uint8_t tms_seq_2a = 0x01; + const uint8_t tms_seq_2b = 0x01 >> 1; + sbw_tms_sequence(1, true, &tms_seq_2a); + sbw_tms_sequence(1, sbw_get_last_tclk(), &tms_seq_2b); return bitswap(res); } diff --git a/src/tap.h b/src/tap.h index 4682b68..de5fa25 100644 --- a/src/tap.h +++ b/src/tap.h @@ -2,6 +2,8 @@ #ifndef SBW_TAP_H_ #define SBW_TAP_H_ +#include + // move to run-test/idle. typically this is done by sending a single TMS=0 // cycle, but the MSP430 has an extra JTAG fuse check that needs to be done void sbw_tap_reset(void);