Skip to content

Commit b36a611

Browse files
authored
Merge pull request vedderb#294 from RadinnAB/blackmagic
Blackmagic - Routed nRF reset & halt to cortexm functions
2 parents 66fb7ca + b01930d commit b36a611

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

blackmagic/bm_if.c

+10
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,16 @@ int bm_reboot(void) {
577577
return ret;
578578
}
579579

580+
/**
581+
* Halt target execution.
582+
*/
583+
void bm_halt_req(void) {
584+
if (cur_target) {
585+
target_print_en = false;
586+
target_halt_request(cur_target);
587+
}
588+
}
589+
580590
/**
581591
* Leave debug mode of NRF5x device. Will reduce the sleep power consumption
582592
* significantly.

blackmagic/bm_if.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int bm_erase_flash_all(void);
3131
int bm_write_flash(uint32_t addr, const void *data, uint32_t len);
3232
int bm_mem_read(uint32_t addr, void *data, uint32_t len);
3333
int bm_reboot(void);
34+
void bm_halt_req(void);
3435
void bm_leave_nrf_debug_mode(void);
3536
void bm_disconnect(void);
3637
void bm_change_swd_pins(stm32_gpio_t *swdio_port, int swdio_pin,

blackmagic/target/cortexm.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ static void cortexm_regs_read(target *t, void *data);
5252
static void cortexm_regs_write(target *t, const void *data);
5353
static uint32_t cortexm_pc_read(target *t);
5454

55-
static void cortexm_reset(target *t);
5655
static enum target_halt_reason cortexm_halt_poll(target *t, target_addr *watch);
57-
static void cortexm_halt_request(target *t);
5856
static int cortexm_fault_unwind(target *t);
5957

6058
static int cortexm_breakwatch_set(target *t, struct breakwatch *);
@@ -500,7 +498,7 @@ static void cortexm_pc_write(target *t, const uint32_t val)
500498

501499
/* The following three routines implement target halt/resume
502500
* using the core debug registers in the NVIC. */
503-
static void cortexm_reset(target *t)
501+
void cortexm_reset(target *t)
504502
{
505503
if ((t->target_options & CORTEXM_TOPT_INHIBIT_SRST) == 0) {
506504
platform_srst_set_val(true);
@@ -534,7 +532,7 @@ static void cortexm_reset(target *t)
534532
platform_delay(1);
535533
}
536534

537-
static void cortexm_halt_request(target *t)
535+
void cortexm_halt_request(target *t)
538536
{
539537
volatile struct exception e;
540538
TRY_CATCH (e, EXCEPTION_TIMEOUT) {

blackmagic/target/cortexm.h

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ ADIv5_AP_t *cortexm_ap(target *t);
173173

174174
bool cortexm_attach(target *t);
175175
void cortexm_detach(target *t);
176+
void cortexm_reset(target *t);
177+
void cortexm_halt_request(target *t);
176178
void cortexm_halt_resume(target *t, bool step);
177179
int cortexm_run_stub(target *t, uint32_t loadaddr,
178180
uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3);

blackmagic/target/nrf51.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,10 @@ void nrf51_mdm_probe(ADIv5_AP_t *ap)
403403
t->regs_size = 4;
404404
t->regs_read = (void*)nop_function;
405405
t->regs_write = (void*)nop_function;
406-
t->reset = (void*)nop_function;
407-
t->halt_request = (void*)nop_function;
406+
t->reset = cortexm_reset;
407+
t->halt_request = cortexm_halt_request;
408408
//t->halt_poll = mdm_halt_poll;
409-
t->halt_resume = (void*)nop_function;
409+
t->halt_resume = cortexm_halt_resume;
410410

411411
target_add_commands(t, nrf51_mdm_cmd_list, t->driver);
412412
}

commands.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
462462
} break;
463463

464464
case COMM_SET_MCCONF: {
465-
#ifndef HW_MCCONF_READ_ONLY
465+
#ifndef HW_MCCONF_READ_ONLY
466466
mc_configuration *mcconf = mempools_alloc_mcconf();
467467
*mcconf = *mc_interface_get_configuration();
468468

@@ -525,7 +525,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
525525
} break;
526526

527527
case COMM_SET_APPCONF: {
528-
#ifndef HW_APPCONF_READ_ONLY
528+
#ifndef HW_APPCONF_READ_ONLY
529529
app_configuration *appconf = mempools_alloc_appconf();
530530
*appconf = *app_get_configuration();
531531

@@ -1904,6 +1904,16 @@ static THD_FUNCTION(blocking_thread, arg) {
19041904
}
19051905
} break;
19061906

1907+
case COMM_BM_HALT_REQ: {
1908+
bm_halt_req();
1909+
1910+
int32_t ind = 0;
1911+
send_buffer[ind++] = packet_id;
1912+
if (send_func_blocking) {
1913+
send_func_blocking(send_buffer, ind);
1914+
}
1915+
} break;
1916+
19071917
case COMM_BM_DISCONNECT: {
19081918
bm_disconnect();
19091919
bm_leave_nrf_debug_mode();

datatypes.h

+1
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ typedef enum {
968968
COMM_BMS_FWD_CAN_RX,
969969
COMM_BMS_HW_DATA,
970970
COMM_GET_BATTERY_CUT,
971+
COMM_BM_HALT_REQ,
971972
} COMM_PACKET_ID;
972973

973974
// CAN commands

0 commit comments

Comments
 (0)