-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: mspi: Support MSPI driver for STM32. #96670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: mspi: Support MSPI driver for STM32. #96670
Conversation
834dc73 to
7e8241c
Compare
ed327ea to
a09a921
Compare
There was a problem hiding this comment.
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..
| For example | ||
| dma-names = "tx_rx"; | ||
|
|
||
| ssht-enable: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
e0849ca to
806f0f8
Compare
fc323fc to
6cf8d2c
Compare
| Enabling a stm32 xspi node in a board | ||
| description would typically requires this: (pinning depends on the stm32 mcu) | ||
| &xspi { | ||
| pinctrl-0 = <&octospi_clk_pe9 &octospi_ncs_pe10 &octospi_dqs_pe11 | ||
| &octospi_io0_pe12 &octospi_io1_pe13 | ||
| &octospi_io2_pe14 &octospi_io3_pe15 | ||
| &octospi_io4_pe16 &octospi_io5_pe17 | ||
| &octospi_io6_pe18 &octospi_io7_pe19>; | ||
| pinctrl-names = "default"; | ||
| status = "okay"; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not fully correct as you omit the dtsi part of the node. Pinning doesn't depends on the mcu, but depends on the board, ....
I would fully remove this part to avoid discussions on that part which will be long to get agreed by everyone.
| reg: | ||
| required: true | ||
|
|
||
| interrupts: | ||
| required: true | ||
|
|
||
| pinctrl-0: | ||
| required: true | ||
|
|
||
| pinctrl-names: | ||
| required: true | ||
|
|
||
| clocks: | ||
| required: true | ||
|
|
||
| clock-names: | ||
| required: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of those are already part of the includes above. Please clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erwango
yes correct but here I just marked them as required since in include files they are not marked as required
what do you think ?
drivers/mspi/Kconfig.stm32
Outdated
| # Copyright (c) 2025 STMicroelectronics | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config MSPI_STM32_XSPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sort alphabetically whenvener it is possible.
drivers/mspi/mspi_stm32.h
Outdated
| #ifdef CONFIG_MSPI_STM32_XSPI | ||
| XSPI_HandleTypeDef xspi; | ||
| #endif | ||
| #ifdef CONFIG_MSPI_STM32_OSPI | ||
| OSPI_HandleTypeDef ospi; | ||
| #endif | ||
| #ifdef CONFIG_MSPI_STM32_QSPI | ||
| QSPI_HandleTypeDef qspi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on alphabetical sorting
drivers/mspi/mspi_stm32_common.c
Outdated
| #ifndef LL_DMA_SRC_DATAWIDTH_BYTE | ||
| #define LL_DMA_SRC_DATAWIDTH_BYTE LL_DMA_MDATAALIGN_BYTE | ||
| #endif | ||
|
|
||
| #ifndef LL_DMA_SRC_DATAWIDTH_HALFWORD | ||
| #define LL_DMA_SRC_DATAWIDTH_HALFWORD LL_DMA_MDATAALIGN_HALFWORD | ||
| #endif | ||
|
|
||
| #ifndef LL_DMA_SRC_DATAWIDTH_WORD | ||
| #define LL_DMA_SRC_DATAWIDTH_WORD LL_DMA_MDATAALIGN_WORD | ||
| #endif | ||
|
|
||
| #ifndef LL_DMA_DEST_DATAWIDTH_BYTE | ||
| #define LL_DMA_DEST_DATAWIDTH_BYTE LL_DMA_PDATAALIGN_BYTE | ||
| #endif | ||
|
|
||
| #ifndef LL_DMA_DEST_DATAWIDTH_HALFWORD | ||
| #define LL_DMA_DEST_DATAWIDTH_HALFWORD LL_DMA_PDATAALIGN_HALFWORD | ||
| #endif | ||
|
|
||
| #ifndef LL_DMA_DEST_DATAWIDTH_WORD | ||
| #define LL_DMA_DEST_DATAWIDTH_WORD LL_DMA_PDATAALIGN_WORD | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid redefining LL symbols, but use new symbols instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file really useful vs already available mspi_stm32.h ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ys, it's needed to define global arrays mspi_stm32_table_...[].
drivers/mspi/mspi_stm32_ospi.c
Outdated
| return ret; | ||
| } | ||
|
|
||
| if (IS_ENABLED(MSPI_STM32_DOMAIN_CLOCK_SUPPORT) && (config->pclk_len > 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove use of MSPI_STM32_DOMAIN_CLOCK_SUPPORT in the driver. It's bringing confusion and saving implied is neglectible vs the size of the driver.
include/zephyr/drivers/spi/spi_nor.h
Outdated
| */ | ||
|
|
||
| #ifndef __SPI_NOR_H__ | ||
| #define __SPI_NOR_H__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_SPI_NOR_H_
#define ZEPHYR_INCLUDE_DRIVERS_SPI_SPI_NOR_H_
include/zephyr/drivers/spi/spi_nor.h
Outdated
| #define SPI_NOR_IS_32K_ALIGNED(_ofs) SPI_NOR_IS_ALIGNED(_ofs, 15) | ||
| #define SPI_NOR_IS_64K_ALIGNED(_ofs) SPI_NOR_IS_ALIGNED(_ofs, 16) | ||
|
|
||
| #define CMD_RDCR 0x15 /* Read the configuration register. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, this macro should be renamed SPI_NOR_CMD_RDCR.
For that purpose, I think you can squash commits "include: spi: Move spi_nor.h to include folder"
and "drivers: flash: Adjust include paths for spi_nor.h".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ys, it's needed to define global arrays mspi_stm32_table_...[].
| return ret; | ||
| } | ||
|
|
||
| OSPI_RegularCmdTypeDef s_command = mspi_stm32_ospi_prepare_cmd(cfg_mode, cfg_rate); |
There was a problem hiding this comment.
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 this local variable definition?
|
|
||
| /* For ASYNC mode, wait for IRQ completion (PM locks released in ISR) */ | ||
| if (k_sem_take(&dev_data->sync, K_FOREVER) < 0) { | ||
| LOG_ERR("Failed to complete async transfer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
(void)pm_device_runtime_put(dev);
drivers/mspi/mspi_stm32_xspi.c
Outdated
|
|
||
| if (mspi_stm32_xspi_is_inp(controller)) { | ||
| ret = -EBUSY; | ||
| goto e_return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can put PM ressource at this stage (as done at e_return branch label).
drivers/mspi/mspi_stm32_ospi.c
Outdated
| /* Lock with the expected timeout value = ctx->xfer.timeout */ | ||
| ret = mspi_stm32_ospi_context_lock(ctx, dev_data->dev_id, xfer, true); | ||
| if (ret != 0) { | ||
| goto status_end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not call k_sem_give(&ctx->lock) at function exit.
Suggestion:
static int mspi_stm32_ospi_status_reg(const struct device *controller, const struct mspi_xfer *xfer)
{
// here, return straight upon error
(void)pm_device_runtime_get(controller);
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
// here `goto pm_put` upon error
ret = mspi_stm32_ospi_context_lock(ctx, dev_data->dev_id, xfer, true);
// here `goto ctx_unlock` upon error
ctx_unlock:
k_sem_give(&ctx->lock);
pm_put:
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
(void)pm_device_runtime_put(controller);
return ret;
}See also the QSPI and XSPI drivers for equivalent issues.
drivers/mspi/mspi_stm32_ospi.c
Outdated
| status_end: | ||
| pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); | ||
| (void)pm_device_runtime_put(controller); | ||
| k_sem_give(&ctx->lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To here finding where context lock is locked/taken and unlocked/given, I think it would help to have a helper function that matches mspi_stm32_ospi_context_lock():
static inline void mspi_stm32_ospi_context_unlock(struct mspi_stm32_context *ctx)
{
k_sem_give(&ctx->lock);
}Ditto in QSPI and XSPI drivers.
6cf8d2c to
6a7d2c8
Compare
a6d3767 to
c1ceacb
Compare
This commit moves spi_nor.h from drivers/flash to include/drivers/spi directory and updates affected flash drivers with new include path Signed-off-by: Sara Touqan <[email protected]> Signed-off-by: Sarah Younis <[email protected]> Signed-off-by: Mohammad Odeh <[email protected]>
c1ceacb to
7c1ab3e
Compare
tpambor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are looking to use this driver together with a PSRAM, which would require support for MSPI_DATA_RATE_S_D_D. Maybe you could also support these modes.
| ? HAL_XSPI_INSTRUCTION_DTR_ENABLE | ||
| : HAL_XSPI_INSTRUCTION_DTR_DISABLE; | ||
| cmd_tmp.AlternateBytesMode = HAL_XSPI_ALT_BYTES_NONE; | ||
| cmd_tmp.AddressDTRMode = (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_ADDRESS_DTR_ENABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cmd_tmp.AddressDTRMode = (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_ADDRESS_DTR_ENABLE | |
| cmd_tmp.AddressDTRMode = ((cfg_rate == MSPI_DATA_RATE_DUAL) || (cfg_rate == MSPI_DATA_RATE_S_D_D)) ? HAL_XSPI_ADDRESS_DTR_ENABLE |
| : HAL_XSPI_DATA_DTR_DISABLE; | ||
| /* AddressWidth must be set to 32bits for init and mem config phase */ | ||
| cmd_tmp.AddressWidth = HAL_XSPI_ADDRESS_32_BITS; | ||
| cmd_tmp.DataDTRMode = (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_DATA_DTR_ENABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cmd_tmp.DataDTRMode = (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_DATA_DTR_ENABLE | |
| cmd_tmp.DataDTRMode = (cfg_rate != MSPI_DATA_RATE_SINGLE) ? HAL_XSPI_DATA_DTR_ENABLE |
| cmd_tmp.DataDTRMode = (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_DATA_DTR_ENABLE | ||
| : HAL_XSPI_DATA_DTR_DISABLE; | ||
| cmd_tmp.DQSMode = | ||
| (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_DQS_ENABLE : HAL_XSPI_DQS_DISABLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| (cfg_rate == MSPI_DATA_RATE_DUAL) ? HAL_XSPI_DQS_ENABLE : HAL_XSPI_DQS_DISABLE; | |
| (cfg_rate != MSPI_DATA_RATE_SINGLE) ? HAL_XSPI_DQS_ENABLE : HAL_XSPI_DQS_DISABLE; |
This could also be added later. I prefer we get a more simple version soon, on which contributions could be made. |
| /* Macro to check if any xspi device has a domain clock or more */ | ||
| #define MSPI_STM32_DOMAIN_CLOCK_INST_SUPPORT(inst) DT_CLOCKS_HAS_IDX(DT_INST_PARENT(inst), 1) || | ||
| #define MSPI_STM32_INST_DEV_DOMAIN_CLOCK_SUPPORT \ | ||
| (DT_INST_FOREACH_STATUS_OKAY(MSPI_STM32_DOMAIN_CLOCK_INST_SUPPORT) 0) | ||
|
|
||
| /* This symbol takes the value 1 if device instance has a domain clock in its dts */ | ||
| #if MSPI_STM32_INST_DEV_DOMAIN_CLOCK_SUPPORT | ||
| #define MSPI_STM32_DOMAIN_CLOCK_SUPPORT 1 | ||
| #else | ||
| #define MSPI_STM32_DOMAIN_CLOCK_SUPPORT 0 | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required anymore (to be cleaned up from all O/Q/X drivers variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe moving this spi_nor.h header file could have its own PR ?
@etienne-lms is it ok with you to revert the commit of moving spi_nor.h and then later another PR can be opened? |
I think that the point of @FRASTM was not to do it later, but before. |
I agree. It would allow the SPI maintainer (@swift-tk) to explicitly agree (or not) on this change. |
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]>
7c1ab3e to
897c655
Compare
ok then we can open new PR for this header change. |
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]>
897c655 to
a7ad0cf
Compare
|
Updated PR description to add DMA support for QSPI driver. Tested on STM32L496G-DISCO. |
|



This PR introduces support for MSPI driver on STM32, enabling functionality APIs for MSPI host controllers.
mspi_stm32_xspi driver
ospi_stm32 driver
mspi_stm32_qspi driver
arduino_giga_r1/stm32h747xx/m7andstm32l496g_discoNotes: