aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/drivers/stlink_usb.c
AgeCommit message (Collapse)AuthorFilesLines
2022-04-03libusb_helper.h: Increase USB timeoutGabor Csapo1-2/+2
When we debug a target that works as a USB device, halting the target causes the USB communication with the USB host to become unresponsive. The host will try to reconnect/reset/setup the unresponsive device during which communication with other devices on the same USB bus can get stalled for several seconds. If the JTAG adapter is on the same bus, we need to make sure openOCD will wait for packets at least as long as the host USB stack. Otherwise the USB stack might deliver a valid packet, but openOCD would ignore it due to the timeout. The xHCI spec uses 5 sec timeouts, so let's use that in openOCD with some margin. Use this value in all libusb calls. HID API might have a libusb backend and would probably be victim to the same bug, so it should use this timeout, too. Ticket: https://sourceforge.net/p/openocd/tickets/343/ Signed-off-by: Gabor Csapo <gaborcsapo@google.com> Change-Id: Ia3dc1356e676fe550f57a4c72f7a24ba296b6af2 Reviewed-on: https://review.openocd.org/c/openocd/+/6882 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-03-19stlink: enable queuing with stlink-server API v3Tarek BOCHKATI1-8/+21
ST-Link Server 2.1.0-1 fixes concurrency issue with RW_MISC command Starting from this version the ST-Link Server API is now v3. In this change we save the ST-Link Server version, and check if the API is greater or equal to 3 to enable the queuing. Change-Id: I239eb81024700514c607a269b66651f457206faa Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6876 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-11-28drivers: call adapter_get_required_serial() in jtag_libusb_open()Antonio Borneo1-1/+1
Now that adapter serial is handled independently from the adapter drivers, move inside jtag_libusb_open() the call to adapter_get_required_serial(), so every adapter that uses libusb will automagically get USB serial support. Extend the documentation to list the adapters involved. Change-Id: I75b3482d38f8ed3418329f3106c5e8b689fd460b Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6663 Tested-by: jenkins
2021-11-28jtag/hla, jtag/stlink: switch to command 'adapter serial'Antonio Borneo1-38/+12
The driver hla defines the command 'hla_serial' to specify the serial string of the adapter. The driver st-link defines the command 'st-link serial' to specify the serial string of the adapter. Remove and deprecate the driver commands and use 'adapter serial'. Change-Id: I9505c398a77125b1ebf4ba71da7baf4d663b75be Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6657 Tested-by: jenkins
2021-11-13stlink (tcp): manage scattered stlink-server responsesTarek BOCHKATI1-9/+28
detected in ubuntu 20.04 sometimes, the stlink-server response could be segmented on multiple packets. this causes stlink_tcp_send_cmd to fail with the following msg: Error: failed to receive USB CMD response because the received_size < expected size to fix the issue, do recv in a loop till all data is received or timeout is reached. Change-Id: I46cc60c231b4cc52f150ead268f843bc60c41149 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6671 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
2021-11-05stlink: skip rw-misc commands with TCP serverAntonio Borneo1-0/+7
The main purpose of TCP server is to allow multiple clients to connect and share the same physical stlink. The commands RW MISC don't lock the communication between command and answer, thus cannot prevent another client to break this sequence. The commands are not supposed to be used in shared mode. Prevent the use of RW MISC commands on a (possibly) shared TCP backend. This degrades the overall performance, but the shared mode already adds its own overhead, so this is not really an issue. Change-Id: I713d912a269664859c8142932a9905d24b6d3caa Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6608 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: add support for rw-misc commandsAntonio Borneo1-4/+193
Firmware versions V2J32 and V3J2 introduce the commands RW-MISC to put in a single USB packet a sequence of mem_ap read/write. These commands provide a significant speed improvement while accessing the debug unit at scattered addresses. Add the low level commands and extend high level implementation. Skip for the moment the command to read the max number of items allowed by the firmware and use some hardcoded values. Change-Id: I8adc630cc0de733511e9d94533cbfe9f3b301a83 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6607 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: dequeue CSW write only if it doesn't change csw_defaultAntonio Borneo1-4/+17
The stlink commands for buffer read/write carry the associated CSW value that has to be used. We can dequeue any CSW write request and add the CSW in the following buffer read/write. In preparation to next patch that uses stlink commands misc-rw (commands that don't handle CSW value), let's dequeue only those CSW write that don't change csw_default. Keep a local cache of last csw_default. Tag the queued CSW writes that change csw_default. Dequeue only the un-tagged CSW writes. On buffer read/write commands, limiting the dequeued CSW write surely adds a performance penalty. But csw_default is not changed often so the penalty is not significant. Change-Id: I538d257fe3c434fc97587846d759951384327f02 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6606 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: add support for native no_addr_incr commandsAntonio Borneo1-2/+106
Firmware versions V2J26 and V3J1 introduce the command STLINK_DEBUG_WRITEMEM_32BIT_NO_ADDR_INC Firmware versions V2J32 and V3J2 introduce the command STLINK_DEBUG_READMEM_32BIT_NO_ADDR_INC These new commands can provide speed improvement to Cortex-A memory download (its debug port use a FIFO for data transfer). Add the low level commands and extend high level implementation. Change-Id: I3b65acbeaec3bd305f5568b9ee4bc9495b113448 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6605 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: collapse consecutive mem AP r/w in a single commandAntonio Borneo1-42/+94
Detect a sequence of memory AP operations that can be issued as a single stlink command. This improves the data throughput during memory transfer. Change-Id: Ifa4488513346fc7cd0c9317b7d24ef510ccfd959 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6604 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: detect mem_ap R/W and dequeue set TAR and CSWAntonio Borneo1-8/+172
By using the stlink commands for memory read write we can gain some performance, but only when TAR and/or CSW are changed. During long transfers with constant CSW and TAR auto-incremented there is no gain, since the same amount of USB/TCP packet is used. Plus, by dropping ADIv5 packed transfers the performance is lower on 8 and 16 bits transfers. This changes opens the opportunity for collapsing memory burst accesses in a single stlink USB/TCP packet. Initialize the values of enum queue_cmd to easily extract the word size through a macro, even if this is not used here. Change-Id: I6661a00d468a1591a253cba9feb3bdb3f7474f5a Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6603 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: expose ap number and csw in memory r/wAntonio Borneo1-34/+89
Recent versions of stlink firmware allow accessing access port other than zero and setting the CSW. Modify the internal API to provide ap_num and csw. There is no interest to modify HLA to use ap_num and csw, so set and use some backward compatible defaults. Change-Id: I3f6dfc6c670d19467d9f5e717c6c956db6faf7f3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6602 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: add queue in dap-direct modeAntonio Borneo1-47/+181
Implement a minimalist queue for DP/AP commands and reorganize the code to use it. There is no performance improvement; the queue elements are still sent one-by-one on USB or on TCP during dap_run(). Change-Id: I8353563e59f883624bcc0fbe8b54955e4f27ccfa Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6601 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-11-05stlink: check buffer size on 16 and 32 bit memory transferAntonio Borneo1-8/+35
Both HLA and ADIv5 layers limit the memory transfer within blocks whose boundaries are aligned at 1024 or 4096 bytes. New stlink firmware handle the ADIv5 TAR autoincrement, making possible to send memory transfers across the boundary of 1024 or 4096 byte. OpenOCD doesn't use this feature yet. Use the correct buffer size in the code, even if it is not used. While there, split SWIM buffer size from JTAG/SWD case; stlink has a dedicated command to retrieve SWIM buffer size, but currently not implemented in OpenOCD. Change-Id: Id46c0356ef21cead08726c044a1cd9725fd4f923 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6600 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-10-02stlink-dap: add 'cmd' to send arbitrary commandsAntonio Borneo1-0/+44
Either for testing new commands and to retrieve information that don't fit in any specific place of OpenOCD, for example monitoring the target's VDD power supply from a TCL script. Change-Id: Id43ced92c799b115bb1da1c236090b0752329051 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6564 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-09-25armv7m.h: relax dependency from 'arm_adi_v5.h'Antonio Borneo1-0/+1
The include file 'armv7m.h' includes 'arm_adi_v5.h' only to get the definition of 'struct adiv5_ap', but doesn't need the struct content. Reducing the cross dependencies speeds-up the compile time during code development by avoiding re-compiling file. Relax the dependency by locally declaring 'struct adiv5_ap' in 'armv7m.h' and remove the include of 'arm_adi_v5.h'. Fix the other files that have now lost the includes file that 'arm_adi_v5.h' depends from. Change-Id: Ic0d40b17db6045fa43f348bda83eaf211a6b347d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6468 Tested-by: jenkins Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com> Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-09-18stlink: Add PID for V3 device without MSDAndreas Sandberg1-0/+2
Add the 0x3754 PID used by some STLINK-V3 devices when MSD has been disabled. This PID has been observed on a Nucleo-G431RB board. Signed-off-by: Andreas Sandberg <andreas@sandberg.uk> Change-Id: Idb85874fa5a9dff5940bae7e95426a956693b976 Reviewed-on: https://review.openocd.org/c/openocd/+/6555 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-08-22stlink: fix SWIM mode on stlink-v3Antonio Borneo1-1/+2
Commit 89f07325f2e7 ("stlink: Set speed before entering JTAG/SWD mode") anticipates setting the adapter speed just before entering in the JTAG/SWD mode. This to initiate the communication with the speed selected by the user. But SWIM doesn't allow setting the speed before entering in SWIM mode. The resulting error causes OpenOCD to quit. The problem only happens with stlink-v3, due to the different way to set the adapter speed on different stlink versions. Set the speed before entering in the mode only for JTAG and SWD modes. Change-Id: Iab42cd9d72ecfac14c7e17bae74e0dee2218b235 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: 89f07325f2e7 ("stlink: Set speed before entering JTAG/SWD mode") Reviewed-on: https://review.openocd.org/c/openocd/+/6443 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-07-24openocd: remove NULL comparisons with checkpatch [1/2]Antonio Borneo1-3/+3
Patch generated automatically through the new checkpatch with flags "--types COMPARISON_TO_NULL --fix-inplace". This only fixes the comparisons if (symbol == NULL) if (symbol != NULL) The case of NULL on the left side of the comparison is not tested. Some automatic fix is incorrect and has been massaged by hands: - if (*psig == NULL) + if (*!psig) changed as + if (!*psig) Change-Id: If4a1e2b4e547e223532e8e3d9da89bf9cb382ce6 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6351 Tested-by: jenkins
2021-07-24openocd: fix simple cases of NULL comparisonAntonio Borneo1-49/+49
There are more than 1000 NULL comparisons to be aligned to the coding style. For recurrent NULL comparison it's preferable using trivial scripts in order to minimize the review effort. Patch generated automatically with the command: sed -i PATTERN $(find src/ -type f) where PATTERN is in the list: 's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g' 's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g' 's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g' Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6350 Tested-by: jenkins
2021-07-20target/cortex_m: rename CamelCase symbolAntonio Borneo1-1/+1
Change-Id: I67d803e15ba9fd08f2b31361fb3604275e483605 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6339 Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-27stlink: fix SIGSEGV with libusb v1.0.24-33-g32a2206 (11618)Antonio Borneo1-6/+1
The stlink driver incorrectly uses a NULL pointer for libusb's struct libusb_context. The correct value to be used is local in libusb_helper.c. Move in the helper file, in a wrapper function, the only call that requires the above value, and let stlink driver to use this wrapper. This issue has not triggered any visible problem until a code refactoring [1] in libusb has made OpenOCD crashing on Windows and on MacOS. Change-Id: Id1818c8af7cf0d4d17dfa1d22aad079da01ef740 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: https://sourceforge.net/p/openocd/tickets/308/ Fixes: https://github.com/libusb/libusb/issues/928/ Fixes: 42d8fa899c6a ("stlink_usb: Submit multiple USB URBs at once to improve performance") Link: [1] https://github.com/libusb/libusb/commit/32a22069428c Reported-by: Andrzej Sierżęga <asier70@gmail.com> Co-developed-by: Andrzej Sierżęga <asier70@gmail.com> Co-developed-by: Xiaofan Chen <xiaofanc@gmail.com> Reviewed-on: http://openocd.zylin.com/6331 Tested-by: jenkins Reviewed-by: Marc Schink <dev@zapb.de> Reviewed-by: Xiaofan <xiaofanc@gmail.com> Reviewed-by: Andrzej Sierżęga <asier70@gmail.com> Reviewed-by: Oleksij Rempel <linux@rempel-privat.de> Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2021-06-04Avoid non-standard conditionals with omitted operands.R. Diez1-2/+2
Fixes bug #257. Change-Id: I05fc6468306d46399e769098e031e7e588798afc Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de> Reviewed-on: http://openocd.zylin.com/6271 Tested-by: jenkins Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-29stlink: reorder the flag macro by firmware releaseAntonio Borneo1-11/+11
The corresponding bit for each macro is changed, but this is not relevant in the code. Change-Id: I7039464f5a3d55d008208f44952aadeb815bd5a3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6212 Tested-by: jenkins
2021-05-29stlink: add comment of firmware version for each flag bitAntonio Borneo1-11/+11
Change-Id: I7f7c7b9c9cfd88125f82662ed864a2c0715140b1 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6211 Tested-by: jenkins
2021-05-01Cleanup of config/includes.Tim Newsome1-0/+1
Remove a use of AH_BOTTOM from configure.ac. This macro is used by autoheader to add '#include' of some include file to the end of config.h.in and then to config.h. OpenOCD can be built with a custom config.h, so it's preferable to move these '#include' statement directly in the C files that need them dropping this unneeded dependency. It also causes problems when I want to use the gnulib library (which comes with its own Makefile, and does not have the same include path as the top-level Makefile). So this change touches a lot of files, but is actually really simple. It does not affect functionality at all. Change-Id: I52c70bf15eb2edc1dd10e0fde23b2bcd4caec000 Signed-off-by: Tim Newsome <tim@sifive.com> Reviewed-on: http://openocd.zylin.com/6171 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-01libusb: don't use typedef'sAntonio Borneo1-1/+1
Libusb defines both the struct and a typedef to the struct using the same struct name. It's then possible to use either 'struct x' and 'x'. E.g.: typedef struct libusb_device libusb_device; OpenOCD is not consistent and uses a mix of 'struct x' and 'x'. To make OpenOCD code uniform, stick at project's coding style and use 'struct x' in place of the typedef'd name. Change-Id: I901458b680e42830d3f371e47997157f91b7f675 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6165 Tested-by: jenkins Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li> Reviewed-by: Marc Schink <dev@zapb.de> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2021-03-10stlink: swo: use completely the available bufferAntonio Borneo1-1/+1
The buffer passed to stlink_usb_trace_read() is allocated of size *size and does not need to be zero-terminated. There is no reason to not fill its last byte. When checking the bytes available on swo, limit the retrieved byte length to *size. Change-Id: Iade0f8963118695931f13a8a3f1ab204911236b6 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reported-by: Adrian Negreanu <adrian.negreanu@nxp.com> Reviewed-on: http://openocd.zylin.com/6061 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com> Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2021-03-10stlink: fix execution order in stlink_config_trace()Antonio Borneo1-7/+16
The change [1] guarantees that the value pointed by 'prescaler' gets always set, even when the adapter does not support the specific mode requested (e.g. sync), or during trace disabling. This works fine with the code in armv7m_trace_tpiu_config(), but requires all the parameters to be valid also to disable the trace (with 'enable==false'), otherwise returns error on incorrect parameters or even causes segmentation fault if pointers 'trace_freq' or 'prescaler' are NULL. Another problem in stlink_config_trace(), not linked with [1], is caused by a tentative to change the settings on an already enabled trace; the trace is disabled before the new parameters are fully validated and in case of invalid parameters the trace is not re-enabled. It would be more logical to first check all the parameters, then disable the trace, change the settings and re-enable the trace. Practically revert [1] by checking 'enable==false' at function entry, then disable trace and exit without any further check on the other parameters. For the case 'enable==true', validate all the function parameters then disable the trace, update the trace settings and re-enable the trace. Modify the caller armv7m_trace_tpiu_config() to initialize the variable 'prescaler' to a safe value to avoid the issue targeted by [1]. [1] commit 38277fa75280 ("jtag/drivers/stlink_usb: fix SWO prescaler") Change-Id: Ia6530682162ca2c9f5ac64301f2456f70cc07ed2 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5934 Tested-by: jenkins Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com>
2021-03-10stlink: support of ST-LINK TCP server using stlink-dap and hlaTarek BOCHKATI1-18/+489
Quote: The ST-LINK TCP server is an application to share the debug interface of a single ST-LINK board among several host applications, typically a debugging tool and a monitoring tool. Note: ST-Link TCP server does not support the SWIM transport. ST-LINK TCP server allows several applications to connect to the same ST-Link through sockets (TCP). To use ST-LINK TCP server: - using stlink-dap : use 'st-link backend tcp [port]' - using hla : use 'hla_stlink_backend tcp [port]' the default port value is 7184 Change-Id: I9b79f65267f04b1e978709934892160e65bd2d6d Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5633 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-03-10stlink: separate stlink core from USB functionsTarek BOCHKATI1-62/+141
the introduced stlink_backend_s struct provides an API to separate USB internals from stlink core. this separation aims to ease: - stlink-server integration [1] - stlink driver split into modules: - stlink_core - stlink_usb - stlink_tcp [1] [1] refer to http://openocd.zylin.com/#/c/5633/ Change-Id: Iff6790942612ce1769ec4c75990914534e5e9e24 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5632 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-11-15stlink: handle read/write FPU registers in HLA APIAntonio Borneo1-0/+21
Old stlink firmware in stlink V1 and stlink V2 pre-J15 do not handle FPU registers in the read_reg() and write_reg() API. Add code to be compatible with the new API of OpenOCD. Change-Id: Ib0439c5294b6911ea75efe8c7fa085b014317a4b Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5883 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-11-15hla: API: specify that read_reg/write_reg use regsel as parameterAntonio Borneo1-4/+4
The API of hla have been defined from ST-Link basic operations. By chance, all the current implementation of hla (st-link, ti-icdi and nulink) share the same way to handle the parameter 'num' of the API read_reg() and write_reg(), that is simply using it to initialize the field REGSEL (bits [6:0]) of armv7m Debug Core Register Selector Register (DCRSR). Add a comment in the API definition to highlight this, in case it get used by a further hla implementation, then rename as 'regsel' the 'num' parameter. Change-Id: I4b6a2c7d78b4fc4de2b9b2bdba065414b15c6ba3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5882 Reviewed-by: Edward Fewell <edwardfewell@hotmail.com> Tested-by: jenkins Reviewed-by: Zale Yu Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-11-07stlink: fix computation of trace prescalerAntonio Borneo1-6/+10
Use integer rounding for the computation of prescaler. Improve the test of prescaler range, knowing its value would be decremented before being written in TPIU ACPR. Change-Id: I041dde1dca41323904e36a6b6975028a6de902b3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5909 Tested-by: jenkins
2020-11-07stlink: fix max SWV baudrate on stlink v3Antonio Borneo1-3/+7
While stlink v2 anly accept till to 2 MHz for SWV baudrate, stlink v3 accepts up to 24 MHz. Check the stlink version and use the respective max value. Change-Id: I911207a35983b6acf0b901059076dd31f70e6290 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reported-by: Pawel <phryniszak@users.sourceforge.net> Fixes: https://sourceforge.net/p/openocd/tickets/283/ Reviewed-on: http://openocd.zylin.com/5908 Tested-by: jenkins
2020-11-04jtag: declare local symbols as staticAntonio Borneo1-4/+4
Functions and variables that are not used outside the file should be declared as static. Change-Id: I58c9f5557d4809db9ccc34d32182c3797f825da1 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5896 Tested-by: jenkins
2020-10-30jtag/drivers/stlink_usb: fix SWO prescalerCliff L. Biffle1-6/+6
The config_trace function has an out-parameter for generating the prescaler for the TPIU. The STLink implementation wasn't always writing it, causing the tpiu command to load uninitialized stack memory (minus one) into the TPIU's prescaler register when 'external' was requested. This change ensures that the out-parameter (and the other one, trace_freq, which hadn't caused any buggy behavior for me) are written every time. Signed-off-by: Cliff L. Biffle <cliff@oxide.computer> Change-Id: I222975869b1aa49cc6b1963c79d5ea0f46522b8c Reviewed-on: http://openocd.zylin.com/5656 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-09-05jtag: use proper format with uint32_tAntonio Borneo1-4/+4
Modify the format strings to properly handle uint32_t data types. Change the prototype of detect_swo_freq_and_prescaler() in 'jlink.c' to avoid an implicit cast in the caller function. Change the type of the variable retlen in some functions in 'usb_blaster.c' to properly pass their pointer to the local read and write functions. Use the proper parser COMMAND_PARSE_NUMBER(u32, ...). Change-Id: I5227dbce04ee59881f173724db90790b7b9cc7af Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5815 Tested-by: jenkins
2020-07-26jtag: fix minor typosAntonio Borneo1-3/+3
Change-Id: I3a3370db438f8fd045fb22e7c9fff4e83794a3b7 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5767 Tested-by: jenkins
2020-06-14stlink: code factorization by introducing stlink_usb_exit_modeTarek BOCHKATI1-43/+24
Change-Id: I4abd6432c4ef969e382bfed96cd19a49d9610000 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5612 Tested-by: jenkins
2020-05-24stlink: fix open AP for v2j37 and v3j7Antonio Borneo1-4/+11
The new stlink firmware requires opening the AP before issuing any operation. In the current code we have a 'questionable' check about the core model to set the TAR autoincrement, that is issued without opening the AP, thus causing a STLINK_BAD_AP_ERROR. Modify the AP open API to handle this case and open AP#0 before the memory access to check the core model. Change-Id: I576955b5094bd41d63ff1fbad7b4fd9433253321 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reported-by: Andreas Bolsch <hyphen0break@gmail.com> Reviewed-on: http://openocd.zylin.com/5691 Tested-by: jenkins Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
2020-05-24stlink: fix incorrectly returned error on v2j28Antonio Borneo1-1/+14
Firmware v2j28 introduces the API to open and close the AP, but closing AP always returns error 0x1d (STLINK_BAD_AP_ERROR). Ignore the error returned by the bogus firmware on closing AP. Change-Id: I992ddbf7acb10f1d376ed8f781eeb3344605b85d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5683 Tested-by: jenkins
2020-05-24stlink: default dapdirect to SWD instead of JTAGAntonio Borneo1-1/+1
When the transport is not specified, OpenOCD uses the first listed by the selected adapter driver. The old HLA driver for stlink lists SWD as first. The new driver dapdirect instead lists JTAG, making more difficult a fallback to HLA when dapdirect is not available due to old stlink FW. Plus, in case of JTAG wiring, SWD is still possible, while the opposite is not. Reorder the list of transports to grant the default to SWD. Change-Id: Id9c529e921b148d5b352d4603a9028c2a5f15d83 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Suggested-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5538 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-05-24stlink: simplify handling of SWIMAntonio Borneo1-17/+8
Now that SWIM is not accessed through HLA anymore, decouple the SWIM code and remove the conditional execution. Fix the inconsistency of the return type for stlink_usb_state() in case of SWIM (returns ERROR_OK while type is enum target_state) introduced by commit 3de6b5f6e52f ("jtag/drivers/stlink_usb : implemented and repaired SWIM support"). The code added by commit above in stlink_usb_state() is an hack to reuse existing HLA API to perform a reconnect. Move the SWIM specific code from stlink_usb_state() to a dedicated stlink_swim_op_reconnect() that provides consistent data type. Change-Id: I3fe175fef00b0735bea6139b057f217a080c9d38 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: 3de6b5f6e52f ("jtag/drivers/stlink_usb : implemented and repaired SWIM support") Reviewed-on: http://openocd.zylin.com/5532 Tested-by: jenkins
2020-05-24stlink: simplify mem R/W with SWIMAntonio Borneo1-12/+36
Thanks to API separation between SWIM and the other transports, we can easily split the memory read/write for SWIM from the rest of the code. While there, use the macro STLINK_DATA_SIZE as size of data chunks that can be read/write in SWIM. This was not implemented before. Change-Id: I7d913c92539007e4d914480bacc0126a8f0e9705 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5531 Tested-by: jenkins
2020-05-24swim: add new transportAntonio Borneo1-4/+35
Add SWIM and STM8 to documentation and update TODO file. Introduce transport "swim" and command "swim newtap". Switch in swim.c from HLA API to the new SWIM API. Implement in stlink driver the SWIM APIs as wrappers of existing HLA functions. Remove any SWIM related reference from HLA files. Update stm8 config files and stlink-dap interface config file. Change-Id: I2bb9f58d52900f6eb4df05f979f7ef11fd439c24 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5530 Tested-by: jenkins
2020-05-24swim: fix adapter speed handlingAntonio Borneo1-6/+10
SWIM transport only supports two adapter speeds: - "low speed" equal to 363 kHz (8 MHz / 22) - "high speed" equal to 800 kHz (8 MHz / 10) Replace the previous convention that use "0" or "1" for "low" or "high" speed with the effective speed in kHz. Rework the implementation of stlink_speed_swim(). Set low speed in the stm8 config files, because only low speed is permitted at debug connection; the previous code ignores the initial value. Change-Id: I2484c9419a2c554c59eb6b9216339393ab0b54f3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5529 Tested-by: jenkins
2020-05-24stlink: reduce use of hla specific enum hl_transportsAntonio Borneo1-50/+52
In the driver's code it's widely used the enum hl_transports for any check concerning the current transport, even for the non-hla transport dapdirect. The driver already provides a stlink specific enum stlink_mode that can be used in place of the hla one. Replace the hla enum with the stlink one allover the code. Introduce a hla specific wrapper stlink_usb_hl_open() to cope with the only API that requires the hla specific enum. The overall behaviour is not changed, with exception for a debug message in stlink_usb_open() than now prints the numeric value of stlink enum in place of the numeric value of the corresponding hla one. This change prepares the road for moving SWIM transport out of hla by removing any reference to the macro HL_TRANSPORT_SWIM from the stlink driver. Change-Id: Ieeea34f312245a94bfc1333087afdb8eb9f77139 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5526 Tested-by: jenkins
2020-05-09coding style: avoid unnecessary line continuationsAntonio Borneo1-3/+3
Line continuation, adding a backslash as last char of the line, is requested in multi-line macro definition, but is not necessary in the rest of C code. Remove it where present. Identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types LINE_CONTINUATIONS -f {} \; Change-Id: Id0c69e93456731717a7b290b16580e9f8ae741bc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5619 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09coding style: remove useless break after a goto or returnAntonio Borneo1-1/+0
In a switch/case statement, a break placed after a goto or return is never executed. The script checkpatch available in Linux kernel v5.1 issues a warning for such unused break statements. In the process of reviewing the new checkpatch for its inclusion in OpenOCD, let's get rid of these warnings. The script checkpatch is unable to fixup automatically this case. Thanks to having "break" command using a single code line, this patch has been generated using the script below: find src/ -type f -exec ./tools/scripts/checkpatch.pl -q \ --types UNNECESSARY_BREAK -f {} \; \ | sed -n '/^#/{s/^.*FILE: //;s/:$//;s/:/ /;p}' \ | awk 'function P() {print "sed -i '\''"b"'\'' "a}; { if ($1!=a) { if (a) {P()}; a=$1; b=$2"{d}"; } else { b=b";"$2"{d}" } }; END {P()}' Change-Id: I56ca098faa5fe8d1e3f712dc0a029a3f10559d99 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5617 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins