|
Lines 1565-1570
static int stlink_usb_exit_mode(void *handle)
Link Here
|
| 1565 |
return ERROR_OK; |
1565 |
return ERROR_OK; |
| 1566 |
} |
1566 |
} |
| 1567 |
|
1567 |
|
|
|
1568 |
static enum target_state stlink_usb_state(void *handle); |
| 1569 |
|
| 1568 |
/** */ |
1570 |
/** */ |
| 1569 |
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int initial_interface_speed) |
1571 |
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int initial_interface_speed) |
| 1570 |
{ |
1572 |
{ |
|
Lines 1621-1627
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init
Link Here
|
| 1621 |
if (emode == STLINK_MODE_DEBUG_JTAG) { |
1623 |
if (emode == STLINK_MODE_DEBUG_JTAG) { |
| 1622 |
if (h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ) { |
1624 |
if (h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ) { |
| 1623 |
stlink_dump_speed_map(stlink_khz_to_speed_map_jtag, ARRAY_SIZE(stlink_khz_to_speed_map_jtag)); |
1625 |
stlink_dump_speed_map(stlink_khz_to_speed_map_jtag, ARRAY_SIZE(stlink_khz_to_speed_map_jtag)); |
|
|
1626 |
//initial_interface_speed=9000; |
| 1627 |
LOG_DEBUG("set speed before %d", initial_interface_speed); |
| 1624 |
stlink_speed(h, initial_interface_speed, false); |
1628 |
stlink_speed(h, initial_interface_speed, false); |
|
|
1629 |
LOG_DEBUG("set speed after"); |
| 1625 |
} |
1630 |
} |
| 1626 |
} else if (emode == STLINK_MODE_DEBUG_SWD) { |
1631 |
} else if (emode == STLINK_MODE_DEBUG_SWD) { |
| 1627 |
if (h->version.flags & STLINK_F_HAS_SWD_SET_FREQ) { |
1632 |
if (h->version.flags & STLINK_F_HAS_SWD_SET_FREQ) { |
|
Lines 1638-1643
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init
Link Here
|
| 1638 |
stlink_speed(h, initial_interface_speed, false); |
1643 |
stlink_speed(h, initial_interface_speed, false); |
| 1639 |
} |
1644 |
} |
| 1640 |
|
1645 |
|
|
|
1646 |
LOG_DEBUG("after speed"); |
| 1647 |
//usleep(100000); |
| 1648 |
|
| 1649 |
//stlink_usb_state(handle); |
| 1650 |
LOG_DEBUG("after speed"); |
| 1651 |
|
| 1652 |
//connect_under_reset = true; |
| 1641 |
/* preliminary SRST assert: |
1653 |
/* preliminary SRST assert: |
| 1642 |
* We want SRST is asserted before activating debug signals (mode_enter). |
1654 |
* We want SRST is asserted before activating debug signals (mode_enter). |
| 1643 |
* As the required mode has not been set, the adapter may not know what pin to use. |
1655 |
* As the required mode has not been set, the adapter may not know what pin to use. |
|
Lines 1645-1659
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init
Link Here
|
| 1645 |
* Tested firmware STLINK v2 JTAG v27 API v2 SWIM v6 uses T_NRST pin by default |
1657 |
* Tested firmware STLINK v2 JTAG v27 API v2 SWIM v6 uses T_NRST pin by default |
| 1646 |
* after power on, SWIM_RST stays unchanged */ |
1658 |
* after power on, SWIM_RST stays unchanged */ |
| 1647 |
if (connect_under_reset && emode != STLINK_MODE_DEBUG_SWIM) |
1659 |
if (connect_under_reset && emode != STLINK_MODE_DEBUG_SWIM) |
|
|
1660 |
LOG_DEBUG("assert reset"); |
| 1648 |
stlink_usb_assert_srst(handle, 0); |
1661 |
stlink_usb_assert_srst(handle, 0); |
| 1649 |
/* do not check the return status here, we will |
1662 |
/* do not check the return status here, we will |
| 1650 |
proceed and enter the desired mode below |
1663 |
proceed and enter the desired mode below |
| 1651 |
and try asserting srst again. */ |
1664 |
and try asserting srst again. */ |
| 1652 |
|
1665 |
|
|
|
1666 |
LOG_DEBUG("before mode enter"); |
| 1653 |
res = stlink_usb_mode_enter(handle, emode); |
1667 |
res = stlink_usb_mode_enter(handle, emode); |
| 1654 |
if (res != ERROR_OK) |
1668 |
if (res != ERROR_OK) |
| 1655 |
return res; |
1669 |
return res; |
| 1656 |
|
1670 |
|
|
|
1671 |
LOG_DEBUG("after mode enter"); |
| 1672 |
|
| 1657 |
/* assert SRST again: a little bit late but now the adapter knows for sure what pin to use */ |
1673 |
/* assert SRST again: a little bit late but now the adapter knows for sure what pin to use */ |
| 1658 |
if (connect_under_reset) { |
1674 |
if (connect_under_reset) { |
| 1659 |
res = stlink_usb_assert_srst(handle, 0); |
1675 |
res = stlink_usb_assert_srst(handle, 0); |
|
Lines 1661-1666
static int stlink_usb_init_mode(void *handle, bool connect_under_reset, int init
Link Here
|
| 1661 |
return res; |
1677 |
return res; |
| 1662 |
} |
1678 |
} |
| 1663 |
|
1679 |
|
|
|
1680 |
LOG_DEBUG("check mode"); |
| 1664 |
res = stlink_usb_current_mode(handle, &mode); |
1681 |
res = stlink_usb_current_mode(handle, &mode); |
| 1665 |
|
1682 |
|
| 1666 |
if (res != ERROR_OK) |
1683 |
if (res != ERROR_OK) |
|
Lines 2137-2142
static int stlink_usb_reset(void *handle)
Link Here
|
| 2137 |
if (retval != ERROR_OK) |
2154 |
if (retval != ERROR_OK) |
| 2138 |
return retval; |
2155 |
return retval; |
| 2139 |
|
2156 |
|
|
|
2157 |
//usleep(10000); |
| 2158 |
|
| 2140 |
if (h->trace.enabled) { |
2159 |
if (h->trace.enabled) { |
| 2141 |
stlink_usb_trace_disable(h); |
2160 |
stlink_usb_trace_disable(h); |
| 2142 |
return stlink_usb_trace_enable(h); |
2161 |
return stlink_usb_trace_enable(h); |