semihosting: remove comparison with NULL
[openocd.git] / src / target / arm_tpiu_swo.c
index fba3fec4f25be74112b0e3438d14626a9d237870..a9f558e12406758f445d18ce1a122b865e87b92b 100644 (file)
@@ -90,6 +90,7 @@ struct arm_tpiu_swo_event_action {
 struct arm_tpiu_swo_object {
        struct list_head lh;
        struct adiv5_mem_ap_spot spot;
+       struct adiv5_ap *ap;
        char *name;
        struct arm_tpiu_swo_event_action *event_action;
        /* record enable before init */
@@ -233,6 +234,9 @@ int arm_tpiu_swo_cleanup_all(void)
                        ea = next;
                }
 
+               if (obj->ap)
+                       dap_put_ap(obj->ap);
+
                free(obj->name);
                free(obj->out_filename);
                free(obj);
@@ -596,7 +600,6 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const
        struct command *c = jim_to_command(interp);
        struct arm_tpiu_swo_object *obj = c->jim_handler_data;
        struct command_context *cmd_ctx = current_command_context(interp);
-       struct adiv5_ap *tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num);
        uint32_t value;
        int retval;
 
@@ -614,8 +617,8 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const
        if (obj->enabled)
                return JIM_OK;
 
-       if (transport_is_hla() && obj->spot.ap_num > 0) {
-               LOG_ERROR("Invalid access port %d. Only AP#0 allowed with hla transport", obj->spot.ap_num);
+       if (transport_is_hla() && obj->spot.ap_num != 0) {
+               LOG_ERROR("Invalid access port 0x%" PRIx64 ". Only AP#0 allowed with hla transport", obj->spot.ap_num);
                return JIM_ERR;
        }
 
@@ -644,21 +647,28 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const
                struct cortex_m_common *cm = target_to_cm(target);
                obj->recheck_ap_cur_target = false;
                obj->spot.ap_num = cm->armv7m.debug_ap->ap_num;
-               tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num);
                if (obj->spot.ap_num == 0)
                        LOG_INFO(MSG "Confirmed TPIU %s is on AP 0", obj->name);
                else
-                       LOG_INFO(MSG "Target %s is on AP %d. Revised command is "
-                               "\'tpiu create %s -dap %s -ap-num %d\'",
+                       LOG_INFO(MSG "Target %s is on AP#0x%" PRIx64 ". Revised command is "
+                               "\'tpiu create %s -dap %s -ap-num 0x%" PRIx64 "\'",
                                target_name(target), obj->spot.ap_num,
                                obj->name, adiv5_dap_name(obj->spot.dap), obj->spot.ap_num);
        }
        /* END_DEPRECATED_TPIU */
 
+       if (!obj->ap) {
+               obj->ap = dap_get_ap(obj->spot.dap, obj->spot.ap_num);
+               if (!obj->ap) {
+                       LOG_ERROR("Cannot get AP");
+                       return JIM_ERR;
+               }
+       }
+
        /* trigger the event before any attempt to R/W in the TPIU/SWO */
        arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_ENABLE);
 
-       retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_DEVID_OFFSET, &value);
+       retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_DEVID_OFFSET, &value);
        if (retval != ERROR_OK) {
                LOG_ERROR("Unable to read %s", obj->name);
                return JIM_ERR;
@@ -684,7 +694,7 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const
        }
 
        if (obj->pin_protocol == TPIU_SPPR_PROTOCOL_SYNC) {
-               retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_SSPSR_OFFSET, &value);
+               retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_SSPSR_OFFSET, &value);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Cannot read TPIU register SSPSR");
                        return JIM_ERR;
@@ -759,26 +769,26 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const
                obj->swo_pin_freq = swo_pin_freq;
        }
 
-       retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_CSPSR_OFFSET, BIT(obj->port_width - 1));
+       retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_CSPSR_OFFSET, BIT(obj->port_width - 1));
        if (retval != ERROR_OK)
                goto error_exit;
 
-       retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_ACPR_OFFSET, prescaler - 1);
+       retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_ACPR_OFFSET, prescaler - 1);
        if (retval != ERROR_OK)
                goto error_exit;
 
-       retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_SPPR_OFFSET, obj->pin_protocol);
+       retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_SPPR_OFFSET, obj->pin_protocol);
        if (retval != ERROR_OK)
                goto error_exit;
 
-       retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_FFCR_OFFSET, &value);
+       retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_FFCR_OFFSET, &value);
        if (retval != ERROR_OK)
                goto error_exit;
        if (obj->en_formatter)
                value |= BIT(1);
        else
                value &= ~BIT(1);
-       retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_FFCR_OFFSET, value);
+       retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_FFCR_OFFSET, value);
        if (retval != ERROR_OK)
                goto error_exit;
 
@@ -1037,7 +1047,7 @@ COMMAND_HANDLER(handle_tpiu_deprecated_config_command)
                struct cortex_m_common *cm = target_to_cm(target);
                struct adiv5_private_config *pc = target->private_config;
                struct adiv5_dap *dap = pc->dap;
-               int ap_num = pc->ap_num;
+               uint64_t ap_num = pc->ap_num;
                bool set_recheck_ap_cur_target = false;
 
                LOG_INFO(MSG "Adding a TPIU \'%s.tpiu\' in the configuration", target_name(target));
@@ -1055,10 +1065,10 @@ COMMAND_HANDLER(handle_tpiu_deprecated_config_command)
                        set_recheck_ap_cur_target = true;
                }
 
-               LOG_INFO(MSG "Running: \'tpiu create %s.tpiu -dap %s -ap-num %d\'",
+               LOG_INFO(MSG "Running: \'tpiu create %s.tpiu -dap %s -ap-num 0x%" PRIx64 "\'",
                        target_name(target), adiv5_dap_name(dap), ap_num);
 
-               retval = command_run_linef(CMD_CTX, "tpiu create %s.tpiu -dap %s -ap-num %d",
+               retval = command_run_linef(CMD_CTX, "tpiu create %s.tpiu -dap %s -ap-num 0x%" PRIx64,
                        target_name(target), adiv5_dap_name(dap), ap_num);
                if (retval != ERROR_OK)
                        return retval;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)