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 Nonebaudrate (
Optional
[int
]) – speed of the UART interface, defaults to 56700timeout (
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 convertlittle_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 Nonebaudrate (
int
) – baudrate of the serial port, defaults to 57600timeout (
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
McuBootDataAbortError – Indicates data transmission abort
McuBootConnectionError – When received invalid CRC
-
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
McuBootConnectionError – If the target device doesn’t respond to ping
McuBootConnectionError – If the start frame is not received
McuBootConnectionError – If the header is invalid
McuBootConnectionError – If the frame type is invalid
McuBootConnectionError – If the ping response is not received
McuBootConnectionError – If crc does not match
- 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
McuBootConnectionError – if no device is available
McuBootConnectionError – if the device can not be opened
- Return type
None
-
close
()¶ Close the interface.
- Raises
McuBootConnectionError – if no device is available
McuBootConnectionError – if the device can not be opened
- 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
McuBootError – Raises an error if packet type is incorrect
McuBootConnectionError – Raises an error if device is not openned for writing
McuBootConnectionError – Raises an error if device is not available
McuBootConnectionError – Raises an error if write operation fails
McuBootDataAbortError – May happen when ROM rejects SB file in shortenned evaluation
- 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
McuBootConnectionError – Raises an error if device is not openned for reading
McuBootConnectionError – Raises if device is not available
McuBootConnectionError – Raises if reading fails
TimeoutError – Time-out
-
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
-
property
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