This commit is contained in:
Triss 2021-10-05 18:41:25 +02:00
parent e92afbcc06
commit b51e47810f
4 changed files with 99 additions and 50 deletions

View File

@ -78,7 +78,10 @@ void mehfet_hw_tclk_burst(uint32_t ncyc) {
sbw_tclk_burst(ncyc); sbw_tclk_burst(ncyc);
} }
void mehfet_hw_reset_tap(void) { enum mehfet_resettap_status mehfet_hw_reset_tap(enum mehfet_resettap_flags flags) {
enum mehfet_resettap_status rv = 0;
if (flags & mehfet_rsttap_do_reset) {
// TDI always 1 // TDI always 1
// TMS=1,1,1,1,1,1 -- reset TAP state to initial // TMS=1,1,1,1,1,1 -- reset TAP state to initial
// TMS=0 -- test-logic-reset to run-test/idle // TMS=0 -- test-logic-reset to run-test/idle
@ -88,6 +91,33 @@ void mehfet_hw_reset_tap(void) {
//const uint16_t tms_seq = 0x1abf;//0x3f | (0<<6) | (0x15 << 7) | (0x1 << 12); //const uint16_t tms_seq = 0x1abf;//0x3f | (0<<6) | (0x15 << 7) | (0x1 << 12);
const uint8_t tms_seq[2] = {0xbf,0x1a}; const uint8_t tms_seq[2] = {0xbf,0x1a};
sbw_tms_sequence(14, true, tms_seq); sbw_tms_sequence(14, true, tms_seq);
}
if (flags & mehfet_rsttap_fuse_do) {
// TDI always 1
// TMS=01010110 // same sequence as above, but without TAP reset
const uint8_t tms_seq = 0x6a;
sbw_tms_sequence(8, true, &tms_seq);
}
if (flags & mehfet_rsttap_fuse_read) {
for (size_t i = 0; i < 3; ++i) {
mehfet_hw_shift_ir(0x14); // CNTRL_SIG_CAPTURE
uint16_t dr = mehfet_hw_shift_dr16(0xaaaa);
if (dr == 0x5555) {
rv |= mehfet_rsttap_fuse_blown;
break;
}
}
}
if (flags & mehfet_rsttap_highspeed) {
sbw_set_freq(true, 350e3);
} else {
sbw_set_freq(false, 50e3);
}
return rv;
} }
uint8_t mehfet_hw_shift_ir(uint8_t newir) { uint8_t mehfet_hw_shift_ir(uint8_t newir) {

View File

@ -286,12 +286,12 @@ static void my_hid_set_report_cb(uint8_t instance, uint8_t report_id,
#if CFG_TUD_CDC > 0 #if CFG_TUD_CDC > 0
static void my_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding) { static void my_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* line_coding) {
switch (itf) { switch (itf) {
/*#ifdef DBOARD_HAS_UART #ifdef DBOARD_HAS_UART
case CDC_N_UART: case CDC_N_UART:
cdc_uart_set_coding(line_coding->bit_rate, line_coding->stop_bits, cdc_uart_set_coding(line_coding->bit_rate, line_coding->stop_bits,
line_coding->parity, line_coding->data_bits); line_coding->parity, line_coding->data_bits);
break; break;
#endif*/ #endif
#ifdef USE_USBCDC_FOR_STDIO #ifdef USE_USBCDC_FOR_STDIO
case CDC_N_STDIO: case CDC_N_STDIO:
stdio_usb_line_coding_cb(line_coding); stdio_usb_line_coding_cb(line_coding);

View File

@ -366,10 +366,10 @@ void mehfet_task(void) {
case mehfet_reset_tap: case mehfet_reset_tap:
if (!(mehfet_hw_get_caps() & mehfet_cap_has_reset_tap)) write_resp(mehfet_nocaps, 0, NULL); if (!(mehfet_hw_get_caps() & mehfet_cap_has_reset_tap)) write_resp(mehfet_nocaps, 0, NULL);
else if (cmdhdr.len != 0) write_resp_str(mehfet_badargs, "ResetTAP takes no parameters"); else if (cmdhdr.len != 1) write_resp_str(mehfet_badargs, "ResetTAP takes one parameter byte");
else { else {
mehfet_hw_reset_tap(); uint8_t v = mehfet_hw_reset_tap(read_pl());
write_resp(mehfet_ok, 0, NULL); write_resp(mehfet_ok, 1, &v);
} }
break; break;
case mehfet_irshift: case mehfet_irshift:

View File

@ -1,3 +1,4 @@
// vim: set et:
#ifndef M_ISP_MEHFET #ifndef M_ISP_MEHFET
#define M_ISP_MEHFET #define M_ISP_MEHFET
@ -62,6 +63,17 @@ enum mehfet_conn {
mehfet_conn_nrstmask = 0x80 mehfet_conn_nrstmask = 0x80
}; };
enum mehfet_resettap_flags {
mehfet_rsttap_do_reset = 1<<0, // reset TAP to run-test/idle state
mehfet_rsttap_fuse_do = 1<<1, // perform fuse check procedure (TMS pulses) on target
mehfet_rsttap_fuse_read = 1<<2, // check whether the JTAG fuse has been blown
mehfet_rsttap_highspeed = 1<<3, // can move to high-speed transport afterwards
// (fuse check procedure is max 50 kHz)
};
enum mehfet_resettap_status {
mehfet_rsttap_fuse_blown = 0x80
};
// hw routines // hw routines
void mehfet_hw_init(void); void mehfet_hw_init(void);
@ -86,10 +98,17 @@ void mehfet_hw_tms_seq(uint32_t ncyc, bool tdilvl, const uint8_t* tms);
void mehfet_hw_tclk_edge(bool newtclk); void mehfet_hw_tclk_edge(bool newtclk);
void mehfet_hw_tclk_burst(uint32_t ncyc); void mehfet_hw_tclk_burst(uint32_t ncyc);
void mehfet_hw_reset_tap(void); enum mehfet_resettap_status mehfet_hw_reset_tap(enum mehfet_resettap_flags flags);
uint8_t mehfet_hw_shift_ir(uint8_t newir); uint8_t mehfet_hw_shift_ir(uint8_t newir);
// drin is not const here, as the implementation may want to shuffle stuff around // drin is not const here, as the implementation may want to shuffle stuff around
void mehfet_hw_shift_dr(uint32_t nbits, uint8_t* drin, uint8_t* drout); void mehfet_hw_shift_dr(uint32_t nbits, uint8_t* drin, uint8_t* drout);
static inline uint16_t mehfet_hw_shift_dr16(uint16_t newdr) {
uint8_t drin[2], drout[2];
drin[0] = (uint8_t)newdr;
drin[1] = (uint8_t)(newdr >> 8);
mehfet_hw_shift_dr(16, drin, drout);
return drout[0] | ((uint16_t)drout[1] << 8);
}
#endif #endif