Skip to content

Commit 5247797

Browse files
maxd-nordicrlubos
authored andcommitted
connectivity_bridge: add debug feature
This patch adds a cmsis-dap probe feature to the connectivity_bridge. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent dca8ce8 commit 5247797

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

applications/connectivity_bridge/boards/thingy91x_nrf5340_cpuapp.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ CONFIG_DK_LIBRARY=y
3838
# Bootloader firmware information
3939
CONFIG_FW_INFO=y
4040
CONFIG_SECURE_BOOT_STORAGE=y
41+
CONFIG_DAP=y
42+
CONFIG_DP_DRIVER=y
43+
44+
CONFIG_CMSIS_DAP_DEVICE_VENDOR="Nordic Semiconductor ASA"
45+
CONFIG_CMSIS_DAP_DEVICE_NAME="nrf91"

applications/connectivity_bridge/boards/thingy91x_nrf5340_cpuapp.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
clk-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
1313
dio-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>;
1414
reset-gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
15-
port-write-cycles = <2>;
15+
port-write-cycles = <12>;
1616
};
1717

1818
zephyr,user {

applications/connectivity_bridge/boards/thingy91x_nrf5340_cpuapp_readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This USB interface has the following functions:
66
* Disk drive containing this file and others
77
* COM ports for nRF91 debug, trace, and firmware update
8+
* CMSIS-DAP 2.1 compliant debug probe interface for accessing the nRF91 SiP
89

910
COM Ports
1011
====================

applications/connectivity_bridge/src/modules/usb_bulk_commands.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <bl_storage.h>
1313
#include <ncs_commit.h>
1414

15+
#include <cmsis_dap.h>
16+
1517
#include <zephyr/logging/log.h>
1618
LOG_MODULE_REGISTER(bulk_commands, CONFIG_BRIDGE_BULK_LOG_LEVEL);
1719

@@ -100,12 +102,17 @@ static void nrf53_reset_work_handler(struct k_work *work)
100102
/* This is a placeholder implementation until proper CMSIS-DAP support is available.
101103
* Only custom vendor commands are supported.
102104
*/
103-
size_t dap_execute_cmd(uint8_t *in, uint8_t *out)
105+
size_t dap_execute_vendor_cmd(uint8_t *in, uint8_t *out)
104106
{
105107
LOG_DBG("got command 0x%02X", in[0]);
106-
int ret;
108+
109+
if (in[0] < ID_DAP_VENDOR0) {
110+
return dap_execute_cmd(in, out);
111+
}
107112

108113
#if IS_ENABLED(CONFIG_RETENTION_BOOT_MODE)
114+
int ret;
115+
109116
if (in[0] == ID_DAP_VENDOR_NRF53_BOOTLOADER) {
110117
ret = bootmode_set(BOOT_MODE_TYPE_BOOTLOADER);
111118
if (ret) {

applications/connectivity_bridge/src/modules/usb_bulk_interface.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_BRIDGE_BULK_LOG_LEVEL);
2323
/* needs to be included after defining logging config */
2424
#include "usb_bulk_msosv2.h"
2525

26+
#include <cmsis_dap.h>
27+
2628
#define USB_BULK_PACKET_SIZE 64
2729
#define USB_BULK_PACKET_COUNT 4
2830

@@ -41,7 +43,7 @@ static K_FIFO_DEFINE(dap_rx_queue);
4143
NET_BUF_POOL_FIXED_DEFINE(dapusb_rx_pool, USB_BULK_PACKET_COUNT, USB_BULK_PACKET_SIZE, 0, NULL);
4244

4345
/* Execute CMSIS-DAP command and write reply into output buffer */
44-
size_t dap_execute_cmd(uint8_t *in, uint8_t *out);
46+
size_t dap_execute_vendor_cmd(uint8_t *in, uint8_t *out);
4547

4648
/* string descriptor for the interface */
4749
#define DAP_IFACE_STR_DESC "CMSIS-DAP v2"
@@ -172,7 +174,7 @@ static int dap_usb_process(void)
172174
struct net_buf *buf = k_fifo_get(&dap_rx_queue, K_FOREVER);
173175
uint8_t ep = dapusb_config.endpoint[DAP_USB_EP_IN_IDX].ep_addr;
174176

175-
len = dap_execute_cmd(buf->data, tx_buf);
177+
len = dap_execute_vendor_cmd(buf->data, tx_buf);
176178
LOG_DBG("response length %u, starting with [0x%02X, 0x%02X]", len, tx_buf[0], tx_buf[1]);
177179
net_buf_unref(buf);
178180

@@ -196,6 +198,8 @@ static int dap_usb_thread_fn(const struct device *dev)
196198
return 0;
197199
}
198200

201+
const struct device *const swd_dev = DEVICE_DT_GET_ONE(zephyr_swdp_gpio);
202+
199203
K_THREAD_DEFINE(dap_usb_thread,
200204
CONFIG_BULK_USB_THREAD_STACK_SIZE, dap_usb_thread_fn, NULL, NULL, NULL, 5, 0, 0);
201205

@@ -208,11 +212,21 @@ static bool app_event_handler(const struct app_event_header *aeh)
208212
/* tell the rest of the system that we are busy. */
209213
module_set_state(MODULE_STATE_READY);
210214

211-
/* Add MS OS 2.0 BOS descriptor to BOS structure */
215+
/* add MS OS 2.0 BOS descriptor to BOS structure. */
212216
usb_bos_register_cap((void *)&bos_cap_msosv2);
213-
/* Point interface index to string descriptor */
217+
/* point interface index to string descriptor. */
214218
iface_string_desc_init(&dapusb_config);
215219

220+
if (!device_is_ready(swd_dev)) {
221+
LOG_ERR("SWD device is not ready");
222+
}
223+
224+
int ret = dap_setup(swd_dev);
225+
226+
if (ret) {
227+
LOG_ERR("Failed to initialize DAP controller, %d", ret);
228+
}
229+
216230
/* tell the usb_cdc_handler we are done. */
217231
module_set_state(MODULE_STATE_STANDBY);
218232
}

0 commit comments

Comments
 (0)