SWD_READ
The SWD_READ function provides a simple way to perform an SWD read that takes care of the bi-directional nature of the protocol operation for the user.
SWD_READ 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. In this mode unless the SWD_READ is a complete success there will be a runtime error and the test will exit. The following rules apply:
- If the target responds with the OK acknowledgement (0b001) and no parity bit error the function will return with the value read.
- 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.
- If there is a parity bit error in the read data after a OK acknowledgement a SWD runtime error will be reported and the test will exit.
- Calling SWD_READ with ack and parityError arguments is a runtime error and the test will exit.
- SWD_EXIT_ON_ERROR disabled
In this mode SWD_READ calls will always return. Errors must be checked by the user. The following rules apply:
- If the target responds with the OK acknowledgement (0b001) and no parity bit error the function will return with the value read.
- 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 and the read value will be invalid. The timeoutOnWaitCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
- If the target responds with the FAULT acknowledgement (0b100) the function will return and the read value will be invalid. The faultCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
- If the target responds with any other unrecognised acknowledgement the function will return and the read value will be invalid. The otherAcksCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
- If there is a parity bit error in the read data after a OK acknowledgement the function will return and the read value will be invalid. The parityErrorCounter retrieved by SWD_GET_RESPONSE_COUNTERS will be incremented.
When SWD_EXIT_ON_ERROR is disabled it is recommended to regularly call SWD_GET_RESPONSE_COUNTERS or SWD_GET_LAST_RESPONSE to check for any errors having occurred previously, or using SWD_READ with the ack and parityError arguments to pass the error data back with the read. There is no added performance cost retrieving errors for every SWD_READ scan.
If SWD pins are shared with JTAG TAP pins, the first JTAG access after using SWD_READ will reset the JTAG chain.
The target will need to be configured to be in the SWD mode before the SWD_READ 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_READ calls can be made within a HOLDOFF block. The read operation will be added to the HOLDOFF queue before the HOLDOFF is temporarily released for all outstanding requests to complete including the SWD_READ. HOLDOFF is then re-enabled for the next operation.
Syntax
SWD_READ( INT APnDP, INT address ) ( INT data )
SWD_READ( INT APnDP, INT address ) ( INT data, INT ack, INT parityError )
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 INT value containing the data successfully read (LSB is the first read).
- ack
- The acknowledgement returned by the target. Can only be used when SWD_EXIT_ON_ERROR is disabled.
- parityError
- Following an OK acknowledgement this will be 0 if there is no parity error in the read value returned or 1 if there is. Can only be used when SWD_EXIT_ON_ERROR is disabled.
Examples
CONST INT DPIDR := 0x0; CONST INT STAT := 0x4; INT data, id, ack, parityError; SWD SWD_READ(0, DPIDR[3..2])(id); PRINT("id = ", FORMAT(id, "%#08x\n")); SWD_READ(0, STAT[3..2])(data); PRINT("data = ", FORMAT(data, "%#08x\n")); END; SWD_EXIT_ON_ERROR(FALSE); SWD SWD_READ(0, DPIDR[3..2])(id, ack, parityError); PRINT("id = ", FORMAT(id, "%#08x"), ", ack = ", FORMAT(ack, "%#03b"), ", parityError = ", parityError, "\n"); SWD_READ(0, STAT[3..2])(data, ack, parityError); PRINT("data = ", FORMAT(data, "%#08x"), ", ack = ", FORMAT(ack, "%#03b"), ", parityError = ", parityError, "\n"); END;
id = 0x2ba01477 data = 0x00000000 id = 0x2ba01477, ack = 0b001, parityError = 0 data = 0x00000000, ack = 0b001, parityError = 0
See also
XJTAG v4.1.100