From 9dae30092ebefba421274aeeb9fe21a8abc542cf Mon Sep 17 00:00:00 2001 From: Jan Zyczkowski Date: Mon, 24 Jun 2024 13:20:33 +0200 Subject: [PATCH] [nrf noup] soc: nordic: nrf54h20: Turn off MRAM suspend Turn off suspending MRAM for nRF54H20 SoC. This change is required so sections of code depending on critical timings will not have unacceptable latency. Signed-off-by: Jan Zyczkowski Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 58284ff0e1b85f24d1be928860e9e6eb0e86b4e5) (cherry picked from commit 9b6cae8d899a67341963671963d58fb161462edb) (cherry picked from commit 2c2f60d1ebd959900405e448cee45c03ecdc6646) --- soc/nordic/nrf54h/CMakeLists.txt | 2 ++ soc/nordic/nrf54h/Kconfig | 6 ++++ soc/nordic/nrf54h/mram.c | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 soc/nordic/nrf54h/mram.c diff --git a/soc/nordic/nrf54h/CMakeLists.txt b/soc/nordic/nrf54h/CMakeLists.txt index 0496841ffe7..04f6329b36a 100644 --- a/soc/nordic/nrf54h/CMakeLists.txt +++ b/soc/nordic/nrf54h/CMakeLists.txt @@ -12,6 +12,8 @@ zephyr_library_sources_ifdef(CONFIG_PM_S2RAM pm_s2ram.c) zephyr_include_directories(.) +zephyr_library_sources_ifdef(CONFIG_SOC_NRF54H20_NO_MRAM_LATENCY mram.c) + # Ensure that image size aligns with 16 bytes so that MRAMC finalizes all writes # for the image correctly zephyr_linker_sources(SECTIONS SORT_KEY zzz_place_align_at_end align.ld) diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index 9132ca8458b..be6334e5df5 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -75,3 +75,9 @@ config SOC_NRF54H20_CPUFLPR config SOC_NRF54H20_ENGB_CPUFLPR depends on RISCV_CORE_NORDIC_VPR + +config SOC_NRF54H20_NO_MRAM_LATENCY + bool "Disallow MRAM latency" + imply NRFS + imply NRFS_MRAM_SERVICE_ENABLED + default y if SOC_NRF54H20_CPUAPP diff --git a/soc/nordic/nrf54h/mram.c b/soc/nordic/nrf54h/mram.c new file mode 100644 index 00000000000..5ca3526a091 --- /dev/null +++ b/soc/nordic/nrf54h/mram.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +LOG_MODULE_REGISTER(mram, CONFIG_SOC_LOG_LEVEL); + +void mram_latency_handler(nrfs_mram_latency_evt_t const *p_evt, void *context) +{ + ARG_UNUSED(context); + + switch (p_evt->type) { + case NRFS_MRAM_LATENCY_REQ_APPLIED: + LOG_DBG("MRAM latency not allowed setting applied"); + break; + case NRFS_MRAM_LATENCY_REQ_REJECTED: + LOG_ERR("MRAM latency not allowed setting rejected"); + k_panic(); + break; + default: + LOG_WRN("Unexpected event: %d", p_evt->type); + } +} + +/* Turn off mram automatic suspend as it causes delays in time depended code sections. */ +static int turn_off_suspend_mram(void) +{ + nrfs_err_t err; + + /* Wait for ipc initialization */ + nrfs_backend_wait_for_connection(K_FOREVER); + + err = nrfs_mram_init(mram_latency_handler); + if (err != NRFS_SUCCESS) { + LOG_ERR("MRAM service init failed: %d", err); + return -EIO; + } + + LOG_DBG("MRAM service initialized, disallow latency"); + + err = nrfs_mram_set_latency(MRAM_LATENCY_NOT_ALLOWED, NULL); + if (err != NRFS_SUCCESS) { + LOG_ERR("MRAM: set latency failed (%d)", err); + return -EIO; + } + + return 0; +} + +SYS_INIT(turn_off_suspend_mram, APPLICATION, 90);