-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SWDP driver interface API and bit-bang driver, add CMSIS-DAP compatible controller #53798
Add SWDP driver interface API and bit-bang driver, add CMSIS-DAP compatible controller #53798
Conversation
drivers/dp/swdp_bitbang.c
Outdated
static uint8_t sw_request_lut[16] = {0U}; | ||
|
||
static void mk_sw_request_lut(void) | ||
{ | ||
uint32_t parity = 0U; | ||
|
||
for (int request = 0; request < sizeof(sw_request_lut); request++) { | ||
parity = request; | ||
parity ^= parity >> 2; | ||
parity ^= parity >> 1; | ||
|
||
/* | ||
* Move A[3:3], RnW, APnDP bits to their position, | ||
* add start bit, stop bit(6), and park bit. | ||
*/ | ||
sw_request_lut[request] = BIT(7) | (request << 1) | BIT(0); | ||
/* Add parity bit */ | ||
if (parity & 0x01U) { | ||
sw_request_lut[request] |= BIT(5); | ||
} | ||
} | ||
|
||
LOG_HEXDUMP_DBG(sw_request_lut, sizeof(sw_request_lut), "request lut"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why compute it at runtime instead of just having fixed const array with the values (with comment stating how the values were generated)? Using precomputed array would save a bit of RAM and code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was done with the latest changes 👍🏻
@flit fyi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was not able to get this working with an nrf52840dk connected to an nrf52832, ACK timed out for every request. Re-wired the nrf52832 directly to a DAPLINK programmer (without nRESET) and it works fine through that using pyocd.
I love this - thanks @jfischer-no 👍 |
f91d393
to
36daa53
Compare
Rebased. I have not addressed all the comments yet, will do so later. |
shouldn't this make use of CMSIS-DAP v2 (USB bulk) instead of HID?
|
No. USB transfer is only an option, it is not the main scope of this PR, it is there for demonstration and testing. Bit-bang controller performance is far far away from the possible USB FS interrupt transfers maximum bandwidth. I see no need to discuss this until we have stable API with few fast SWDP controllers. Also, no one forces you to use sample in this PR, you are free to implement own host backend. |
yes, true for swd communication which needs a mcu-specific optimization for speed. but for vendor-commands running over daplink you can make use of the packet-size and added speed of v2 compared to HID, even when using FS phy's |
Regardless of performance, I strongly recommend switching the example/test to use CMSIS-DAP v2 / bulk endpoints. HID for CMSIS-DAP is deprecated and should no longer be used for new code or examples. Fwiw, bit bang SWD is able to achieve 2-10 MHz, sometimes even higher, depending on the MCU and how well the code is implemented (eg, direct register writes with constant register addresses and bit masks). However, the duty cycle tends to be all over the place (not a problem protocol-wise, but ugly as hell on a scope 😝). Point being that on some controller MCUs, you can achieve faster SWD performance with bulk. |
Great work @jfischer-no! I've tested to integrate it into a probe we have and it was rather simple to get it going. Added support for nxp lpc series and could run it with 512 byte packet size on high speed usb. please feel free to integrate them into your rebase branch. I did not include the usb class driver since i do not have it in the zephyr tree. |
FYI: I'm currently working on updating this to CMSIS-DAPv2. Generic device support and simpler PIN configurations are already there. I based it on @te-johan 's version. |
I can upstream my cmsis-dapv2 class driver next week. edit:I see that you also added swd sequence support. |
@te-johan I'm sure we can find a way to merge our additions. |
16669ee
to
b12c90b
Compare
include/zephyr/drivers/swdp.h
Outdated
* @param turnaround Line turnaround cycles | ||
* @param data_phase Always generate Data Phase (also on WAIT/FAULT) | ||
* @return 0 on success, or error code | ||
*/ |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
samples/subsys/dap/sample.yaml
Outdated
build_only: true | ||
platform_allow: nrf52840dk_nrf52840 | ||
integration_platforms: | ||
- nrf52840dk_nrf52840 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- nrf52840dk_nrf52840 | |
- nrf52840dk/nrf52840 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(occurs multiple times)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworked sample configuration and removed thingy91 which is only supported in NCS.
Move low-level GPIO functions to a separate file and use GPIO driver API if low-level GPIO support is not available for the platform. Allows alternative pin configuration using only two pins, clk and dio. Improve binding description. Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
Add API to read count bits from SWDIO into data LSB first. Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
Implement wait for SWJ pins command. Signed-off-by: Maximilian Deubel <[email protected]>
Add support for DAP_INFO string elements. Signed-off-by: Maximilian Deubel <[email protected]>
Add ID_DAP_UART_* command definitions and react properly to unsupported UART commands. Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
DAP SWD sequence command is a requirement to support CMSIS-DAPv2. Raise supported version to "2.1.0". Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
b12c90b
to
89577c9
Compare
Add CMSIS DAP sample using USB as interface. Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
Use k_timepoint_t for timeout handling in the swj_pins function. Signed-off-by: Maximilian Deubel <[email protected]>
Hardcode the lookup table for SWDP requests. This is an optimization to save some space. Documentation was added to understand the values. Signed-off-by: Maximilian Deubel <[email protected]>
This patch adds documentation for the SWDP API. Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
89577c9
to
a4f7311
Compare
Add Serial Wire Debug Port interface driver API and bit-bang driver.
Add CMSIS-DAP compatible controller which is a handler between
the host interface and SWD driver.
Add cmsis dap sample using
USB HID as interfacebulk transfers.This is a rebase and followup of #20183