Memory Configuration API#

SPSDK Memory Configuration utilities.

This module provides functionality for configuring and managing memory settings across NXP MCU devices, including memory layout definitions and configuration validation.

Memory Config API#

SPSDK Memory configuration management utilities.

This module provides functionality for handling memory configuration options, including flash configuration option words and memory interface management across NXP MCU portfolio.

class spsdk.memcfg.memcfg.Memory(name, type, manufacturer, interfaces)#

Bases: object

Memory configuration representation for SPSDK operations.

This class represents a memory device with its properties and supported interfaces, providing methods to query and access available communication interfaces.

get_interface(interface)#

Get interface by its name.

Parameters:

interface (str) – Interface name to search for.

Raises:

SPSDKValueError – Interface is not presented in memory.

Return type:

MemoryInterface

Returns:

Memory interface object.

has_interface(interface)#

Check if memory has mentioned interface.

Parameters:

interface (str) – Interface name to check for existence.

Return type:

bool

Returns:

True if interface exists, False otherwise.

interfaces: list[MemoryInterface]#
manufacturer: str#
name: str#
type: str#
class spsdk.memcfg.memcfg.MemoryConfig(family, peripheral, interface=None)#

Bases: FeatureBaseClass

SPSDK Memory Configuration Manager.

This class manages memory configuration for NXP MCU peripherals, providing functionality to configure memory interfaces, validate settings, and generate configuration data for various memory types across the supported MCU families.

Variables:
  • FEATURE – Database feature identifier for memory configuration.

  • PERIPHERALS – List of supported peripheral names across all families.

  • SUPPORTS_FCB_CREATION – List of region numbers that support FCB creation.

Initialize memory configuration class.

Initialize the memory configuration for a specific chip family and peripheral, setting up registers and validating the memory interface.

Parameters:
  • family (FamilyRevision) – Chip family and revision information.

  • peripheral (str) – Name of the peripheral to configure.

  • interface (Optional[str]) – Memory interface to use. If None, uses the first supported interface.

Raises:
FEATURE: str = 'memcfg'#
PERIPHERALS: list[str] = ['flexspi_nor', 'xspi_nor', 'flexspi_nand', 'semc_nor', 'semc_nand', 'spi_nor', 'mmc', 'emmc', 'sd']#
SUPPORTS_FCB_CREATION = [9]#
create_blhost_batch_config(instance=None, fcb_output_name=None, secure_addresses=False)#

Create BLHOST script that configures memory.

Optionally the script can force creation of FCB on chip and read it back.

Parameters:
  • instance (Optional[int]) – Optional peripheral instance number for runtime switching

  • fcb_output_name (Optional[str]) – Name of the generated FCB block file for readback

  • secure_addresses (bool) – Use secure addresses instead of normal addresses

Raises:
Return type:

str

Returns:

BLHOST batch script content that configures the external memory

export()#

Export option words to bytes.

Return type:

bytes

Returns:

Binary representation of the option words.

get_config(data_path='./')#

Create memory configuration object.

The method generates a configuration dictionary containing family information, peripheral settings, interface details, and register configurations up to the maximum option words count.

Parameters:

data_path (str) – Path to store the data files of configuration.

Return type:

Config

Returns:

Configuration object with memory settings.

classmethod get_config_template(family, peripheral='Unknown', interface=None)#

Get feature configuration template.

Generates a configuration template for the specified MCU family and peripheral, which can be used as a starting point for memory configuration.

Parameters:
  • family (FamilyRevision) – The MCU family name and revision information.

  • peripheral (str) – Name of the peripheral to generate template for.

  • interface (Optional[str]) – Memory interface type, if applicable.

Return type:

str

Returns:

Template file string representation.

static get_known_chip_memory(chip_name)#

Get Memory for one chip from database.

Retrieves the Memory object for a specific chip by searching through the known memory configurations in the database.

Parameters:

chip_name (str) – Name of the chip to search for in the memory database.

Raises:

SPSDKValueError – If the specified chip name is not found in database.

Return type:

Memory

Returns:

Memory object containing configuration for the specified chip.

static get_known_memories(mem_type=None, interfaces=None)#

Get all known supported memory configurations.

Loads memory configuration data from the database and filters based on specified memory type and interfaces.

Parameters:
  • mem_type (Optional[str]) – Restrict results just for this one memory type if defined.

  • interfaces (Optional[list[str]]) – Restrict results just for mentioned memory interfaces if defined.

Return type:

list[Memory]

Returns:

List of Memory objects containing supported memory configurations.

static get_known_peripheral_memories(family, peripheral=None, validate_option_words=True)#

Get all known supported memory configurations.

This method retrieves memory configurations based on the specified family and peripheral. It can optionally validate that option words for the memories can be properly parsed.

Parameters:
  • family (Optional[FamilyRevision]) – The optional chip family to filter memories for.

  • peripheral (Optional[str]) – Restrict results just for this one peripheral if defined.

  • validate_option_words (bool) – If True, validate that option words can be parsed.

Raises:

SPSDKValueError – In case the family does not support external memories.

Return type:

list[Memory]

Returns:

List of supported memory configurations.

static get_peripheral_cnt(family, peripheral)#

Get count of peripheral instances for specified family and peripheral type.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information.

  • peripheral (str) – Name of the peripheral type to count instances for.

Return type:

int

Returns:

Number of available instances for the specified peripheral.

static get_peripheral_instances(family, peripheral)#

Get peripheral instances for a specific family and peripheral type.

Retrieves the list of available instances for a given peripheral from the memory configuration database.

Parameters:
  • family (FamilyRevision) – Target MCU family and revision information.

  • peripheral (str) – Name of the peripheral to get instances for.

Return type:

list[int]

Returns:

List of peripheral instance numbers available for the specified family and peripheral.

static get_supported_interfaces(family, peripheral)#

Get list of supported interfaces by the peripheral for the family.

Retrieves the available communication interfaces that can be used with a specific peripheral on the given MCU family.

Parameters:
  • family (FamilyRevision) – MCU family and revision specification.

  • peripheral (str) – Name of the peripheral to query interfaces for.

Return type:

list[str]

Returns:

List of supported interface names for the specified peripheral.

static get_supported_peripherals(family)#

Get list of supported peripherals by the family.

The method retrieves all peripherals that have at least one instance configured for the specified family from the memory configuration database.

Parameters:

family (FamilyRevision) – Family revision to get supported peripherals for.

Return type:

list[str]

Returns:

List of peripheral names that are supported by the family.

classmethod get_validation_schemas(family, peripheral='Unknown', interface=None)#

Create the validation schema for one peripheral.

The method builds validation schemas by combining family, base configuration, and settings schemas. It updates the schemas with supported peripherals and interfaces for the given family and configures the settings schema using StrictRegisters.

Parameters:
  • family (FamilyRevision) – The MCU family revision identifier.

  • peripheral (str) – Name of the peripheral to create validation schema for.

  • interface (Optional[str]) – Memory interface type, optional parameter.

Return type:

list[dict[str, Any]]

Returns:

List containing family, base, and settings validation schemas.

static get_validation_schemas_basic()#

Get validation schemas for MemCfg class basic configuration.

The method retrieves and combines validation schemas for family configuration and base memory configuration settings. It updates the family schema with currently supported families from MemoryConfig.

Return type:

list[dict[str, Any]]

Returns:

List containing family and base configuration validation schemas.

classmethod get_validation_schemas_from_cfg(config)#

Get validation schemas based on configuration.

This method validates the provided configuration against basic schemas and creates a memory configuration instance to retrieve the appropriate validation schemas.

Parameters:

config (Config) – Valid configuration object containing family and peripheral settings

Return type:

list[dict[str, Any]]

Returns:

List of validation schema dictionaries for the memory configuration

Raises:

SPSDKError – If configuration validation fails

classmethod load_from_config(config)#

Load memory configuration object from configuration.

The method creates a new memory configuration instance by extracting family, peripheral, and interface information from the provided configuration, then loads register settings into the configuration object.

Parameters:

config (Config) – Configuration dictionary containing memory setup parameters.

Return type:

Self

Returns:

Initialized memory configuration object with loaded settings.

property option_words: list[int]#

Get option words from memory configuration registers.

Retrieves the values of option words by iterating through the available registers up to the specified count limit.

Returns:

List of option word values as integers.

property option_words_count: int#

Get current count of option words.

Determines the number of option words based on the peripheral’s configuration rule. The count is calculated using different strategies depending on the rule type: - “All”: Returns total number of registers - “OptionSize”: Returns 1 plus the OptionSize bitfield value - “AcTimingMode”: Returns all registers if UserDefined, otherwise 1

Raises:

SPSDKValueError – When an unsupported rule is encountered for determining option word count.

Returns:

Number of option words for the current peripheral configuration.

static option_words_to_bytes(option_words)#

Convert option words to bytes.

The method converts a list of integer option words into a byte sequence using little-endian byte order, with each option word represented as 4 bytes.

Parameters:

option_words (list[int]) – List of integer option words to convert.

Return type:

bytes

Returns:

Byte sequence containing the converted option words.

static option_words_to_string(option_words)#

Convert option words list to formatted hexadecimal string representation.

The method takes a list of integer option words and formats them as a comma-separated string of hexadecimal values with 0x prefix and 8-digit zero-padding.

Parameters:

option_words (list[int]) – List of integer option words to be converted to string format.

Return type:

str

Returns:

Comma-separated string of hexadecimal option words (e.g., “0x12345678, 0xABCDEF00”).

classmethod parse(data, family, peripheral, interface=None)#

Parse the option words to configuration.

Creates a new instance of the class and parses the provided option words data into the internal registers structure.

Parameters:
  • data (bytes) – Option words in bytes to be parsed.

  • family (FamilyRevision) – Chip family revision information.

  • peripheral (str) – Name of the peripheral device.

  • interface (Optional[str]) – Memory interface specification, defaults to None.

Return type:

Self

Returns:

New instance with parsed configuration data.

property supported_interfaces: list[str]#

Get list of supported interfaces for the current family and peripheral.

Returns:

List of interface names supported by the current memory configuration.

class spsdk.memcfg.memcfg.MemoryInterface(name, option_words=<factory>, tested=False)#

Bases: object

Memory interface representation for SPSDK memory configuration.

This class represents a memory interface with its associated option words and testing status. It provides functionality to manage and format memory interface configuration data used in SPSDK memory configuration operations.

get_option_words_string()#

Get option words in string format.

The method converts the option words to a formatted string representation with each option word displayed in hexadecimal format.

Return type:

str

Returns:

String containing option words in format “Opt0: 0xXXXXXXXX, Opt1: 0xXXXXXXXX”.

name: str#
option_words: list#
tested: bool = False#
exception spsdk.memcfg.memcfg.SPSDKUnsupportedInterface(desc=None)#

Bases: SPSDKError

SPSDK exception for unsupported memory interface operations.

This exception is raised when attempting to use a memory interface that is not supported by the current SPSDK configuration or hardware target.

Initialize the base SPSDK Exception.

Parameters:

desc (Optional[str]) – Optional description of the exception.