MBoot Interfaces

Module implementing the Mboot communication protocol.

MBoot UART

Module for serial communication with a target device using MBoot protocol.

spsdk.mboot.interfaces.uart.scan_uart(port=None, baudrate=None, timeout=None)

Scan connected serial ports.

Returns list of serial ports with devices that respond to PING command. If ‘port’ is specified, only that serial port is checked If no devices are found, return an empty list.

Parameters
  • port (Optional[str]) – name of preferred serial port, defaults to None

  • baudrate (Optional[int]) – speed of the UART interface, defaults to 56700

  • timeout (Optional[int]) – timeout in milliseconds, defaults to 5000

Return type

List[Interface]

Returns

list of interfaces responding to the PING command

spsdk.mboot.interfaces.uart.calc_crc(data)

Calculate CRC from the data.

Parameters

data (bytes) – data to calculate CRC from

Return type

int

Returns

calculated CRC

spsdk.mboot.interfaces.uart.to_int(data, little_endian=True)

Convert bytes into single integer.

Parameters
  • data (bytes) – bytes to convert

  • little_endian (bool) – indicate byte ordering in data, defaults to True

Return type

int

Returns

integer

spsdk.mboot.interfaces.uart.PROTOCOL_VERSION = <Struct>

Version of protocol used in serial communication

spsdk.mboot.interfaces.uart.PING_RESPONSE = <Struct>

Type of frame used for pig response

class spsdk.mboot.interfaces.uart.FPType

Bases: spsdk.utils.easy_enum.Enum

Type of frames used in serial communication.

ACK = 161
NACK = 162
ABORT = 163
CMD = 164
DATA = 165
PING = 166
PINGR = 167
class spsdk.mboot.interfaces.uart.Uart(port=None, baudrate=57600, timeout=5000)

Bases: spsdk.mboot.interfaces.base.Interface

UART interface.

Initialize the UART interface.

Parameters
  • port (Optional[str]) – name of the serial port, defaults to None

  • baudrate (int) – baudrate of the serial port, defaults to 57600

  • timeout (int) – read/write timeout in milliseconds, defaults to 2000

Raises

McuBootConnectionError – when the port could not be opened

FRAME_START_BYTE = 90
property is_opened

Return True if device is open, False othervise.

Return type

bool

open()

Open the UART interface.

Raises

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

Return type

None

close()

Close the UART interface.

Raises

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

Return type

None

info()

Return information about the UART interface.

Return type

str

Returns

Description of UART interface

Raises

McuBootConnectionError – When no port is available

read()

Read data from device.

Return type

Union[CmdResponse, bytes]

Returns

read data

Raises
write(packet)

Write data to the device; data might be in form of ‘CmdPacket’ or bytes.

Parameters

packet (Union[CmdPacket, bytes]) – Packet to send

Return type

None

ping()

Ping the target device, retrieve protocol version.

Raises
Return type

None

MBoot USB

Module for serial communication with a target device using MBoot protocol.

spsdk.mboot.interfaces.usb.scan_usb(device_name=None)

Scan connected USB devices.

Parameters

device_name (Optional[str]) – see USBDeviceFilter classes constructor for usb_id specification

Return type

Sequence[Interface]

Returns

list of matching RawHid devices

class spsdk.mboot.interfaces.usb.RawHid

Bases: spsdk.mboot.interfaces.base.Interface

Base class for OS specific RAW HID Interface classes.

Initialize the USB interface object.

property name

Get the name of the device.

Return type

str

Returns

Name of the device.

property is_opened

Indicates whether device is open.

Return type

bool

Returns

True if device is open, False othervise.

info()

Return information about the USB interface.

Return type

str

open()

Open the interface.

Raises
Return type

None

close()

Close the interface.

Raises
Return type

None

write(packet)

Write data on the OUT endpoint associated to the HID interfaces.

Parameters

packet (Union[CmdPacket, bytes]) – Data to send

Raises
Return type

None

read()

Read data on the IN endpoint associated to the HID interface.

Return type

Union[CmdResponse, bytes]

Returns

Return CmdResponse object.

Raises
static enumerate(usb_device_filter)

Get list of all connected devices matching the USBDeviceFilter object.

Parameters

usb_device_filter (USBDeviceFilter) – USBDeviceFilter object

Return type

Sequence[Interface]

Returns

List of interfaces found

MBoot USBSIO

Module for USB-SIO communication with a target device using MBoot protocol.

spsdk.mboot.interfaces.usbsio.scan_usbsio(config=None)

Scan connected USB-SIO bridge devices.

Parameters

config (Optional[str]) – configuration string identifying spi or i2c SIO interface

Return type

List[Interface]

Returns

list of matching RawHid devices

Raises

SPSDKError – When libusbsio library error or if no bridge device found

class spsdk.mboot.interfaces.usbsio.UsbSio(config=None)

Bases: spsdk.mboot.interfaces.uart.Uart

USBSIO general interface, base class for SPI or I2C communication over LIBUSBSIO.

This class inherits from Uart communication as the SPI/I2C protocol is the same. The Uart’s read and write methods are leveraged. The low-level _read and _write methods are overridden.

Initialize the Interface object.

property is_opened

Indicates whether interface is open.

Return type

bool

info()

Return string containing information about the interface.

Return type

str

class spsdk.mboot.interfaces.usbsio.UsbSioSPI(config=None, port=0, ssel_port=0, ssel_pin=15, speed_khz=1000, cpol=1, cpha=1)

Bases: spsdk.mboot.interfaces.usbsio.UsbSio

USBSIO SPI interface.

Initialize the UsbSioSPI Interface object.

Parameters
  • config (Optional[str]) – configuration string passed from command line

  • port (int) – default SPI port to be used, typically 0 as only one port is supported by LPCLink2/MCULink

  • ssel_port (int) – bridge GPIO port used to drive SPI SSEL signal

  • ssel_pin (int) – bridge GPIO pin used to drive SPI SSEL signal

  • speed_khz (int) – SPI clock speed in kHz

  • cpol (int) – SPI clock polarity mode

  • cpha (int) – SPI clock phase mode

Raises

SPSDKError – When port configuration cannot be parsed

open()

Open the interface.

Return type

None

close()

Close the interface.

Return type

None

class spsdk.mboot.interfaces.usbsio.UsbSioI2C(config=None, port=0, address=16, speed_khz=100)

Bases: spsdk.mboot.interfaces.usbsio.UsbSio

USBSIO I2C interface.

Initialize the UsbSioI2C Interface object.

Parameters
  • config (Optional[str]) – configuration string passed from command line

  • port (int) – default I2C port to be used, typically 0 as only one port is supported by LPCLink2/MCULink

  • address (int) – I2C target device address

  • speed_khz (int) – I2C clock speed in kHz

Raises

SPSDKError – When port configuration cannot be parsed

open()

Open the interface.

Return type

None

close()

Close the interface.

Return type

None

MBoot Interface Class

Module for functionality shared across all MBoot interfaces.

class spsdk.mboot.interfaces.base.Interface(reopen=False)

Bases: abc.ABC

Base class for all Mboot Interface classes.

Initialize the Interface object.

Parameters

reopen (bool) – Reopen the interface after reset, defaults to False

close()

Close the interface.

Return type

None

info()

Return string containing information about the interface.

Return type

str

property is_opened

Indicates whether interface is open.

Return type

bool

property need_data_split

Indicates whether device need to split data into smaller chunks.

Return type

bool

open()

Open the interface.

Return type

None

read()

Read data from the device.

Return type

Union[CmdResponse, bytes]

write(packet)

Write a packet to the device.

Return type

None