@@ -409,6 +409,7 @@ struct esp_apptrace_cmd_data {
409
409
uint32_t poll_period ;
410
410
uint32_t sv_acc_time_delta ;
411
411
int sv_last_core_id ;
412
+ int sv_trace_running ;
412
413
uint32_t max_len ;
413
414
uint32_t skip_len ;
414
415
bool wait4halt ;
@@ -1311,6 +1312,7 @@ static int esp_sysview_start(struct esp_apptrace_cmd_ctx *ctx)
1311
1312
uint8_t cmds [] = {SEGGER_SYSVIEW_COMMAND_ID_START };
1312
1313
uint32_t fired_target_num = 0 ;
1313
1314
struct esp108_apptrace_target_state target_state [ESP_APPTRACE_TARGETS_NUM_MAX ];
1315
+ struct esp_apptrace_cmd_data * cmd_data = (struct esp_apptrace_cmd_data * )ctx -> cmd_priv ;
1314
1316
1315
1317
// get current block id
1316
1318
int res = esp_apptrace_get_data_info (ctx , target_state , & fired_target_num );
@@ -1330,16 +1332,17 @@ static int esp_sysview_start(struct esp_apptrace_cmd_ctx *ctx)
1330
1332
LOG_ERROR ("SEGGER: Failed to start tracing!" );
1331
1333
return res ;
1332
1334
}
1335
+ cmd_data -> sv_trace_running = 1 ;
1333
1336
return res ;
1334
1337
}
1335
1338
1336
1339
static int esp_sysview_stop (struct esp_apptrace_cmd_ctx * ctx )
1337
1340
{
1338
1341
uint32_t old_block_id , fired_target_num = 0 , empty_target_num = 0 ;
1339
1342
struct esp108_apptrace_target_state target_state [ESP_APPTRACE_TARGETS_NUM_MAX ];
1343
+ struct esp_apptrace_cmd_data * cmd_data = (struct esp_apptrace_cmd_data * )ctx -> cmd_priv ;
1340
1344
uint8_t cmds [] = {SEGGER_SYSVIEW_COMMAND_ID_STOP };
1341
1345
struct duration wait_time ;
1342
- int last_blocks_num = 0 ;
1343
1346
1344
1347
struct esp_apptrace_block * block = esp_apptrace_free_block_get (ctx );
1345
1348
if (!block ) {
@@ -1358,8 +1361,6 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
1358
1361
// in this case block_ids on both CPUs are equal, so the first one will be selected
1359
1362
for (int k = 0 ; k < ctx -> cores_num ; k ++ ) {
1360
1363
if (target_state [k ].data_len ) {
1361
- // data_len = target_state[k].data_len;
1362
- // block_id = target_state[k].block_id;
1363
1364
fired_target_num = k ;
1364
1365
break ;
1365
1366
}
@@ -1400,21 +1401,20 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
1400
1401
}
1401
1402
// resume targets to allow command processing
1402
1403
LOG_INFO ("Resume targets" );
1403
- for (int k = 0 ; k < ctx -> cores_num ; k ++ ) {
1404
- if (!ctx -> esp32_target ) {
1405
- res = target_resume (ctx -> cpus [k ], 1 , 0 , 1 , 0 );
1406
- if (res != ERROR_OK ) {
1407
- LOG_ERROR ("SEGGER: Failed to resume target '%s' (%d)!" , target_name (ctx -> cpus [k ]), res );
1408
- return res ;
1409
- }
1410
- }
1411
- }
1412
1404
if (ctx -> esp32_target ) {
1413
1405
res = target_resume (ctx -> esp32_target , 1 , 0 , 1 , 0 );
1414
1406
if (res != ERROR_OK ) {
1415
1407
LOG_ERROR ("SEGGER: Failed to resume target '%s' (%d)!" , target_name (ctx -> esp32_target ), res );
1416
1408
return res ;
1417
1409
}
1410
+ } else {
1411
+ for (int k = 0 ; k < ctx -> cores_num ; k ++ ) {
1412
+ res = target_resume (ctx -> cpus [k ], 1 , 0 , 1 , 0 );
1413
+ if (res != ERROR_OK ) {
1414
+ LOG_ERROR ("SEGGER: Failed to resume target '%s' (%d)!" , target_name (ctx -> cpus [k ]), res );
1415
+ return res ;
1416
+ }
1417
+ }
1418
1418
}
1419
1419
// wait for block switch (command sent), so we can disconnect from targets
1420
1420
old_block_id = target_state [fired_target_num ].block_id ;
@@ -1423,8 +1423,8 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
1423
1423
return ERROR_FAIL ;
1424
1424
}
1425
1425
// we are waiting for the last data from TRAX block and also there can be data in the pended data buffer
1426
- // so we are expectign two TRX block switches at most or stopping due to timeout
1427
- while (last_blocks_num < 2 ) {
1426
+ // so we are expecting two TRX block switches at most or stopping due to timeout
1427
+ while (cmd_data -> sv_trace_running ) {
1428
1428
res = esp_apptrace_get_data_info (ctx , target_state , & fired_target_num );
1429
1429
if (res != ERROR_OK ) {
1430
1430
LOG_ERROR ("SEGGER: Failed to read targets data info!" );
@@ -1463,14 +1463,13 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
1463
1463
}
1464
1464
}
1465
1465
old_block_id = target_state [fired_target_num ].block_id ;
1466
- last_blocks_num ++ ;
1467
1466
}
1468
1467
}
1469
1468
if (duration_measure (& wait_time ) != 0 ) {
1470
1469
LOG_ERROR ("Failed to start trace stop timeout measurement!" );
1471
1470
return ERROR_FAIL ;
1472
1471
}
1473
- if (duration_elapsed (& wait_time ) >= 0.1 ) {
1472
+ if (duration_elapsed (& wait_time ) >= 0.5 ) {
1474
1473
LOG_INFO ("Stop waiting for the last data due to timeout." );
1475
1474
break ;
1476
1475
}
@@ -1845,6 +1844,9 @@ static int esp_sysview_process_data(struct esp_apptrace_cmd_ctx *ctx, int core_i
1845
1844
break ;
1846
1845
}
1847
1846
}
1847
+ if (event_id == SYSVIEW_EVTID_TRACE_STOP ) {
1848
+ cmd_data -> sv_trace_running = 0 ;
1849
+ }
1848
1850
ctx -> tot_len += pkt_len ;
1849
1851
processed += pkt_len ;
1850
1852
}
0 commit comments