cederom / LibSWD

CeDeROM's Serial Wire Debug Open Library
Other
122 stars 47 forks source link

Can we improve efficiency? #17

Open andrewparlane opened 7 years ago

andrewparlane commented 7 years ago

I'm capturing my SWD bus using a Salea USB scope to debug various issues and I notice that libSWD has a lot more bus transactions than my J-link programmer:

For example - Writing to the DHCSR register to enable debug:

C code using libSWD

    // set up the DHCSR reg
    int dhcsr = LIBSWD_ARM_DEBUG_DHCSR_DBGKEY |
                (enable ? LIBSWD_ARM_DEBUG_DHCSR_CDEBUGEN : 0);

    res = libswd_memap_write_int_32(libswdctx, LIBSWD_OPERATION_EXECUTE, LIBSWD_ARM_DEBUG_DHCSR_ADDR, 1, &dhcsr);

libSWD:

0.50693350  Operation   read    DebugPort   CTRL/STAT   0x8D    OK  0xF0000041  CSYSPWRUPACK=1, CSYSPWRUPREQ=1, CDBGPWRUPACK=1, CDBGPWRUPREQ=1, CDBGRSTACK=0, CDBGRSTREQ=0, TRNCNT=0x000, MASKLANE=0x0, WDATAERR=0, READOK=1, STICKYERR=0, STICKYCMP=0, TRNMODE=Normal, STICKYORUN=0, ORUNDETECT=1
0.50703380  Operation   write   AccessPort  TAR 0x8B    OK  0xE000EDF0
0.50708460  Operation   read    AccessPort  TAR 0xAF    OK  0x00000000
0.50716530  Operation   read    DebugPort   RDBUFF  0xBD    OK  0xE000EDF0
0.50724630  Operation   write   DebugPort   ABORT   0x81    OK  0x0000001E  ORUNERRCLR=1, WDERRCLR=1, STKERRCLR=1, STKCMPCLR=1, DAPABORT=0
0.50729995  Operation   read    DebugPort   CTRL/STAT   0x8D    OK  0xF0000041  CSYSPWRUPACK=1, CSYSPWRUPREQ=1, CDBGPWRUPACK=1, CDBGPWRUPREQ=1, CDBGRSTACK=0, CDBGRSTREQ=0, TRNCNT=0x000, MASKLANE=0x0, WDATAERR=0, READOK=1, STICKYERR=0, STICKYCMP=0, TRNMODE=Normal, STICKYORUN=0, ORUNDETECT=1
0.50740975  Operation   write   AccessPort  TAR 0x8B    OK  0xE000EDF0
0.50746895  Operation   write   AccessPort  DRW 0xBB    OK  0xA05F0001

J-Link

0.16056980  Operation   write   AccessPort  CSW 0xA3    OK  0x23000002  DbgSwEnable=0, Prot=0x23, SPIDEN=0, Mode=0x0, TrInProg=0, DeviceEn=0, AddrInc=Auto-increment off, Size=Word (32 bits)
0.16118865  Operation   write   AccessPort  TAR 0x8B    OK  0xE000EDF0
0.16180810  Operation   write   AccessPort  DRW 0xBB    OK  0xA05F0001

so in libswd we have 8 operations where we could use 3 or even 2 (if we know CSW is already correct).

This is not really a big problem, but something we can look at in the future.

cederom commented 7 years ago

Very good poin @andrewparlane ! I did not reverse other solutions, so your input is highly welcome and appreciated! :-)

Also please note that LibSWD was first meant to be only transport layer, while DAP was supposed to be done in a separate library. I will try to come back to this idea in my https://github.com/cederom/icederom project :-)

andrewparlane commented 7 years ago

Definitely makes sense to split hem up. My chip has two APs which makes it a bit awkward at times.

I'd love to do a bunch of tidying up and what not, but I don't really have much time to put into this. I figure creating a bunch of issues is probably the best place to start, so at least we have a list of todo items.

On 27 June 2017 at 18:06, Tomasz CEDRO notifications@github.com wrote:

Very good poin @andrewparlane https://github.com/andrewparlane ! I did not reverse other solutions, so your input is highly welcome and appreciated! :-)

Also please note that LibSWD was first meant to be only transport layer, while DAP was supposed to be done in a separate library. I will try to come back to this idea in my https://github.com/cederom/icederom project :-)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cederom/LibSWD/issues/17#issuecomment-311499988, or mute the thread https://github.com/notifications/unsubscribe-auth/AE51Ok2ZNUzAsKOx7_vmv_4xWeDIx98qks5sIXz3gaJpZM4OHNfr .

cederom commented 7 years ago

exactly, simple list, clear TODO per issue :-)

http://www.humorsoffice.com/images/2013/08/office-humor-20130818-131112.jpg

hopefully soon I will have time and resources for those things to happen :-)

andrewparlane commented 7 years ago

ha!

On 27 June 2017 at 19:09, Tomasz CEDRO notifications@github.com wrote:

exactly, simple list, clear TODO per issue :-)

http://www.humorsoffice.com/images/2013/08/office-humor- 20130818-131112.jpg

hopefully soon I will have time and resources for those things to happen :-)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cederom/LibSWD/issues/17#issuecomment-311511172, or mute the thread https://github.com/notifications/unsubscribe-auth/AE51OrabOJrBsjc5DzLpY316DaPW0prZks5sIYu0gaJpZM4OHNfr .