Skip to content

drivers: mspi: stm32_*: save base address in device configuration#108507

Open
mathieuchopstm wants to merge 1 commit intozephyrproject-rtos:mainfrom
mathieuchopstm:topic/mspi_octo_bugfix
Open

drivers: mspi: stm32_*: save base address in device configuration#108507
mathieuchopstm wants to merge 1 commit intozephyrproject-rtos:mainfrom
mathieuchopstm:topic/mspi_octo_bugfix

Conversation

@mathieuchopstm
Copy link
Copy Markdown
Contributor

The base address is constant, it's wasteful to store it in device data. void * type is used instead of hardware-specific xxx_TypeDef * since the structure is shared by all controller drivers (QSPI, OSPI and XSPI).

Since this removes the need for a cast, this tangantially fixes a bug in the OSPI driver which used the wrong type when casting device address: (XSPI_TypeDef *) instead of (OCTOSPI_TypeDef *).

While at it, move a bool field at the tail to avoid padding INSIDE the structure (although there's sadly still some, due to struct mspi_cfg...)

cc @djiatsaf-st

The base address is constant, it's wasteful to store it in device data.
`void *` type is used instead of hardware-specific `xxx_TypeDef *` since
the structure is shared by all controller drivers (QSPI, OSPI and XSPI).

Since this removes the need for a cast, this tangantially fixes a bug in
the OSPI driver which used the wrong type when casting device address:
`(XSPI_TypeDef *)` instead of `(OCTOSPI_TypeDef *)`.

While at it, move a `bool` field at the tail to avoid padding INSIDE the
structure (although there's sadly still some, due to struct mspi_cfg...)

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

}; \
static struct mspi_stm32_data mspi_stm32_dev_data_##index = { \
.phys_addr = DT_INST_REG_ADDR(index), \
.hmspi.ospi = { \
Copy link
Copy Markdown
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 set the base address straight here:

 	static struct mspi_stm32_data mspi_stm32_dev_data_##index = {                              \
-		.phys_addr = DT_INST_REG_ADDR(index),                                              \
		.hmspi.ospi = {                                                                    \
+			.Instance = (void *)DT_INST_REG_ADDR(index),                               \
 			.Init = {                                                                  \

Ditto in mspi_stm32_xspi.c driver.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants