SWD_WRITE
The SWD_WRITE function provides a simple way to perform an SWD write that takes care of the bi-directional nature of the protocol operation for the user.
SWD_WRITE behaves differently depending on the current setting of the XJEase function SWD_EXIT_ON_ERROR:
- SWD_EXIT_ON_ERROR enabled (default legacy behaviour)
The default legacy behaviour for SWD scans. The following rules apply:
- If the target responds with the OK acknowledgement (0b001) the write will be completed.
- If the target responds with the WAIT acknowledgement (0b010) the scan is automatically retried a number of times. After multiple attempts if it's still reponding with WAIT a SWD runtime error will be reported and the test will exit.
- If the target responds with the FAULT acknowledgement (0b100) or any other unknown acknowledgement a SWD runtime error will be reported and the test will exit.
- SWD_EXIT_ON_ERROR disabled
In this mode SWD_WRITE calls will always return. Errors must be checked by the user. The following rules apply:
- If the target responds with the OK acknowledgement (0b001) the write will be completed.
- If the target responds with the WAIT acknowledgement (0b010) the scan is automatically retried a number of times. After multiple attempts if it's still reponding with WAIT the function will return without performing the write and the test will move on. The timeoutOnWaitCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
- If the target responds with the FAULT acknowledgement (0b100) the function will return without performing the write and the test will move on. The faultCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
- If the target responds with any other unrecognised acknowledgement the function will return without performing the write and the test will move on. The otherAcksCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
It is not recommended to call SWD_GET_RESPONSE_COUNTERS or SWD_GET_LAST_RESPONSE after every SWD_WRITE because every call to get responses will pause the runtime thread waiting for the last response to be fully processed. Instead the recommended approach is to periodically call SWD_GET_RESPONSE_COUNTERS after blocks of writes to see if any occurred in the previous set.
If SWD pins are shared with JTAG TAP pins, the first JTAG access after using SWD_WRITE will reset the JTAG chain.
The target will need to be configured to be in the SWD mode before the SWD_WRITE function can succeed. If the device also supports JTAG, switching to SWD operation using the SWD defined line reset sequence is required. To switch the target to SWD mode use an SWD block or send an SWD line reset sequence manually using SWD_RAW_SEND.
SWD_WRITE calls can be made within a HOLDOFF block. The writes will be queued up to be performed once exiting the final HOLDOFF block, or after calls to other functions that require all requests to be released immediately such as SWD_READ or FLUSH.
Syntax
SWD_WRITE( INT APnDP, INT address, INT data )
Parameters
- APnDP
- A single bit indicating whether the Debug Port or the Access Port Access register is to be accessed. 0b0 for DP and 0b1 for AP.
- address
- A two bit value specifying the A[3:2] address field.
- data
- A 32-bit value to write (LSB is the first sent).
Examples
CONST INT DPIDR := 0x0; CONST INT CTRL := 0x4; INT id; SWD SWD_READ(0, DPIDR[3..2])(id); SWD_WRITE(0, CTRL[3..2], 0x50000000); END;
See also
XJTAG v4.1.100