DK6 API

Contents

DK6 API#

SPSDK DK6 device programming support.

This module provides functionality for programming and managing DK6 devices within the SPSDK framework, offering reliable provisioning capabilities for NXP’s DK6 device family.

Module with the DK6 commands#

DK6 device communication commands and responses.

This module provides command and response structures for communicating with DK6 devices, including memory operations, device identification, and status management. It defines command packets, response parsing, and various memory access utilities for the DK6 protocol implementation.

class spsdk.dk6.commands.CmdPacket(data)#

Bases: object

DK6 command packet representation.

This class encapsulates command data for DK6 operations, providing methods for packet creation, comparison, serialization, and debugging information.

Initialize the Command Packet object.

Parameters:

data (bytes) – Command data bytes to be stored in the packet.

export()#

Export CmdPacket into bytes.

Return type:

Optional[bytes]

Returns:

Exported object data as bytes, or None if no data is available.

info()#

Get object info.

Returns a string representation of the CMDPacket object showing its data bytes in hexadecimal format.

Return type:

str

Returns:

String representation in format “CMDPacket[XX, XX, …]” where XX are hex bytes.

class spsdk.dk6.commands.CmdResponse(cmd_type, raw_data)#

Bases: object

DK6 command response handler.

This class represents and manages DK6 command responses, providing parsing and formatting capabilities for response data including status codes and raw message content.

Variables:

MSG_OFFSET – Offset position for message data in response buffer.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

MSG_OFFSET = 1#
info()#

Get object info.

Returns a formatted string containing the object’s status, type, and raw data in hexadecimal format.

Return type:

str

Returns:

Formatted string with status, type and raw data in hex format.

class spsdk.dk6.commands.CommandTag(tag, label, description=None)#

Bases: SpsdkEnum

DK6 command enumeration for device communication protocol.

This enumeration defines all supported commands for DK6 device communication, including memory operations, device control, and ISP functionality. Each command contains the command code, internal name, and human-readable description.

EXECUTE = (33, 'ExecuteCommand', 'Execute Command')#
GET_CHIPID = (50, 'GetChipIdCommand', 'Get Chip ID Command')#
MEM_BLANK_CHECK = (68, 'MemBlankCheckCommand', 'Memory Blank Check Command')#
MEM_CLOSE = (74, 'MemoryCloseCommand', 'Memory Close Command')#
MEM_ERASE = (66, 'MemEraseCommand', 'Memory Erase Command')#
MEM_GET_INFO = (76, 'MemoryGetInfoCommand', 'Memory Get Info Command')#
MEM_OPEN = (64, 'MemOpenCommand', 'Memory Open Command')#
MEM_READ = (70, 'MemReadCommand', 'Memory Read Command')#
MEM_WRITE = (72, 'MemoryWriteCommand', 'Memory Write Command')#
RESET = (20, 'ResetCommand', 'Reset Command')#
SET_BAUD = (39, 'SetBaudCommand', 'Set Baud Command')#
UNLOCK_ISP = (78, 'UnlockISPCommand', 'Unlock ISP Command')#
class spsdk.dk6.commands.GenericResponse(cmd_type, raw_data)#

Bases: CmdResponse

DK6 generic response format class.

This class represents a standard response format for DK6 commands, providing a generic structure for handling command responses with status information and formatted output capabilities.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

info()#

Get object info.

Returns a formatted string containing the object’s tag and status information.

Return type:

str

Returns:

Formatted string with tag and status details.

class spsdk.dk6.commands.GetChipIdResponse(cmd_type, raw_data)#

Bases: CmdResponse

DK6 command response for chip identification operations.

This class handles the response data from chip ID retrieval commands, parsing the chip ID and version information from the raw response data.

Variables:

FORMAT – Binary format string for unpacking chip ID and version data.

Initialize the Flash-Read-Once response object.

Creates a response object for Flash-Read-Once command with chip identification data. When status is OK, extracts chip ID and version from the raw response data.

Parameters:
  • cmd_type (int) – Command type identifier for the response

  • raw_data (bytes) – Raw response data containing chip information

FORMAT = '<II'#
info()#

Get object information as formatted string.

Returns a formatted string containing the response tag, status, and optionally chip ID and version information when the status is OK.

Return type:

str

Returns:

Formatted string with object information including tag, status, and chip details.

class spsdk.dk6.commands.IspUnlockResponse(cmd_type, raw_data)#

Bases: CmdResponse

ISP Unlock response format class.

This class represents the response received from an ISP (In-System Programming) unlock command, providing authentication status and response details for secure provisioning operations.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Type of the command

  • raw_data (bytes) – Response data

info()#

Get object info.

Returns a formatted string containing the object’s tag, status, and authentication state.

Return type:

str

Returns:

Formatted string with tag, status, and authenticated information.

class spsdk.dk6.commands.MemBlankCheckResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory blank check response format class.

This class represents the response format for memory blank check operations in DK6 protocol, providing structured access to the response data and status information.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

info()#

Get object info.

Returns formatted string containing tag and status information for the object.

Return type:

str

Returns:

Formatted string with tag and status details.

class spsdk.dk6.commands.MemCloseResponse(cmd_type, raw_data)#

Bases: CmdResponse

DK6 memory close response format class.

This class represents the response format for DK6 memory close operations, providing structured access to response data and status information.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

info()#

Get object info.

Returns formatted string containing tag and status information for the object.

Return type:

str

Returns:

Formatted string with tag and status details.

class spsdk.dk6.commands.MemEraseResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory erase response format class.

This class represents the response format for memory erase operations in DK6 protocol, providing structured access to response data and status information.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

info()#

Get object info.

Returns formatted string containing tag and status information for the object.

Return type:

str

Returns:

Formatted string with tag and status labels.

class spsdk.dk6.commands.MemGetInfoResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory get info response handler for DK6 bootloader commands.

This class processes and parses responses from memory get info commands, extracting memory properties such as base address, length, sector size, memory type, and access permissions when the command executes successfully.

Variables:
  • FORMAT – Binary format string for unpacking response data.

  • MEM_NAME_OFFSET – Byte offset where memory name starts in response.

Initialize the Flash-Read-Once response object.

Parses the raw response data to extract memory information including memory name, ID, base address, length, sector size, type, and access permissions.

Parameters:
  • cmd_type (int) – Command type identifier for the response

  • raw_data (bytes) – Raw response data containing memory information

Raises:

SPSDKError – If response parsing fails or data is corrupted

FORMAT = '<BIIIBB'#
MEM_NAME_OFFSET = 15#
info()#

Get object information as formatted string.

Returns detailed memory information including tag, status, memory name, ID, base address, length, sector size, memory type, and access permissions when status is OK. For non-OK status, returns only tag and status information.

Return type:

str

Returns:

Formatted string containing object information details.

class spsdk.dk6.commands.MemOpenResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory open response handler for DK6 commands.

This class processes and parses responses from memory open operations, extracting the memory handle when the operation is successful and providing formatted information about the response status.

Variables:

FORMAT – Binary format string for unpacking response data.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Type of the command

  • raw_data (bytes) – Response data

Raises:

SPSDKError – If command processing fails

FORMAT = '<B'#
info()#

Get object information as formatted string.

Returns a formatted string containing the response tag, status, and optionally the handle if the status is OK.

Return type:

str

Returns:

Formatted string with object information including tag, status and handle.

class spsdk.dk6.commands.MemReadResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory read response handler for DK6 commands.

This class processes and manages response data from memory read operations, parsing the raw response data and extracting the actual memory content when the operation is successful.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data bytes

info()#

Get object info.

Returns a formatted string containing the response tag, status, and data bytes in hexadecimal format for debugging and logging purposes.

Return type:

str

Returns:

Formatted string with tag label, status label, and hex data.

class spsdk.dk6.commands.MemWriteResponse(cmd_type, raw_data)#

Bases: CmdResponse

Memory write response format class.

This class represents the response format for memory write operations in DK6 protocol, providing structured access to response data and status information.

Initialize the Command Response object.

Parameters:
  • cmd_type (int) – Command type identifier

  • raw_data (bytes) – Raw response data as bytes

Raises:

AssertionError – If raw_data is not bytes or bytearray type

info()#

Get object info.

Returns formatted string containing tag and status information for the object.

Return type:

str

Returns:

Formatted string with tag and status details.

class spsdk.dk6.commands.MemoryAccessValues(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Memory Access Permission Values.

Enumeration defining memory access permission values for DK6 operations. Each value represents a specific type of memory access that can be enabled or disabled for security and operational control.

ALL = (15, 'All is available')#
BLANK_CHECK_ENABLED = (4, 'Blank Check Enabled')#
ERASE = (2, 'Erase Enabled')#
ERASE_ALL = (3, 'Erase All Enabled')#
READ = (0, 'Read Enabled')#
WRITE = (1, 'Write Enabled')#
class spsdk.dk6.commands.MemoryId(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Memory ID enumeration.

This enumeration defines the available memory types and their corresponding identifiers for DK6 device operations including flash programming, configuration access, and memory management operations.

Config = (3, 'Config')#
EFUSE = (4, 'EFUSE')#
FLASH = (0, 'FLASH')#
PSECT = (1, 'PSECT')#
RAM0 = (6, 'RAM0')#
RAM1 = (7, 'RAM1')#
ROM = (5, 'ROM')#
pFLASH = (2, 'pFLASH')#
class spsdk.dk6.commands.MemoryType(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Memory Types enumeration.

This enumeration defines the available memory types for DK6 operations, including ROM, FLASH, RAM, and EFUSE memory types with their corresponding identifiers and descriptions.

EFUSE = (5, 'EFUSE (OTP)', 'EFUSE (OTP)')#
FLASH = (1, 'FLASH', 'FLASH memory')#
RAM = (2, 'RAM', 'RAM')#
ROM = (0, 'ROM', 'Read only memory')#
class spsdk.dk6.commands.ResponseTag(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Response Tag Enumeration.

Enumeration of response tags used in DK6 protocol communication to identify different types of responses from the target device including memory operations, chip identification, and ISP unlock responses.

EXECUTE = (34, 'ExecuteResponse', 'Execute Response')#
GET_CHIPID = (51, 'GetChipIdResponse', 'Get Chip ID Response')#
MEM_BLANK_CHECK = (69, 'MemBlankCheckResponse', 'Memory Blank Check Response')#
MEM_CLOSE = (75, 'MemoryCloseResponse', 'Memory Close Response')#
MEM_ERASE = (67, 'MemEraseResponse', 'Memory Erase Response')#
MEM_GET_INFO = (77, 'MemoryGetInfoResponse', 'Memory Get Info Response')#
MEM_OPEN = (65, 'MemOpenResponse', 'Memory Open Response')#
MEM_READ = (71, 'MemReadResponse', 'Memory Read Response')#
MEM_WRITE = (73, 'MemoryWriteResponse', 'Memory Write Response')#
RESET = (21, 'ResetResponse', 'Reset Response')#
SET_BAUD = (40, 'SetBaudResponse', 'Set Baud Response')#
UNLOCK_ISP = (79, 'UnlockISPResponse', 'Unlock ISP Response')#
class spsdk.dk6.commands.StatusCode(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Command Status Codes enumeration.

This enumeration defines all possible status codes returned by DK6 commands, including success status and various error conditions for memory operations, authentication, and communication failures.

ASSERT_FAIL = (251, 'ASSERT_FAIL', 'Assertion fail')#
AUTH_ERROR = (247, 'AUTH_ERROR', 'Not authorized')#
CRC_ERROR = (252, 'CRC_ERROR', 'CRC Error')#
INVALID_RESPONSE = (253, 'INVALID_RESPONSE', 'Invalid response')#
MEMORY_ACCESS_INVALID = (243, 'MEMORY_ACCESS_INVALID', 'Memory access invalid')#
MEMORY_BAD_STATE = (240, 'MEMORY_BAD_STATE', 'Memory bad state')#
MEMORY_INVALID = (245, 'MEMORY_INVALID', 'Memory invalid')#
MEMORY_INVALID_MODE = (239, 'MEMORY_INVALID_MODE', 'Memory invalid mode')#
MEMORY_NOT_SUPPORTED = (244, 'MEMORY_NOT_SUPPORTED', 'Memory not supported')#
MEMORY_OUT_OF_RANGE = (242, 'MEMORY_OUT_OF_RANGE', 'Memory out of range')#
MEMORY_TOO_LONG = (241, 'MEMORY_TOO_LONG', 'Memory too long')#
NOT_SUPPORTED = (255, 'NOT_SUPPORTED', 'Not supported')#
NO_RESPONSE = (246, 'NO_RESPONSE', 'No response')#
OK = (0, 'OK', 'Success')#
READ_FAIL = (249, 'READ_FAIL', 'Read fail')#
TEST_ERROR = (248, 'TEST_ERROR', 'Test Error')#
USER_INTERRUPT = (250, 'USER_INTERRUPT', 'User interrupt')#
WRITE_FAIL = (254, 'WRITE_FAIL', 'Write fail')#
spsdk.dk6.commands.parse_cmd_response(data, frame_type)#

Parse command response based on frame type.

This method analyzes the frame type and returns the appropriate response object for the given command. It supports various DK6 protocol responses including memory operations, chip identification, and ISP unlock commands.

Parameters:
  • data (bytes) – Raw response data received from the device.

  • frame_type (int) – Frame type identifier that determines response format.

Return type:

Union[CmdResponse, GenericResponse, GetChipIdResponse, MemOpenResponse, MemEraseResponse, MemBlankCheckResponse, MemReadResponse, MemWriteResponse, MemCloseResponse, MemGetInfoResponse, IspUnlockResponse]

Returns:

Parsed response object specific to the command type, or generic CmdResponse if frame type is unknown.

Module representing DK6 device and memories#

SPSDK DK6 device management and communication interface.

This module provides high-level API for interacting with DK6 devices, including device identification, memory operations, and communication management through UART interface.

class spsdk.dk6.dk6device.DK6ChipIdInternal(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Internal chip ID enumeration.

This enumeration defines the internal chip identifiers used by the DK6 provisioning system for supported NXP MCU devices. Each entry contains the chip ID value, short name, and full device description.

JN5189 = (2290649224, 'JN5189', 'JN5189 ESx')#
K32W041 = (318817926, 'K32W041', 'K32W041')#
K32W061 = (339789446, 'K32W061', 'K32W061')#
QN9090 = (306235014, 'QN9090', 'QN9090')#
class spsdk.dk6.dk6device.DK6Device(device)#

Bases: object

DK6 device communication interface.

This class provides a high-level interface for communicating with DK6 devices, encapsulating the underlying serial communication protocol and device management. It handles device initialization, memory operations, and maintains device state including chip information and MAC address.

DK6Device constructor.

Initialize a new DK6Device instance for communication with DK6-compatible devices.

Parameters:

device (SerialDevice) – SerialDevice that will be used for communication with the DK6 device.

add_memory(memory)#

Add memory to the list of available memories.

Parameters:

memory (DK6Memory) – DK6Memory object to be added to the device’s memory collection.

Return type:

None

add_memory_from_response(memory_response)#

Add memory configuration from device memory information response.

This method processes a MemGetInfoResponse and creates a DK6Memory object with the provided memory configuration parameters. The memory is only added if the response status indicates success.

Parameters:

memory_response (MemGetInfoResponse) – Memory information response containing device memory details.

Raises:

No explicit exceptions raised by this method.

Return type:

None

close()#

Close UART device.

Closes the UART connection and resets the initialization state of the device.

Raises:

SPSDKError – When the device cannot be closed.

Return type:

None

erase_memory(memory_id, address, length, access=MemoryAccessValues(tag=15, label='All is available', description=None), progress_callback=None, relative=False, verify=False)#

Erase memory of DK6 device.

The method validates the erase request, opens memory in given access mode, erases data, optionally verifies with blank check, and closes memory. 1. Make a validation of the read request 2. Open memory in given access mode 4. Erase data 5. Optionally verify with blank check 6. Close memory

Parameters:
  • memory_id (MemoryId) – MemoryID of the memory to be used.

  • address (int) – Start address for memory erase operation.

  • length (int) – Length of data to be erased in bytes.

  • access (MemoryAccessValues) – Memory access value, defaults to MemoryAccessValues.ALL.

  • progress_callback (Optional[Callable[[int, int], None]]) – Progress callback function used in CLI, defaults to None.

  • relative (bool) – True if address is relative to the memory base address.

  • verify (bool) – True for erase verification by memory blank check.

Raises:
Return type:

None

get_mac_str()#

Get MAC address in string format.

The method formats the MAC address bytes into a colon-separated hexadecimal string representation. If no MAC address is available, returns “N/A”.

Return type:

str

Returns:

String containing MAC address in format “XX:XX:XX:XX:XX:XX” or “N/A” if not available.

get_memory(memory_id)#

Get DK6Memory based on memory_id.

Parameters:

memory_id (MemoryId) – MemoryId of the desired memory

Raises:

SPSDKError – When the memory cannot be fetched

Return type:

DK6Memory

Returns:

DK6Memory object corresponding to the specified memory ID

init()#

Initialize DK6 device for communication.

This method performs the complete initialization sequence for a DK6 device including ISP unlocking, device information retrieval, memory discovery, MAC address reading, and device type identification. If the device is already initialized, the method will skip the initialization process.

Raises:

SPSDKError – When device communication fails or device type cannot be determined.

Return type:

None

read_memory(memory_id, address, length, access=MemoryAccessValues(tag=1, label='Write Enabled', description=None), progress_callback=None, relative=False)#

Read memory from the DK6 device.

The method performs memory reading operation by validating the request, opening memory in specified access mode, splitting the request into chunks based on maximum payload size, reading data sequentially, and closing the memory connection.

  1. Make a validation of the read request

  2. Open memory in given access mode

  3. Split read request to chunks of max(MAX_PAYLOAD_SIZE, requested_len)

  4. Read data

  5. Close memory

Parameters:
  • memory_id (MemoryId) – Memory identifier specifying which memory to access.

  • address (int) – Starting address for the read operation.

  • length (int) – Number of bytes to read from memory.

  • access (MemoryAccessValues) – Memory access mode for the operation.

  • progress_callback (Optional[Callable[[int, int], None]]) – Optional callback function to report reading progress.

  • relative (bool) – Whether address is relative to memory base address.

Raises:
Return type:

bytes

Returns:

Read data as bytes.

reset()#

Reset the device.

This method performs a device reset operation through the protocol interface and validates the operation was successful.

Raises:

SPSDKError – When the reset operation fails.

Return type:

None

set_baud_rate(baudrate)#

Set baud rate for the DK6 device communication.

Parameters:

baudrate (int) – The baud rate value to set for serial communication.

Return type:

None

write_memory(memory_id, address, length, data, access=MemoryAccessValues(tag=15, label='All is available', description=None), progress_callback=None, relative=False)#

Write memory to the DK6 device.

The method performs memory write operation by validating the request, opening memory in given access mode, splitting write request to chunks, writing data, and closing memory.

  1. Make a validation of the read request

  2. Open memory in given access mode

  3. Split write request to chunks of max(MAX_PAYLOAD_SIZE, requested_len)

  4. Write data

  5. Close memory

Parameters:
  • memory_id (MemoryId) – Memory ID of the memory to be used.

  • address (int) – Start address for writing data.

  • length (int) – Length of data to be written.

  • data (bytes) – Data bytes to be written to memory.

  • access (MemoryAccessValues) – Memory access mode, defaults to MemoryAccessValues.ALL.

  • progress_callback (Optional[Callable[[int, int], None]]) – Optional callback function for progress reporting.

  • relative (bool) – True if address is relative to the memory base address.

Raises:
Return type:

None

class spsdk.dk6.dk6device.DK6DeviceId(tag, label, description=None)#

Bases: SpsdkEnum

DK6 Device ID enumeration for supported NXP devices.

This enumeration defines the supported device identifiers for the DK6 (Development Kit 6) family of NXP microcontrollers, including JN51xx, QN90xx, and K32W0xx series devices.

JN5188 = (5188, 'JN5188')#
JN5189 = (5189, 'JN5189')#
K32W041 = (32041, 'K32W041')#
K32W061 = (32061, 'K32W061')#
QN9030 = (9030, 'QN9030')#
QN9090 = (9090, 'QN9090')#
UNKNOWN = (0, 'UNKNOWN')#
class spsdk.dk6.dk6device.DK6Memory(base_address, length, sector_size, mem_type, mem_name, mem_id, access)#

Bases: object

DK6 memory region descriptor.

This class represents a memory region in DK6 devices, encapsulating all properties and characteristics of a specific memory area including its location, size, type, and access permissions.

Initialize DK6Memory instance with memory configuration parameters.

Parameters:
  • base_address (int) – Base address where the memory region starts.

  • length (int) – Total size of the memory region in bytes.

  • sector_size (int) – Size of individual memory sector in bytes.

  • mem_type (MemoryType) – Type of memory (e.g., flash, RAM).

  • mem_name (str) – Human-readable name identifier for the memory.

  • mem_id (MemoryId) – Unique identifier for the memory region.

  • access (MemoryAccessValues) – Memory access permissions and capabilities.

property end_address: int#

Calculate the end address of the memory region.

The end address is computed by adding the base address and the length of the memory region.

Returns:

The end address of the memory region.

spsdk.dk6.dk6device.check_memory(memory, access, length, relative, address)#

Check memory range and return sanitized address value.

Validates memory access permissions, address ranges, and converts relative addresses to absolute addresses when needed.

Parameters:
  • memory (DK6Memory) – DK6Memory object containing memory configuration and access permissions.

  • access (MemoryAccessValues) – Memory access type to be validated against allowed operations.

  • length (int) – Length of data in bytes to be accessed.

  • relative (bool) – True if address is relative to memory base address, False for absolute.

  • address (int) – Memory address (relative or absolute based on relative parameter).

Raises:
  • SPSDKError – If memory ID is not supported.

  • SPSDKError – If access type is not allowed for this memory.

  • SPSDKError – If the memory range is invalid or out of bounds.

Return type:

int

Returns:

Sanitized absolute memory address.

Module representing drivers for communication#

DK6 driver backend interface for device communication.

This module provides the core driver infrastructure for DK6 devices, including backend abstraction, device information handling, and communication interfaces. It supports multiple backend types and provides utilities for device discovery and connection management.

class spsdk.dk6.driver.Backend(value)#

Bases: Enum

Backend enumeration for DK6 driver communication interfaces.

This enumeration defines the available backend drivers that can be used for communication with DK6 devices, including FTDI-based drivers and serial communication options.

FTD2xx = 3#
PYFTDI = 1#
PYLIBFTDI = 2#
PYSERIAL = 4#
class spsdk.dk6.driver.DeviceInfo(device_id, vid, pid, sn, description, address, backend)#

Bases: object

Device information container for DK6 connected devices.

This class encapsulates essential information about a connected device including USB identifiers, serial number, description, address, and backend interface. It provides a structured way to store and access device metadata for DK6 operations and device management.

Initialize device information object.

Creates a new device information instance with USB connection details, serial number, and backend configuration for SPSDK communication.

Parameters:
  • device_id (Union[str, int]) – Unique identifier for the device, either string or integer format.

  • vid (int) – USB Vendor ID for device identification.

  • pid (int) – USB Product ID for device identification.

  • sn (str) – Serial number string for unique device identification.

  • description (str) – Human-readable description of the device.

  • address (int) – Physical or logical address of the device.

  • backend (Backend) – Communication backend instance for device operations.

class spsdk.dk6.driver.DriverInterface(backend)#

Bases: object

FTDI driver interface for DK6 communication.

This class provides a unified interface to multiple FTDI backend libraries (pyftdi, pylibftdi, and ftd2xx) enabling communication with DK6 devices through different driver implementations.

Initialize driver interface and serial interface based on backend.

Sets up the appropriate FTDI driver backend (PYFTDI, PYLIBFTDI, or FTD2xx) for DK6 communication. Initializes driver and device objects based on the selected backend.

Parameters:

backend (Backend) – Backend type to use for FTDI communication.

Raises:

SPSDKError – When required backend package is not installed or underlying library is missing.

get_serial()#

Get serial device.

Retrieves the initialized serial device instance used for communication.

Raises:

SPSDKError – If serial device is not initialized.

Return type:

SerialDevice

Returns:

Serial device based on backend.

go_to_isp(device_id)#

Send a sequence that goes to ISP mode using FTDI bitbang device.

The method sends a predefined sequence of bitbang commands to put the target device into In-System Programming (ISP) mode. It supports both PyFTDI and FTD2xx backends for FTDI device communication.

Parameters:

device_id (str) – Device identifier for the FTDI device to use for ISP sequence.

Raises:
  • AssertionError – If driver is not properly initialized for PyFTDI backend.

  • ImportError – If required FTDI library is not available.

Return type:

None

init_serial(device_id, baudrate=115200, timeout=5000)#

Initialize serial device.

Configures and establishes connection to a serial device using the specified backend. The method supports multiple backends including PYFTDI, PYLIBFTDI, FTD2xx, and PYSERIAL.

Parameters:
  • device_id (str) – Device identifier (format depends on backend type)

  • baudrate (int) – UART baudrate for communication, defaults to 115200

  • timeout (int) – Read and write timeout in milliseconds, defaults to 5000 ms

Raises:

SPSDKError – If invalid device_id is provided or device initialization fails

Return type:

None

list_devices()#

List connected DK6 devices for the selected backend.

Enumerates and returns information about all DK6 devices that are currently connected and accessible through the configured backend (PYFTDI, FTD2xx, or PYSERIAL).

Return type:

list[DeviceInfo]

Returns:

List of DeviceInfo objects containing device details such as ID, VID, PID, serial number, description, and address for each connected device.

set_baud_rate(baudrate)#

Set baud rate for the UART communication.

The method configures the baud rate for different backend implementations including PYFTDI, PYLIBFTDI, FTD2xx, and PYSERIAL. If the device is not initialized, the operation is skipped with an error log.

Parameters:

baudrate (int) – UART baud rate value to be set.

Return type:

None

spsdk.dk6.driver.DriverType#

alias of (<class ‘pyftdi.ftdi.Ftdi’>, <class ‘pylibftdi.driver.Driver’>, ftd2xx.FTD2XX, <class ‘serial.serialposix.Serial’>)

spsdk.dk6.driver.generate_pyftdi_url(serial_number, address=1)#

Generates URL for PyFTDI from serial number.

Parameters:
  • serial_number (str) – Serial number from USBDeviceDescriptor.

  • address (int) – Interface number, defaults to 1.

Return type:

str

Returns:

URL string for PyFTDI connection.

Module representing communication interface#

SPSDK DK6 UART communication interface.

This module provides low-level UART communication functionality for DK6 devices, including packet transmission, CRC calculation, and response parsing utilities.

class spsdk.dk6.interface.Uart(device)#

Bases: object

UART communication interface for DK6 devices.

This class provides a high-level interface for UART communication with DK6 devices, handling frame-based protocol operations including reading, writing, and managing connection state through an underlying serial device.

Variables:
  • FRAME_START_BYTE – Start byte marker for frame protocol.

  • HEADER_SIZE – Total size of the frame header in bytes.

Initialize the UART interface.

Parameters:

device (SerialDevice) – Serial device instance for communication.

Raises:

McuBootConnectionError – When the device could not be opened.

CHECKSUM_SIZE = 4#
FLAG_SIZE = 1#
FRAME_START_BYTE = 0#
FRAME_TYPE_SIZE = 1#
HEADER_SIZE = 8#
LENGTH_SIZE = 2#
static calc_frame_crc(data, frame_type)#

Calculate the CRC of a frame.

The method constructs frame data with header information and calculates CRC checksum for UART communication protocol.

Parameters:
  • data (Optional[bytes]) – Frame payload data, None for frames without payload.

  • frame_type (Union[int, CommandTag]) – Frame type identifier as integer or CommandTag enum.

Return type:

int

Returns:

Calculated CRC checksum as integer value.

close()#

Close the UART interface.

Raises:

SPSDKError – In any case of fail of UART close operation.

Return type:

None

static create_frame(data, frame_type)#

Encapsulate data into frame for UART communication.

Creates a properly formatted frame with start byte, length, frame type, payload data, and CRC checksum for secure transmission.

Parameters:
  • data (Optional[bytes]) – Payload data to be encapsulated, None for frames without payload.

  • frame_type (Union[int, CommandTag]) – Frame type identifier as integer or CommandTag enum.

Return type:

bytes

Returns:

Complete frame as bytes ready for transmission.

property is_opened: bool#

Check device connection status.

Returns:

True if device is open and connected, False otherwise.

open()#

Open the UART interface.

Raises:

SPSDKError – In any case of fail of UART open operation.

Return type:

None

read()#

Read data from device.

Reads and parses a complete frame from the device, including validation of frame structure and CRC checksum.

Return type:

Any

Returns:

Parsed command response object.

Raises:
  • SPSDKError – Did not receive correct frame start byte.

  • SPSDKError – When received invalid CRC.

write(frame_type, packet)#

Write data to the device.

Data might be in form of ‘CmdPacket’ or bytes. The method automatically converts CmdPacket objects to bytes before sending.

Parameters:
  • frame_type (CommandTag) – Command tag specifying the type of frame to create.

  • packet (Union[CmdPacket, bytes, None]) – Packet data to send, can be CmdPacket object, bytes, or None.

Raises:

AttributeError – Frame type is incorrect.

Return type:

None

spsdk.dk6.interface.calc_crc(data)#

Calculate CRC from the data.

The method uses CRC32 algorithm to compute the checksum value for the provided data.

Parameters:

data (bytes) – Data bytes to calculate CRC from.

Return type:

int

Returns:

Calculated CRC32 checksum as integer value.

spsdk.dk6.interface.to_int(data, little_endian=False)#

Convert bytes into single integer.

Parameters:
  • data (bytes) – Bytes to convert into integer.

  • little_endian (bool) – Indicate byte ordering in data, defaults to False for big endian.

Return type:

int

Returns:

Converted integer value.

Module representing communication protocol#

SPSDK DK6 communication protocol implementation.

This module provides the core communication protocol for DK6 devices, including ISP mode handling and low-level command/response processing.

class spsdk.dk6.protocol.DK6Protocol(device)#

Bases: object

DK6 communication protocol handler.

This class provides a high-level interface for communicating with DK6 devices over UART, implementing the complete protocol for device operations including ISP unlocking, memory operations, and device information retrieval.

Variables:

MAX_PAYLOAD_SIZE – Maximum payload size supported by device buffer.

Initialize DK6Protocol with UART device.

Parameters:

device (Uart) – Serial device that will be used for communication.

MAX_PAYLOAD_SIZE = 512#
execute(address)#

Execute code at specified memory address.

This command executes (runs) code in flash or RAM. The response is sent before execution jumps to the provided address.

Parameters:

address (int) – Memory address to start execution from.

Return type:

GenericResponse

Returns:

Generic response from the device.

get_device_information()#

Get device information from the connected device.

Retrieves chip identification and ROM version information by sending a GET_CHIPID command to the device via UART communication.

Return type:

GetChipIdResponse

Returns:

GetChipIdResponse containing chip ID and chip (ROM) version information.

mem_blank_check(address, length, handle=0, mode=0)#

Check if a region of the selected memory has been erased.

This command verifies whether the specified memory region is in an erased state by performing a blank check operation on the target memory area.

Parameters:
  • address (int) – Start address of the memory region to check.

  • length (int) – Number of bytes to check for blank state.

  • handle (int) – Handle returned by open memory command, defaults to 0.

  • mode (int) – Blank check mode, defaults to 0.

Return type:

MemBlankCheckResponse

Returns:

MemBlankCheckResponse object containing the result of the blank check operation.

mem_close(handle=0)#

Close the memory and finalize writing operations.

This method sends a memory close command to finalize any pending write operations and properly close the memory handle that was previously opened.

Parameters:

handle (int) – Memory handle returned by open memory command, defaults to 0

Return type:

MemCloseResponse

Returns:

Response object containing the result of the memory close operation

mem_erase(address, length, handle=0, mode=0)#

Erase a region of the selected memory.

This command sends a memory erase request to the target device through UART communication.

Parameters:
  • address (int) – Start address of the memory region to erase.

  • length (int) – Number of bytes to be erased from the specified address.

  • handle (int) – Handle returned by open memory command, defaults to 0.

  • mode (int) – Erase mode specification, defaults to 0.

Return type:

MemEraseResponse

Returns:

Memory erase response containing operation status and details.

mem_get_info(memory_id=MemoryId(tag=0, label='FLASH', description=None))#

Get memory information for the specified memory ID.

Retrieves detailed memory information such as size, length, and other properties for the given memory identifier through the DK6 protocol.

Parameters:

memory_id (Union[MemoryId, int]) – Memory identifier to query information for.

Return type:

MemGetInfoResponse

Returns:

Memory information response containing size, length and other properties.

mem_open(memory_id=MemoryId(tag=0, label='FLASH', description=None), access=MemoryAccessValues(tag=1, label='Write Enabled', description=None))#

Open given memory in the specified access mode.

The method prepares and sends a memory open command packet to the target device and returns the response containing the memory handle.

Parameters:
  • memory_id (MemoryId) – Memory that will be opened, defaults to MemoryId.FLASH

  • access (MemoryAccessValues) – Access mode for the memory, defaults to MemoryAccessValues.WRITE

Return type:

MemOpenResponse

Returns:

MemOpenResponse containing the memory handle

mem_read(address, length, handle=0, mode=0)#

Read data from memory at specified address.

Reads a block of memory data from the target device using the specified handle and mode parameters.

Parameters:
  • address (int) – Start address to read from.

  • length (int) – Number of bytes to read.

  • handle (int) – Memory handle returned by mem_open operation.

  • mode (int) – Memory read mode to use.

Return type:

MemReadResponse

Returns:

MemReadResponse object containing the read data.

mem_write(address, length, data, handle=0, mode=0)#

Write data to memory at specified address.

This method writes the provided data to the target memory location using the DK6 protocol communication interface.

Parameters:
  • address (int) – Start address where data will be written.

  • length (int) – Number of bytes to be written.

  • data (bytes) – Binary data to be written to memory.

  • handle (int) – Memory handle returned by open memory command, defaults to 0.

  • mode (int) – Write operation mode, defaults to 0.

Return type:

MemWriteResponse

Returns:

Memory write response containing operation status.

reset()#

Reset the device.

Sends a reset command to the device via UART communication and waits for the response.

Return type:

GenericResponse

Returns:

Response from the device after reset command execution.

set_baud_rate(baudrate)#

Set the UART communication baud rate.

This method configures the baud rate for UART communication by sending a SET_BAUD command packet to the device and waiting for the change to take effect.

Parameters:

baudrate (int) – The baud rate value to be set for UART communication.

Return type:

None

unlock_isp(mode=IspMode(tag=1, label='start_isp', description='Start ISP Functionality'), key=b'\\x11"3DUfw\\x88\\x11"3DUfw\\x88')#

Unlock ISP (In-System Programming) mode with authentication key.

The method sends an unlock command to enable ISP functionality on the target device. If no key is provided, the default authentication key will be used.

Parameters:
  • mode (IspMode) – ISP unlock mode specifying the operation type

  • key (bytes) – Authentication key for ISP unlock, either default or signed unlock key

Return type:

IspUnlockResponse

Returns:

Response object containing the unlock operation result

unlock_isp_default()#

Unlock ISP sequence in default mode.

Sends the unlock ISP command sequence using default mode, which restricts functionality to only allow the Get device info command to work.

Return type:

IspUnlockResponse

Returns:

Response object containing the unlock operation result.

class spsdk.dk6.protocol.IspMode(tag, label, description=None)#

Bases: SpsdkEnum

DK6 ISP (In-System Programming) mode enumeration.

This enumeration defines the available ISP modes for DK6 protocol operations, including default mode, ISP functionality control, and device unlock operations.

DEFAULT = (0, 'default', 'Default')#
EXTENDED_ISP_UNLOCK = (128, 'extend_unlock', 'Extended unlock')#
START_ISP = (1, 'start_isp', 'Start ISP Functionality')#
UNLOCK_DEVICE = (127, 'unlock_device', 'Unlock device')#