Skip to content

Conversation

@mariopaja
Copy link
Contributor

@mariopaja mariopaja commented Jun 30, 2025

Add STM32 OSPI PSRAM driver support in memory mapped mode

Current driver configuration based on aps6408l on STM32U5xx series

Test application 1

https://github.com/mariopaja/hello_psram

Custom U575 Board:

Memory region         Used Size  Region Size  %age Used
           FLASH:       23572 B         2 MB      1.12%
             RAM:        4864 B       768 KB      0.62%
           PSRAM:       2000 KB         8 MB     24.41%
        IDT_LIST:          0 GB        32 KB      0.00%

b_u585i_iot02a:

Memory region         Used Size  Region Size  %age Used
           FLASH:       34680 B         2 MB      1.65%
             RAM:        6960 B       768 KB      0.89%
           PSRAM:       8000 KB         8 MB     97.66%
          EXTMEM:          0 GB        64 MB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
Hello STM32 OSPI PSRAM!
Verifying PSRAM Buffer size: 2048000 ...
PSRAM verification successful!
[00:00:00.000,000] <dbg> memc_stm32_ospi_psram: memc_stm32_ospi_psram_init: OSPI AHB clock frequency: 160000000 Hz
[00:00:00.000,000] <dbg> memc_stm32_ospi_psram: memc_stm32_ospi_psram_init: OSPI max frequency: 133000000 Hz
[00:00:00.000,000] <dbg> memc_stm32_ospi_psram: memc_stm32_ospi_psram_init: clk: 80000000, prescaler: 2
[00:00:00.000,000] <dbg> memc_stm32_ospi_psram: memc_stm32_ospi_psram_init: MSB set: 23
*** Booting Zephyr OS build v4.2.0-rc1-130-gd97aff3f8f32 ***

Test application 2

tests/drivers/memc/ram

Memory region         Used Size  Region Size  %age Used
           FLASH:       36384 B         2 MB      1.73%
             RAM:        5984 B       768 KB      0.76%
           PSRAM:          8 MB         8 MB    100.00%
          EXTMEM:          0 GB        64 MB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
*** Booting Zephyr OS build v4.2.0-3146-gea283133abd3 ***
Running TESTSUITE test_ram
===================================================================
START - test_psram
 PASS - test_psram in 0.138 seconds
===================================================================
START - test_ram0
 SKIP - test_ram0 in 0.001 seconds
===================================================================
START - test_sdram1
 SKIP - test_sdram1 in 0.001 seconds
===================================================================
START - test_sdram2
 SKIP - test_sdram2 in 0.001 seconds
===================================================================
START - test_sram1
 SKIP - test_sram1 in 0.001 seconds
===================================================================
START - test_sram2
 SKIP - test_sram2 in 0.001 seconds
===================================================================
TESTSUITE test_ram succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [test_ram]: pass = 1, fail = 0, skip = 5, total = 6 duration = 0.143 seconds
 - PASS - [test_ram.test_psram] duration = 0.138 seconds
 - SKIP - [test_ram.test_ram0] duration = 0.001 seconds
 - SKIP - [test_ram.test_sdram1] duration = 0.001 seconds
 - SKIP - [test_ram.test_sdram2] duration = 0.001 seconds
 - SKIP - [test_ram.test_sram1] duration = 0.001 seconds
 - SKIP - [test_ram.test_sram2] duration = 0.001 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch 2 times, most recently from 752b380 to 3e5e735 Compare June 30, 2025 08:52
@dkouba-atym
Copy link

Thank you Mario! Could you tag this for backport into v4.1?

@mariopaja
Copy link
Contributor Author

Thank you Mario! Could you tag this for backport into v4.1?

@dkouba-atym I dont think I can or am allowed to. I dont really see any relevance of this driver for v4.1.

@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch 5 times, most recently from 8b0fd92 to 6efb10f Compare July 4, 2025 11:39
@JarmouniA
Copy link
Contributor

Thank you Mario! Could you tag this for backport into v4.1?

Only fixes are backported.

@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch 5 times, most recently from 17525a8 to 823d932 Compare July 8, 2025 06:57
@mariopaja mariopaja marked this pull request as ready for review July 8, 2025 08:20
@erwango erwango added this to the v4.3.0 milestone Jul 8, 2025
@bilibb
Copy link

bilibb commented Jul 9, 2025

I was able to integrate the driver with an STM32U5A9J overlay and successfully write and read an APS6408L-3OBM-BA using the supplied test program.

@JarmouniA
Copy link
Contributor

JarmouniA commented Sep 18, 2025

I tried using the driver from this PR, but I’m getting errors like: ‘error: unknown type name ‘HAL_OSPI_DLYB_CfgTypeDef’.’ I'm happy to run tests, but I have to admit I don't know the STM32 HAL well enough to develop a new driver.

@Piziwate As a naive fix, that's unlikely to work correctly, try guarding HAL_OSPI_DLYB.... calls with #ifdef CONFIG_SOC_SERIES_STM32U5X... #endif and modify driver config to select USE_STM32_LL_DLYB if SOC_SERIES_STM32U5X

@mariopaja
Copy link
Contributor Author

Okay, that makes more sense! In that case, shouldn’t you add a dependency at the Kconfig level to prevent it from being (unsuccessfully) used on other STM32s?

@JarmouniA @erwango should I make it U5xx specific, or should I do the following:

As a naive fix, that's unlikely to work correctly, try guarding HAL_OSPI_DLYB.... calls with #ifdef CONFIG_SOC_SERIES_STM32U5X... #endif and modify driver config to select USE_STM32_LL_DLYB if SOC_SERIES_STM32U5X

@erwango
Copy link
Member

erwango commented Sep 18, 2025

IMO , we should focus on U5 for now and expansion to a new series should be kept for a future PR. Otherwise we'll lose ourselves in workarounds

@JarmouniA
Copy link
Contributor

IMO , we should focus on U5 for now and expansion to a new series should be kept for a future PR. Otherwise we'll lose ourselves in workarounds

Then the driver config should have depends on SOC_SERIES_STM32U5X to avoid mis-usage.

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.

I think there should be 1 commit for the driver part (incl. the DT bindings addition), 1 for board b_u585i_iot02a and a last one to enable test on that board, which may request to add memc tag in the supported list in the board YAML file. Maybe these 2 last commits could be squashed together.

@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch from 4371901 to b31dc4f Compare September 20, 2025 08:29
@zephyrbot zephyrbot requested a review from erwango September 20, 2025 08:31
@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch 5 times, most recently from 301f902 to 0e53c9b Compare September 20, 2025 09:24
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.

Some late comments.

}

if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t)&dev_cfg->pclken) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: as mentioned in a few other P-Rs (e.g. #96214 (comment), ), cast to clock_control_subsys_t are not needed (the type is void *).
Not a blocking issue, maybe a tree-wide change will fix all occurrences.

etienne-lms
etienne-lms previously approved these changes Sep 23, 2025
@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch 2 times, most recently from b3c0fe6 to 6ba5617 Compare September 24, 2025 09:01
Copy link
Member

@dsseng dsseng left a comment

Choose a reason for hiding this comment

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

Some nitpicks

Add a driver for STM32U5 OSPI PSRAM in memory mapped mode.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
Changes enable OSPI PSRAM on b_u585i_iot02a board.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
This change updates buffer size to the full psram size when
psram node is available

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
Add b_u585i_iot02a board to test/drivers/memc/ram

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
@mariopaja mariopaja force-pushed the memc_stm32_ospi_psram branch from 6ba5617 to c4edb9e Compare September 24, 2025 09:50
@sonarqubecloud
Copy link

@kartben kartben merged commit 60c2db2 into zephyrproject-rtos:main Sep 25, 2025
27 checks passed
@mariopaja mariopaja deleted the memc_stm32_ospi_psram branch November 12, 2025 06:21
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.