SWD protocol

The SWD protocol support allows a Digilent Waveforms device to be used as a simple SWD (Serial Wire Debug) device.

Todo

This section is currently incomplete.

A bit of background on SWD would be helpful.

Using the SWD protocol functionality

To use the SWD protocol functionality you first need to initialize a DwfLibrary instance. Next, you open a specific device. The device’s SWD protocol functionality can now be accessed via its protocol.swd attribute, which is an instance of the ProtocolSWD class:

from pydwf import DwfLibrary
from pydwf.utilities import openDwfDevice

dwf = DwfLibrary()

with openDwfDevice(dwf) as device:
    swd = device.protocol.swd
    swd.reset()

ProtocolSWD reference

class ProtocolSWD

The ProtocolSWD class provides access to the SWD bus protocol functionality of a DwfDevice.

Attention

Users of pydwf should not create instances of this class directly.

It is instantiated during initialization of a DwfDevice and subsequently accessible via its protocol.swd attribute.

reset() None

Reset the SWD protocol functionality.

Raises:

DwfLibraryError – An error occurred while executing the reset operation.

rateSet(data_rate: float) None

Set the SWD bus data rate, in Hz.

Parameters:

data_rate (float) – The data-rate used by the receiver and transmitter.

Raises:

DwfLibraryError – An error occurred while executing the operation.

clockSet(channel: int) None

Set the SWD clock channel.

Parameters:

channel (int) – The SWD clock channel.

Raises:

DwfLibraryError – An error occurred while executing the operation.

ioSet(channel: int) None

Set the SWD I/O channel.

Parameters:

channel (int) – The SWD I/O channel.

Raises:

DwfLibraryError – An error occurred while executing the operation.

turnSet(turn_setting: int) None

Set the SWD ‘turn’ parameter.

Parameters:

turn_setting (int) – The turn setting.

Raises:

DwfLibraryError – An error occurred while executing the operation.

trailSet(trail_setting: int) None

Set the SWD ‘trail’ parameter.

Parameters:

trail_setting (int) – The trail setting.

Raises:

DwfLibraryError – An error occurred while executing the operation.

parkSet(park_setting: int) None

Set the SWD ‘park_setting’ parameter.

Parameters:

park_setting (int) – The park setting.

Raises:

DwfLibraryError – An error occurred while executing the operation.

nakSet(nak_setting: int) None

Set the SWD ‘nak_setting’ parameter.

Parameters:

nak_setting (int) – The nak setting.

Raises:

DwfLibraryError – An error occurred while executing the operation.

ioIdleSet(io_idle_setting: int) None

Set the SWD ‘I/O idle’ parameter.

Parameters:

io_idle_setting (int) – The I/O idle setting.

Raises:

DwfLibraryError – An error occurred while executing the operation.

clear(reset_value: int, trail_value) None

Clear the SWD bus.

Parameters:
  • reset_value (int) – The reset value.

  • trail_value (int) – The trail value.

Raises:

DwfLibraryError – An error occurred while executing the operation.

write(port: int, a32: int, write_data: int) int

Perform an SWD write.

Parameters:
  • port (int) –

    • 0 — DataPort

    • 1 — AccessPort

  • a32 (int) – Address bits 3:2.

  • write_data – Data to write.

Returns:

Acknowledgement bits: 1=OK, 2=WAIT, 4=FAILURE.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

read(port: int, a32: int) Tuple[int, int, bool]

Perform an SWD read.

Parameters:
  • port (int) –

    • 0 — DataPort

    • 1 — AccessPort

  • a32 (int) – Address bits 3:2.

Returns:

The first element of the tuple is the acknowledgement bits: 1=OK, 2=WAIT, 4=FAILURE.

The second element of the tuple is the data word read. The third element of the tuple indicates if the CRC was correct (parity check).

Return type:

Tuple[int, int, bool]

Raises:

DwfLibraryError – An error occurred while executing the operation.

property device

Return the DwfDevice instance of which we are an attribute.

This is useful if we have a variable that contains a reference to a DwfDevice attribute, but we need the DwfDevice itself.

Returns:

The DwfDevice instance that this attribute belongs to.

Return type:

DwfDevice