Read Memory with SDP Host#

The SDP (Serial Downloader Protocol) used by NXP is a communication protocol designed for programming and debugging NXP microcontrollers via a serial interface. It facilitates the downloading of firmware to the microcontroller’s memory. The protocol typically operates over UART (Universal Asynchronous Receiver-Transmitter) or USB (Universal Serial Bus) and allows for commands to be sent from a host computer to the microcontroller.

SDP is particularly useful in development and production environments for flashing firmware onto devices efficiently and reliably.

Note: Customers have the opportunity to develop their own plugins to extend the functionality of SDP Host.This flexibility enables users to implement unique communication interface. For more info about plugins, read the SPSDK plugins documentation .

1. Prerequisites#

  • SPSDK is needed with examples extension. pip install spsdk[examples] (Please refer to the installation documentation.)

  • Connect your preferred board via UART interface. In this example we will be using mimxrt1050-evk connected via UART

    mimxrt1050-evk

2. Read Memory via API#

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright 2019-2024 NXP
#
# SPDX-License-Identifier: BSD-3-Clause

from typing import Optional

from spsdk.sdp.interfaces.uart import SdpUARTInterface
from spsdk.sdp.sdp import SDP


def read_memory(address: int, length: int, port: Optional[str] = None) -> Optional[bytes]:
    """Read memory using USB interface.

    To see all available device names (and their respective VID:PID):
      spsdk/sdp/interfaces/usb.py -> USB_DEVICES
    If device_name is not specified, function will use first available SDP device.

    :param address: The address in target memory
    :param length: Count of bytes to read
    :param device_name: i.MX-RT device name or VID:PID
    :return: bytes or None
    """
    interfaces = SdpUARTInterface.scan(port=port)
    if interfaces:
        with SDP(interfaces[0]) as sdp:
            return sdp.read(address, length, 8)
    return None


DATA = read_memory(0, 4)
print("Read data:", DATA.hex())
Read data: 89232389

3. Read Memory via CLI#

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright 2024 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
COM_PORT = "COM64"

print("Read data:")
%! sdphost -p $COM_PORT read-register 0 32
Read data:
sdphost -p COM64 read-register 0 32 
89 23 23 89
Status (HAB mode) = 1450735702 (0x56787856) Hab Is Disabled (Unlocked).