Skip to content

Conversation

@ExaltZephyr
Copy link
Contributor

@ExaltZephyr ExaltZephyr commented Sep 28, 2025

This PR introduces support for MSPI driver on STM32, enabling functionality APIs for MSPI host controllers.

  1. mspi_stm32_xspi driver

    • support xspi
    • tested using stm32h573i_dk and stm32h7s78_dk boards
    • functionalities:
      • Indirect Mode (read, write and erase).
      • DTR support.
      • Memory map mode (read and write).
      • xip configuration.
      • DMA Mode
      • Zephyr Power Management Support
  2. ospi_stm32 driver

    • support octospi
    • tested using stm32h735g_disco and b_u585i_iot02a
    • functionalities:
      • Indirect mode (read, write and erase)
      • DTR support
      • Memory map mode (read b_u585i_iot02a board)
      • xip configuration
      • DMA transfer (b_u585i_iot02a board)
      • zephyr power management support
  3. mspi_stm32_qspi driver

    • support quadspi
    • tested using arduino_giga_r1/stm32h747xx/m7
    • functionalities:
      • Indirect mode (read, write and erase) with MSPI_IO_MODE_SINGLE
      • Indirect mode (read, write and erase) with MSPI_IO_MODE_QUAD_1_1_4
      • Memory map mode (read)
      • Zephyr Power Management Support
      • DMA transfer: not supported yet

Notes:

  • This PR was tested with JEDEC flash drivers and has not been tested with PSRAM.
  • mspi_stm32_xspi driver - DMA mode here was tested using stm32h573i_dk board only since no zephyr dma support on stm32h7s78_dk

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 8 times, most recently from 834dc73 to 7e8241c Compare September 29, 2025 11:59
@FRASTM FRASTM mentioned this pull request Sep 30, 2025
4 tasks
@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 6 times, most recently from ed327ea to a09a921 Compare October 2, 2025 14:03
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to dts/bindings/mspi/st,stm32-xspi-controller.yaml MSPI is the subsytem api and XSPI is the ST IP name.
Apply everywhere (driver files, ....) on this PR..


}

static int flash_stm32_xspi_dma_init(DMA_HandleTypeDef *hdma, struct stream *dma_stream)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/flash_stm32_xspi_dma_init/mspi_stm32_xspi_dma_init

For example
dma-names = "tx_rx";

ssht-enable:
Copy link
Member

@erwango erwango Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the three IPs, these bindings will have to propose the same configuration options as the union of dts/bindings/memory-controllers/st,stm32-xspi-psram.yaml and dts/bindings/flash_controller/st,stm32-xspi-nor.yaml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this may potentially be done as a follow up PR

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 9 times, most recently from e0849ca to 806f0f8 Compare October 6, 2025 12:23
@erwango erwango requested a review from Copilot October 6, 2025 12:25

LOG_MODULE_REGISTER(mspi_stm32_qspi, CONFIG_MSPI_LOG_LEVEL);

static inline int mspi_context_lock(struct mspi_context *ctx, const struct mspi_dev_id *req,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be mspi_context_lock(struct mspi_stm32_context *ctx ?

device_type = "memory";
reg = <0x90000000 DT_SIZE_M(256)>;
zephyr,memory-region = "QSPI";
zephyr,memory-attr = <( DT_MEM_ARM(ATTR_MPU_RAM_NOCACHE) )>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferrably without the outer parentheeses, e.g.:

		zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_FLASH)>;

command-length ="INSTR_2_BYTE";
rx-dummy = <20>;
jedec-id = [ c2 85 3a ];
partitions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coudl you add an empty line above?

#address-cells = <1>;
#size-cells = <0>;
op-mode = "MSPI_CONTROLLER";
status = "okay";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer have the status property last among the node properties. Not a blocking issue.


e_return:

k_mutex_unlock(&data->lock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutex was lokced only upon data->dev_id != dev_id. Condition to test also here.
Ditto for the unlock instruction above at line 1098.

.dev_cfg = {0}, \
.xip_cfg = {0}, \
.ctx.lock = Z_SEM_INITIALIZER(mspi_stm32_dev_data_##index.ctx.lock, 0, 1), \
OSPI_DMA_CHANNEL(DT_DRV_INST(index), tx_rx)}; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OSPI_DMA_CHANNEL(DT_DRV_INST(index), tx_rx)}; \
OSPI_DMA_CHANNEL(DT_DRV_INST(index), tx_rx), \
}; \

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 6 times, most recently from 96c07b3 to cc1fc60 Compare October 29, 2025 14:21
Copy link
Contributor

@JarmouniA JarmouniA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be applied for all instances in all files.

@ExaltZephyr Please apply review remarks (the ones you agree with) for all instances across all files. Otherwise, comment with your disagreement under the unaddressed ones.

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 3 times, most recently from 2fa8377 to adf9ad9 Compare October 29, 2025 15:17
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for flooding with coding style comments. I tried to be exhaustive, covering the 3 drivers.

uint32_t addr = dev_data->memmap_base_addr + packet->address;
uint32_t size = packet->num_bytes;

size = (size + 31U) & ~31U;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep size = (size + 31U) & ~31U; above? If you keep this, asserting size below is useless.

switch (access_mode) {
case MSPI_ACCESS_SYNC:
hal_ret = HAL_OSPI_Receive(&dev_data->hmspi.ospi, packet->data_buf,
HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hal_ret value is not tested. Ditto in MSPI_TX path below.

*
* @retval 0 if successful.
* @retval -EINVAL invalid capabilities, failed to configure device.
* @retval -ENOTSUP capability not supported by MSPI peripheral.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be other possible return value. Mentioning A negative errno value upon failure would maybe be simpler.

This comment applies to other function inline description comments in this P-R.

@ExaltZephyr
Copy link
Contributor Author

ExaltZephyr commented Oct 30, 2025

I'm guessing you use hardware CE only and support only one device under the same controller? There is no ce-gpios in DTS and yet mspi_verify_device is copied directly from ambiq driver.. What is the plan for multi-peripheral support?

@swift-tk Yes, that’s correct — currently, we only support one device connected to the controller. I don’t think there’s a plan to extend this for now.
Should we remove mspi_verify_device then?

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 3 times, most recently from 56ba9f4 to af6db91 Compare October 30, 2025 15:06
dma-names:
description: |
DMA channel name. If DMA should be used, expected value is "tx_rx".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could add here:

    enum:
      - "tx_rx"

Ditto for the QSPI and XSPI bindings.

dmas:
description: |
Optional DMA channel specifier, required for DMA transactions.
For example dmas for TX/RX on xspi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also, dmas description is not needed since already described in the relevant DMA binding description.

help
Enable QSPI driver for STM32 family of processors.

#DT_STM32_OCTOSPI_HAS_DMA := $(dt_compat_any_has_prop,$(DT_COMPAT_ST_STM32_OSPI),dmas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this line?

bool dst_addr_increment;
};

union hmspi_handle {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
union hmspi_handle {
union mspi_stm32_handle {

}
#else
ret = mspi_stm32_xspi_access(controller, packet,
(ctx->xfer.async == true) ? MSPI_ACCESS_ASYNC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 1374 to 1375
if (((xfer->packets->cmd == SPI_NOR_OCMD_RDSR) ||
(xfer->packets->cmd == SPI_NOR_CMD_RDSR))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (((xfer->packets->cmd == SPI_NOR_OCMD_RDSR) ||
(xfer->packets->cmd == SPI_NOR_CMD_RDSR))) {
if ((xfer->packets->cmd == SPI_NOR_OCMD_RDSR) ||
(xfer->packets->cmd == SPI_NOR_CMD_RDSR)) {

#endif

#if defined(DLYB_XSPI1) || defined(DLYB_XSPI2) || defined(DLYB_OCTOSPI1) || defined(DLYB_OCTOSPI2)
HAL_XSPI_DLYB_CfgTypeDef mspi_delay_block_cfg = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an empty line below?

(void)pm_device_runtime_put(spec->bus);

if (ret == 0) {
LOG_INF("MSPI config'd");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_INF("MSPI config'd");
LOG_INF("MSPI configured");

Does this really belong to the info log level? What about LOG_DBG()?

.xip_cfg = {0}, \
.ctx.lock = Z_SEM_INITIALIZER(mspi_stm32_dev_data_##index.ctx.lock, 0, 1), \
XSPI_DMA_CHANNEL(DT_DRV_INST(index), tx, TX, MEMORY, PERIPHERAL) \
XSPI_DMA_CHANNEL(DT_DRV_INST(index), rx, RX, PERIPHERAL, MEMORY)}; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
XSPI_DMA_CHANNEL(DT_DRV_INST(index), rx, RX, PERIPHERAL, MEMORY)}; \
XSPI_DMA_CHANNEL(DT_DRV_INST(index), rx, RX, PERIPHERAL, MEMORY), \
}; \

*
* @retval 0 if successful.
* @retval -ESTALE device ID don't match, need to call mspi_dev_config first.
* @retval -Error transfer failed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @retval -Error transfer failed.
* @retval A negative errno value upon failure.

8 other occurrences in this commit.

@ExaltZephyr ExaltZephyr force-pushed the stm32-mspi-support branch 3 times, most recently from ecba19e to 04891a6 Compare November 2, 2025 13:08
This commit adds the main DTS configurations required
to enable MSPI/OSPI/QSPI support on STM32.

Signed-off-by: Sara Touqan <[email protected]>
Signed-off-by: Sarah Younis <[email protected]>
Signed-off-by: Mohammad Odeh <[email protected]>
This commit introduces support for the mspi and ospi drivers on STM32,
enabling functionality APIs for MSPI/OSPI/QSPI host controllers..

Signed-off-by: Sara Touqan <[email protected]>
Signed-off-by: Sarah Younis <[email protected]>
Signed-off-by: Mohammad Odeh <[email protected]>
this commit enables building and running the sample on
stm32h573i_dk board,stm32h735g_disco board, arduino_giga_r1
board, and  b_u585i_iot02a board by providing the required overlay
and configuration updates.

Signed-off-by: Sara Touqan <[email protected]>
Signed-off-by: Sarah Younis <[email protected]>
Signed-off-by: Mohammad Odeh <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants