/* project specific includes */
#include <helper/binarybuffer.h>
#include <helper/bits.h>
+#include <helper/system.h>
#include <jtag/interface.h>
#include <jtag/hla/hla_layout.h>
#include <jtag/hla/hla_transport.h>
* Map the relevant features, quirks and workaround for specific firmware
* version of stlink
*/
-#define STLINK_F_HAS_TRACE BIT(0)
-#define STLINK_F_HAS_SWD_SET_FREQ BIT(1)
-#define STLINK_F_HAS_JTAG_SET_FREQ BIT(2)
-#define STLINK_F_HAS_MEM_16BIT BIT(3)
-#define STLINK_F_HAS_GETLASTRWSTATUS2 BIT(4)
-#define STLINK_F_HAS_DAP_REG BIT(5)
-#define STLINK_F_QUIRK_JTAG_DP_READ BIT(6)
-#define STLINK_F_HAS_AP_INIT BIT(7)
-#define STLINK_F_HAS_DPBANKSEL BIT(8)
-#define STLINK_F_HAS_RW8_512BYTES BIT(9)
-#define STLINK_F_FIX_CLOSE_AP BIT(10)
+#define STLINK_F_HAS_TRACE BIT(0) /* v2>=j13 || v3 */
+#define STLINK_F_HAS_SWD_SET_FREQ BIT(1) /* v2>=j22 */
+#define STLINK_F_HAS_JTAG_SET_FREQ BIT(2) /* v2>=j24 */
+#define STLINK_F_HAS_MEM_16BIT BIT(3) /* v2>=j26 || v3 */
+#define STLINK_F_HAS_GETLASTRWSTATUS2 BIT(4) /* v2>=j15 || v3 */
+#define STLINK_F_HAS_DAP_REG BIT(5) /* v2>=j24 || v3 */
+#define STLINK_F_QUIRK_JTAG_DP_READ BIT(6) /* v2>=j24 && v2<j32 */
+#define STLINK_F_HAS_AP_INIT BIT(7) /* v2>=j28 || v3 */
+#define STLINK_F_HAS_DPBANKSEL BIT(8) /* v2>=j32 || v3>=j2 */
+#define STLINK_F_HAS_RW8_512BYTES BIT(9) /* v3>=j6 */
+#define STLINK_F_FIX_CLOSE_AP BIT(10) /* v2>=j29 || v3 */
/* aliases */
#define STLINK_F_HAS_TARGET_VOLT STLINK_F_HAS_TRACE
return res;
size_t bytes_avail = le_to_h_u16(h->databuf);
- *size = bytes_avail < *size ? bytes_avail : *size - 1;
+ *size = bytes_avail < *size ? bytes_avail : *size;
if (*size > 0) {
res = stlink_usb_read_trace(handle, buf, *size);
* based on the length (0x1a = 26) we could easily decide if we have to fixup the serial
* and then we have just to convert the raw data into printable characters using sprintf
*/
-static char *stlink_usb_get_alternate_serial(libusb_device_handle *device,
+static char *stlink_usb_get_alternate_serial(struct libusb_device_handle *device,
struct libusb_device_descriptor *dev_desc)
{
int usb_retval;
{
struct stlink_usb_handle_s *h = handle;
- if (enabled && (!(h->version.flags & STLINK_F_HAS_TRACE) ||
- pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART)) {
+ if (!(h->version.flags & STLINK_F_HAS_TRACE)) {
+ LOG_ERROR("The attached ST-LINK version doesn't support trace");
+ return ERROR_FAIL;
+ }
+
+ if (!enabled) {
+ stlink_usb_trace_disable(h);
+ return ERROR_OK;
+ }
+
+ assert(trace_freq != NULL);
+ assert(prescaler != NULL);
+
+ if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
return ERROR_FAIL;
}
STLINK_V3_TRACE_MAX_HZ : STLINK_TRACE_MAX_HZ;
/* Only concern ourselves with the frequency if the STlink is processing it. */
- if (enabled && *trace_freq > max_trace_freq) {
+ if (*trace_freq > max_trace_freq) {
LOG_ERROR("ST-LINK doesn't support SWO frequency higher than %u",
max_trace_freq);
return ERROR_FAIL;
}
- stlink_usb_trace_disable(h);
-
if (!*trace_freq)
*trace_freq = max_trace_freq;
*prescaler = presc;
- if (!enabled)
- return ERROR_OK;
+ stlink_usb_trace_disable(h);
h->trace.source_hz = *trace_freq;