Skip to content

Infineon/serial-memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serial Memory - External SPI Memory Interface Library for ModusToolbox™

Overview

Provides functions for interacting with an external memory connected through its Single SPI/Dual SPI/Quad SPI/Octal SPI interface. The read operation can be performed in either blocking or non-blocking manner while the write and erase operations are implemented as blocking functions. This library accepts the configuration generated using the QSPI Configurator tool.

Features

  • Supports asynchronous (non-blocking) read operation
  • Implements thread-safety for use with multi-threaded RTOS environment using the abstraction-rtos library
  • Accepts the configuration generated by the QSPI Configurator tool
  • Supports Execute-in-Place (XIP) mode of operation
  • Provides information about the external memory to the programming tool for it to be able to program the memory, for example, when user wants to place the code into the external memory for XIP operation
  • Allows for programming external memory if MTB_SERIAL_MEMORY_ENABLE_XIP_PROGRAM is defined when building the application

When to Use

Use this library when your application needs to interact with an external memory device connected via a Single/Dual/Quad/Octal SPI interface. Common scenarios include:

  • Storing and retrieving application data from external flash or PSRAM
  • Executing code from external memory (XIP mode)
  • Programming external memory with firmware or configuration data

How to use

Step 1. Include the library header and the QSPI Configurator–generated header:

#include "mtb_serial_memory.h"
#include "cycfg_qspi_memslot.h"

Step 2. Optionally add DEFINES=MTB_SERIAL_MEMORY_THREAD_SAFE in the Makefile to enable thread-safety when used in a multi-threaded RTOS environment. This requires the abstraction-rtos library.

Step 3. Declare the objects needed by the library and initialize the SMIF driver via PDL calls:

mtb_serial_memory_t serial_memory_obj;
cy_stc_smif_mem_context_t mem_context;
cy_stc_smif_mem_info_t mem_info;

/* Initialize SMIF with the configurator-generated config */
cy_en_smif_status_t smif_status = Cy_SMIF_Init(
    MEMORYSPI0_hal_config.base,
    MEMORYSPI0_hal_config.config,
    10000u,
    &mem_context.smif_context);

/* Set data select for the chip select used by the memory */
Cy_SMIF_SetDataSelect(
    MEMORYSPI0_hal_config.base,
    smifBlockConfig.memConfig[0]->slaveSelect,
    smifBlockConfig.memConfig[0]->dataSelect);

/* Enable the SMIF block */
Cy_SMIF_Enable(MEMORYSPI0_hal_config.base, &mem_context.smif_context);

Step 4. Set up the serial memory library specifying which chip select to use:

cy_rslt_t result = mtb_serial_memory_setup(
    &serial_memory_obj,
    MTB_SERIAL_MEMORY_CHIP_SELECT_0,
    MEMORYSPI0_hal_config.base,
    MEMORYSPI0_hal_config.clock,
    &mem_context,
    &mem_info,
    &smifBlockConfig);

Step 5. Use the library to erase, write, and read external memory:

#define DATA_SIZE  64u

uint8_t write_buf[DATA_SIZE];
uint8_t read_buf[DATA_SIZE];
uint32_t address = 0x00000000;

/* Get the erase sector size for the target address */
uint32_t erase_size = mtb_serial_memory_get_erase_size(&serial_memory_obj, address);

/* Erase the sector before writing */
result = mtb_serial_memory_erase(&serial_memory_obj, address, erase_size);

/* Fill buffer with data and write to memory */
memset(write_buf, 0xA5, DATA_SIZE);
result = mtb_serial_memory_write(&serial_memory_obj, address, DATA_SIZE, write_buf);

/* Read back and verify */
result = mtb_serial_memory_read(&serial_memory_obj, address, DATA_SIZE, read_buf);

Release Notes and Changelog

  • RELEASE.md - Detailed release notes for all versions

License

This library is licensed under the Apache License, Version 2.0.

  • LICENSE - Primary license terms (Apache License)
  • EULA - End User License Agreement

Copyright

(c) (2019-2026), Infineon Technologies AG, or an affiliate of Infineon Technologies AG. All rights reserved.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages