Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxd-nordic committed Aug 30, 2023
1 parent 338a308 commit c22584c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 71 deletions.
37 changes: 12 additions & 25 deletions drivers/dp/swdp_bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,14 @@ struct sw_config {
void *dout_reg;
void *din_reg;
void *dnoe_reg;
uint32_t dout_port;
uint32_t din_port;
uint32_t dnoe_port;
#else
struct gpio_dt_spec dio;
void *dio_reg;
uint32_t dio_port;
#endif /* defined(CONFIG_SWDP_BITBANG_DRIVER_SEPARATE_IN_OUT) */
struct gpio_dt_spec noe;
struct gpio_dt_spec reset;
uint32_t port_write_cycles;
void *clk_reg;
uint32_t clk_port;
};

struct sw_cfg_data {
Expand Down Expand Up @@ -109,7 +104,7 @@ static ALWAYS_INLINE void pin_swclk_set(const struct device *dev)
const struct sw_config *config = dev->config;

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_set(config->clk_reg, config->clk_port, config->clk.pin);
swdp_ll_pin_set(config->clk_reg, config->clk.pin);
} else {
gpio_pin_set_dt(&config->clk, 1);
}
Expand All @@ -121,7 +116,7 @@ static ALWAYS_INLINE void pin_swclk_clr(const struct device *dev)
const struct sw_config *config = dev->config;

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_clr(config->clk_reg, config->clk_port, config->clk.pin);
swdp_ll_pin_clr(config->clk_reg, config->clk.pin);
} else {
gpio_pin_set_dt(&config->clk, 0);
}
Expand All @@ -134,15 +129,15 @@ static ALWAYS_INLINE void pin_swdio_set(const struct device *dev)
#if defined(CONFIG_SWDP_BITBANG_DRIVER_SEPARATE_IN_OUT)

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_set(config->dout_reg, config->dout_port, config->dout.pin);
swdp_ll_pin_set(config->dout_reg, config->dout.pin);
} else {
gpio_pin_set_dt(&config->dout, 1);
}

#else

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_set(config->dio_reg, config->dio_port, config->dio.pin);
swdp_ll_pin_set(config->dio_reg, config->dio.pin);
} else {
gpio_pin_set_dt(&config->dio, 1);
}
Expand All @@ -157,15 +152,15 @@ static ALWAYS_INLINE void pin_swdio_clr(const struct device *dev)
#if defined(CONFIG_SWDP_BITBANG_DRIVER_SEPARATE_IN_OUT)

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_clr(config->dout_reg, config->dout_port, config->dout.pin);
swdp_ll_pin_clr(config->dout_reg, config->dout.pin);
} else {
gpio_pin_set_dt(&config->dout, 0);
}

#else

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_clr(config->dio_reg, config->dio_port, config->dio.pin);
swdp_ll_pin_clr(config->dio_reg, config->dio.pin);
} else {
gpio_pin_set_dt(&config->dio, 0);
}
Expand All @@ -191,15 +186,15 @@ static ALWAYS_INLINE uint32_t pin_swdio_in(const struct device *dev)
#if defined(CONFIG_SWDP_BITBANG_DRIVER_SEPARATE_IN_OUT)

if (FAST_BITBANG_HW_SUPPORT) {
return swdp_ll_pin_get(config->din_reg, config->din_port, config->din.pin);
return swdp_ll_pin_get(config->din_reg, config->din.pin);
} else {
return gpio_pin_get_dt(&config->din);
}

#else

if (FAST_BITBANG_HW_SUPPORT) {
return swdp_ll_pin_get(config->dio_reg, config->dio_port, config->dio.pin);
return swdp_ll_pin_get(config->dio_reg, config->dio.pin);
} else {
return gpio_pin_get_dt(&config->dio);
}
Expand All @@ -218,15 +213,15 @@ static ALWAYS_INLINE void pin_swdio_out_enable(const struct device *dev)
#if defined(CONFIG_SWDP_BITBANG_DRIVER_SEPARATE_IN_OUT)

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_set(config->dnoe_reg, config->dnoe_port, config->dnoe.pin);
swdp_ll_pin_set(config->dnoe_reg, config->dnoe.pin);
} else {
gpio_pin_set_dt(&config->dnoe, 1);
}

#else

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_output(config->dio_reg, config->dio_port, config->dio.pin);
swdp_ll_pin_output(config->dio_reg, config->dio.pin);
} else {
gpio_pin_configure_dt(&config->dio, GPIO_OUTPUT_ACTIVE);
}
Expand All @@ -245,7 +240,7 @@ static ALWAYS_INLINE void pin_swdio_out_disable(const struct device *dev)
const struct gpio_dt_spec *dt_spec = &config->dnoe;

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_clr(config->dnoe_reg, config->dnoe_port, dt_spec->pin);
swdp_ll_pin_clr(config->dnoe_reg, dt_spec->pin);
} else {
gpio_pin_set_dt(dt_spec, 0);
}
Expand All @@ -254,7 +249,7 @@ static ALWAYS_INLINE void pin_swdio_out_disable(const struct device *dev)
const struct gpio_dt_spec *dt_spec = &config->dio;

if (FAST_BITBANG_HW_SUPPORT) {
swdp_ll_pin_input(config->dio_reg, config->dio_port, dt_spec->pin);
swdp_ll_pin_input(config->dio_reg, dt_spec->pin);
} else {
gpio_pin_configure_dt(dt_spec, GPIO_INPUT);
}
Expand Down Expand Up @@ -728,9 +723,6 @@ static struct swdp_api swdp_bitbang_api = {
#define SW_GPIOS_GET_REG(n, gpios) \
INT_TO_POINTER(DT_REG_ADDR(DT_PHANDLE(DT_DRV_INST(n), gpios)))

#define SW_GPIOS_GET_PORT(n, gpios) \
DT_PROP_OR(DT_PHANDLE(DT_DRV_INST(n), gpios), port, 0)

#define SW_DEVICE_DEFINE(n) \
static const struct sw_config sw_cfg_##n = { \
.clk = GPIO_DT_SPEC_INST_GET(n, clk_gpios), \
Expand All @@ -742,20 +734,15 @@ static struct swdp_api swdp_bitbang_api = {
.dout_reg = SW_GPIOS_GET_REG(n, dout_gpios), \
.din_reg = SW_GPIOS_GET_REG(n, din_gpios), \
.dnoe_reg = SW_GPIOS_GET_REG(n, dnoe_gpios), \
.dout_port = SW_GPIOS_GET_PORT(n, dout_gpios), \
.din_port = SW_GPIOS_GET_PORT(n, din_gpios), \
.dnoe_port = SW_GPIOS_GET_PORT(n, dnoe_gpios), \
), \
( \
.dio = GPIO_DT_SPEC_INST_GET(n, dio_gpios), \
.dio_reg = SW_GPIOS_GET_REG(n, dio_gpios), \
.dio_port = SW_GPIOS_GET_PORT(n, dio_gpios), \
)) \
.noe = GPIO_DT_SPEC_INST_GET_OR(n, noe_gpios, {0}), \
.reset = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {0}), \
.port_write_cycles = DT_INST_PROP(n, port_write_cycles), \
.clk_reg = SW_GPIOS_GET_REG(n, clk_gpios), \
.clk_port = SW_GPIOS_GET_PORT(n, clk_gpios) \
}; \
\
static struct sw_cfg_data sw_data_##n; \
Expand Down
32 changes: 6 additions & 26 deletions drivers/dp/swdp_ll_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#endif

#if defined(CONFIG_SOC_SERIES_NRF52X) \
|| defined(CONFIG_SOC_SERIES_NRF53X) \
|| defined(CONFIG_SOC_FAMILY_LPC)
|| defined(CONFIG_SOC_SERIES_NRF53X)
#define FAST_BITBANG_HW_SUPPORT 1
#else
#define FAST_BITBANG_HW_SUPPORT 0
Expand All @@ -37,68 +36,49 @@ static ALWAYS_INLINE void pin_delay_asm(uint32_t delay)

#if FAST_BITBANG_HW_SUPPORT

static ALWAYS_INLINE void swdp_ll_pin_input(void *const base, uint32_t port, uint8_t pin)
static ALWAYS_INLINE void swdp_ll_pin_input(void *const base, uint8_t pin)
{
#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X)
NRF_GPIO_Type * reg = base;

reg->PIN_CNF[pin] = 0b0000;
#elif defined(CONFIG_SOC_FAMILY_LPC)
GPIO_Type *gpio_base = base;
gpio_base->DIRCLR[port] = BIT(pin);
#endif
}

static ALWAYS_INLINE void swdp_ll_pin_output(void *const base, uint32_t port, uint8_t pin)
static ALWAYS_INLINE void swdp_ll_pin_output(void *const base, uint8_t pin)
{
#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X)
NRF_GPIO_Type * reg = base;

reg->PIN_CNF[pin] = 0b0001;
#elif defined(CONFIG_SOC_FAMILY_LPC)
GPIO_Type *gpio_base = base;

gpio_base->DIRSET[port] = BIT(pin);
#endif
}


static ALWAYS_INLINE void swdp_ll_pin_set(void *const base, uint32_t port, uint8_t pin)
static ALWAYS_INLINE void swdp_ll_pin_set(void *const base, uint8_t pin)
{
#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X)
NRF_GPIO_Type * reg = base;

reg->OUTSET = BIT(pin);
#elif defined(CONFIG_SOC_FAMILY_LPC)
GPIO_Type *gpio_base = base;

gpio_base->SET[port] = BIT(pin);
#endif
}

static ALWAYS_INLINE void swdp_ll_pin_clr(void *const base, uint32_t port, uint8_t pin)
static ALWAYS_INLINE void swdp_ll_pin_clr(void *const base, uint8_t pin)
{
#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X)
NRF_GPIO_Type * reg = base;

reg->OUTCLR = BIT(pin);
#elif defined(CONFIG_SOC_FAMILY_LPC)
GPIO_Type *gpio_base = base;

gpio_base->CLR[port] = BIT(pin);
#endif
}

static ALWAYS_INLINE uint32_t swdp_ll_pin_get(void *const base, uint32_t port, uint8_t pin)
static ALWAYS_INLINE uint32_t swdp_ll_pin_get(void *const base, uint8_t pin)
{
#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X)
NRF_GPIO_Type * reg = base;

return ((reg->IN >> pin) & 1);
#elif defined(CONFIG_SOC_FAMILY_LPC)
GPIO_Type *gpio_base = base;

return ((gpio_base->PIN[port] >> pin) & 1);
#endif
}

Expand Down
15 changes: 9 additions & 6 deletions samples/subsys/dap/src/cmsis_dap_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "cmsis_dap_usb.h"

#define DAP_USB_EP_IN 0x81
#define DAP_USB_EP_OUT 0x01

uint8_t rx_buf[CONFIG_CMSIS_DAP_PACKET_SIZE];
uint8_t tx_buf[CONFIG_CMSIS_DAP_PACKET_SIZE];

Expand Down Expand Up @@ -40,7 +43,7 @@ LOG_MODULE_REGISTER(cmsis_dap);
#define COMPATIBLE_ID_WINUSB \
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00

static struct msosv2_descriptor_t {
static struct msosv2_descriptor {
struct msosv2_descriptor_set_header header;
#if defined(CONFIG_USB_COMPOSITE_DEVICE)
struct msosv2_function_subset_header cmsis_dap_v2_subset_header;
Expand All @@ -55,7 +58,7 @@ static struct msosv2_descriptor_t {
.wLength = sizeof(struct msosv2_descriptor_set_header),
.wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR,
.dwWindowsVersion = 0x06030000,
.wTotalLength = sizeof(struct msosv2_descriptor_t),
.wTotalLength = sizeof(struct msosv2_descriptor),
},
#if defined(CONFIG_USB_COMPOSITE_DEVICE)
.cmsis_dap_v2_subset_header = {
Expand Down Expand Up @@ -245,21 +248,21 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct {
struct usb_ep_descriptor if0_in_ep;
} __packed dapusb_desc = {
.if0 = INITIALIZER_IF(2, USB_BCC_VENDOR),
.if0_out_ep = INITIALIZER_IF_EP(AUTO_EP_OUT, USB_DC_EP_BULK,
.if0_out_ep = INITIALIZER_IF_EP(DAP_USB_EP_OUT, USB_DC_EP_BULK,
CONFIG_CMSIS_DAP_PACKET_SIZE, 0),
.if0_in_ep = INITIALIZER_IF_EP(AUTO_EP_IN, USB_DC_EP_BULK,
.if0_in_ep = INITIALIZER_IF_EP(DAP_USB_EP_IN, USB_DC_EP_BULK,
CONFIG_CMSIS_DAP_PACKET_SIZE, 0),
};

/* Describe EndPoints configuration */
static struct usb_ep_cfg_data dapusb_ep_data[] = {
{
.ep_cb = usb_transfer_ep_callback,
.ep_addr = AUTO_EP_OUT
.ep_addr = DAP_USB_EP_OUT
},
{
.ep_cb = usb_transfer_ep_callback,
.ep_addr = AUTO_EP_IN
.ep_addr = DAP_USB_EP_IN
}
};

Expand Down
34 changes: 20 additions & 14 deletions subsys/dap/cmsis_dap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ static uint16_t dap_info(struct dap_context *const ctx,
switch (id) {
case DAP_ID_VENDOR:
LOG_DBG("ID_VENDOR");
memcpy(info, CONFIG_CMSIS_DAP_PROBE_VENDOR, sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR);
memcpy(info, CONFIG_CMSIS_DAP_PROBE_VENDOR,
sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR));
length = sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR);
break;
case DAP_ID_PRODUCT:
LOG_DBG("ID_PRODUCT");
memcpy(info, CONFIG_CMSIS_DAP_PROBE_NAME, sizeof(CONFIG_CMSIS_DAP_PROBE_NAME));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_PROBE_NAME);
memcpy(info, CONFIG_CMSIS_DAP_PROBE_NAME,
sizeof(CONFIG_CMSIS_DAP_PROBE_NAME));
length = sizeof(CONFIG_CMSIS_DAP_PROBE_NAME);
break;
case DAP_ID_SER_NUM:
/* optional to implement */
Expand All @@ -93,26 +95,30 @@ static uint16_t dap_info(struct dap_context *const ctx,
case DAP_ID_FW_VER:
LOG_DBG("ID_FW_VER");
memcpy(info, DAP_FW_VER, sizeof(DAP_FW_VER));
length = (uint8_t)sizeof(DAP_FW_VER);
length = sizeof(DAP_FW_VER);
break;
case DAP_ID_DEVICE_VENDOR:
LOG_DBG("ID_DEVICE_VENDOR");
memcpy(info, CONFIG_CMSIS_DAP_DEVICE_VENDOR, sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR);
memcpy(info, CONFIG_CMSIS_DAP_DEVICE_VENDOR,
sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR));
length = sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR);
break;
case DAP_ID_DEVICE_NAME:
LOG_DBG("ID_DEVICE_NAME");
memcpy(info, CONFIG_CMSIS_DAP_DEVICE_NAME, sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME);
memcpy(info, CONFIG_CMSIS_DAP_DEVICE_NAME,
sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME));
length = sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME);
break;
case DAP_ID_BOARD_VENDOR:
LOG_DBG("ID_BOARD_VENDOR");
memcpy(info, CONFIG_CMSIS_DAP_BOARD_VENDOR, sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR);
memcpy(info, CONFIG_CMSIS_DAP_BOARD_VENDOR,
sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR));
length = sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR);
break;
case DAP_ID_BOARD_NAME:
memcpy(info, CONFIG_CMSIS_DAP_BOARD_NAME, sizeof(CONFIG_CMSIS_DAP_BOARD_NAME));
length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_BOARD_NAME);
memcpy(info, CONFIG_CMSIS_DAP_BOARD_NAME,
sizeof(CONFIG_CMSIS_DAP_BOARD_NAME));
length = sizeof(CONFIG_CMSIS_DAP_BOARD_NAME);
LOG_DBG("ID_BOARD_NAME");
break;
case DAP_ID_PRODUCT_FW_VER:
Expand Down Expand Up @@ -151,7 +157,7 @@ static uint16_t dap_info(struct dap_context *const ctx,
break;
}

response[0] = (uint8_t)length;
response[0] = length;

return length + 1U;
}
Expand Down

0 comments on commit c22584c

Please sign in to comment.