-
Notifications
You must be signed in to change notification settings - Fork 485
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
nRF52 program failure; packet order issue with CMSIS-DAP on Mac #1257
Comments
Also, on the same Mac the same board can be successfully flashed with openOCD:
|
Thanks for the report! I'll try to reproduce today. From the log message format it looks like you're using the version of pyocd from the |
Well, I'm not able to reproduce it with a micro:bit v2 (granted, it's an nRF52833 rather than nRF52840) using the on-board DAPLink, running on a MacBook Air M1. I tried with 0.32.0, 0.32.1, HEAD of What board and CMSIS-DAP probe are you using? Can you try with Could you please attach a debug log generated with It looks like command packets are somehow getting out of order, dropped, or otherwise mixed-up or corrupted. This is something I haven't seen before. |
It appears to work with just |
Custom, in-house board. Private fork of the CMSIS-DAP branch (d5d9be77268a1eee48339c826d51179c53b5cba2). CMSIS-DAP is running on the K22F (NXP/Freescale).
2019 MacBook Pro, BigSur (11.6.1) |
One other thing worth pointing out - apparently we've tried limit_packets option in house, but used it as |
It's good to hear that at least Which compiler are you using for DAPLink? Also, you might try rebasing your changes on the latest Sorry about the |
One more thing: it could be working in your Ubuntu VM simply because or lesser USB performance and/or differences in the Linux kernel's USB stack compared of macOS. |
Thank you for fixing the bool param parser.
|
Thanks for the answers. Regarding the DAPLink K22F HIC support, ARMmbed/DAPLink#782 adds this but apparently needs some work to be committable. We'd like to have it upstreamed, though. Is your K22F support based on this PR? What are the values of the Unfortunately the trace log didn't show anything clearly unexpected. It was intended to trace the building of transfer command packets, so it doesn't show packets being read. It also is difficult to tell at what point in the log the(first) error actually happened. I'll put together a patch that adds additional trace logging, if you don't mind running some more tests. For now, my best guess is that it's a combination of possible DAPLink firmware issues and different USB stack behaviours. The USB driver also plays a part, if CMSIS-DAP v1 (HID) is being used: Linux uses pyusb to directly control the USB interface, while Mac and Windows use hidapi, which uses the OS's HID stack for transfers. (For CMSIS-DAP v2, all OSes use pyusb.) |
My port is based on d5d9be77268a1eee48339c826d51179c53b5cba2 and merging some of the old NXP-contributed code for Kinetis family (K20, K22, K26, KL27, KL26). I've also added support for multiple (up to 4) virtual UARTs by modularizing UART component for multiple instantiations. I would love to provide it for review to be upstreamed, but I don't see it happening until at least some time in January |
No worries on the timeline… Whenever you're ready, we'd be happy to have it. 😄 |
The feature/more_cmsis_dap_trace_logging branch on my fork (git https URL This branch is based on the You can install from this branch with:
[Edit: added If you don't mind, could you please run with |
Here you go. Thank you for staying on it. |
Thanks! I'll review the log today and report back. |
Well, the last log was actually from the You can test the install by running The good news is, the log had enough extra info to start piecing together a picture of what's happening. The reads are related to scanning flash sectors to be programmed, and the
The failure happens on the 65th deferred packet sent.
This should work by sending as many outstanding packets up to the number supported by the CMSIS-DAP firmware (see the end of this post). When the maximum outstanding count is hit, packets will start to be read as additional (deferred) packets are sent. The error is that a response to a Having the updated trace log should make it possible to nail down the root cause, at least within pyocd or whether it's on the CMSIS-DAP side. I suspect it's not pyocd, since the same logic is used for all CMSIS-DAP transfers—but who knows? 😄 What is the value of the It should be 64… that will confirm part of the understanding of the issue. |
Yes, the DAP_PACKET_COUNT is 64. I assume that's correct for full-speed USB.
Just in case I've done something silly, here is the install log: |
Thanks. Your install and trace log look fine! I don't know why git isn't seeing the more recent tags. Anyway, the "dev419" bit of the version is really the important part—it's the number of commits since the base version. Thanks for confirming The trace clearly shows that the first USB packet read after 64 packets have been sent is one of the 1..64 packets and not packet 0. Also, I'm now able to reproduce the issue on my system! I'm using a K26F HIC, the only other DAPLink HIC port that has a When using CMSIS-DAP v1 (HID) with the hidapi backend (just like your setup), the problem is fully reproducible. But using CMSIS-DAP v2 (bulk) with the pyusb_v2 backend the problem disappears. This seems to be the case because the pyusb backend runs a background read thread. As soon as a a command response is available, it's read and stored by pyocd, so the probe-side queue never actually fills up. Whereas with the hidapi backend, responses are only read as the packet queue gets full. This also fully explains why it works under Ubuntu. On Linux, a pyusb based backend is always used even for CMSIS-DAP v1, so there is always a background read thread. Some further investigation is still needed. It's not clear where the packet is getting lost, if it's on the probe, somewhere in the OS HID stack, or in hidapi. I might have to break out the USB bus analyser! 😁 It seems like it may be possible to add a read thread for the hidapi backend to work around it, but fully understanding the root cause would be nice. Thanks very much for putting up with all the back and forth of this issue! |
Gentlemen, I think this may cause an issue. On Mac, the HIDAPI starts dropping 'outstanding' USB IN reports if there are more than 30 of them. |
Hah, @bohdan-tymkiv. That's exactly it, thanks so much for the pointer! 😄 30 is such an arbitrary number… I'll add a workaround to pyocd for now, and may try to address it in hidapi with packet timeouts or something similar (at least a larger number). |
The same feature/more_cmsis_dap_trace_logging branch has a fix now. Or two, actually. It implements the maximum of 30 outstanding packets for hidapi, and it adds a background read thread. @afeinman-snap If you have a chance, would you mind testing with this branch to make sure it solves the problem on your end. If everything's ok, a pull request will be created for merging into the |
Yep, works like a champ. Thank you and special thanks to @bohdan-tymkiv. I'll wait for the merge. Feel free to close. |
Thanks for testing so quickly. I'll keep this issue open until the fix is merged. Fyi, there will most likely be two PRs: one for the fix, and one for the additional trace logging. So the fix will be moved from the feature/more_cmsis_dap_trace_logging branch to its own branch in preparation. |
I am unable to flash an NRF52 part over CMSIS-DAP connection. I'm pretty sure this used to work but I am unable to find back when. The same physical board can be successfully programmed from the same Macbook from within a Ubuntu VM using the same version of pyOCD (0.32.1)
The error is:
When the error occurs, the actual value of data[0] is DAP_TRANSFER_BLOCK, not DAP_TRANSFER as expected
The text was updated successfully, but these errors were encountered: