From ff1e84725e67cb2fe5aff6138f1b69e22716bdc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Fri, 13 Dec 2024 09:18:17 +0100 Subject: [PATCH 1/9] Revert "[nrf noup] samples: bluetooth: update autoconf.h header path" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e94d330581af040f9e41e0590e6a4b999eccfaf4. Signed-off-by: Michał Stasiak --- samples/bluetooth/bap_unicast_client/src/stream_tx.c | 2 +- samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c | 2 +- samples/bluetooth/cap_acceptor/src/main.c | 2 +- samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c | 2 +- samples/bluetooth/cap_initiator/src/main.c | 2 +- soc/nordic/nrf54l/soc.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/bluetooth/bap_unicast_client/src/stream_tx.c b/samples/bluetooth/bap_unicast_client/src/stream_tx.c index eba7273a0c6..06ea3a3c349 100644 --- a/samples/bluetooth/bap_unicast_client/src/stream_tx.c +++ b/samples/bluetooth/bap_unicast_client/src/stream_tx.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c index aad077a0aed..cbdb859eb8f 100644 --- a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c +++ b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c @@ -7,7 +7,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_acceptor/src/main.c b/samples/bluetooth/cap_acceptor/src/main.c index df4600f09bb..6ca5f59282e 100644 --- a/samples/bluetooth/cap_acceptor/src/main.c +++ b/samples/bluetooth/cap_acceptor/src/main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c index 60509beb258..39b7a68aef6 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_initiator/src/main.c b/samples/bluetooth/cap_initiator/src/main.c index 8eab76938bc..1b35ea7981f 100644 --- a/samples/bluetooth/cap_initiator/src/main.c +++ b/samples/bluetooth/cap_initiator/src/main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 70528c2fd88..74a96c24f2e 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -13,7 +13,7 @@ */ #ifdef __NRF_TFM__ -#include +#include #endif #include From c1258dfe0ea695f4fff7bacbd00d1f78e1b116f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Fri, 13 Dec 2024 09:19:08 +0100 Subject: [PATCH 2/9] Revert "[nrf noup] soc: nordic: nrf54l Fix for wait lasting half expected time" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 382877e15f13507f40c73b385446987fc7ace57e. Signed-off-by: Michał Stasiak --- soc/nordic/nrf54l/soc.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 74a96c24f2e..6905bd020f5 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -48,13 +48,6 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); #define HFXO_NODE DT_NODELABEL(hfxo) #endif -/* Building for cpuflpr with ns uses cpu_1 instead of cpu_0 */ -#if DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) -#define DEVICE_DT_CLOCK_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) -#elif DT_PROP(DT_PATH(cpus, cpu_1), clock_frequency) -#define DEVICE_DT_CLOCK_FREQ DT_PROP(DT_PATH(cpus, cpu_1), clock_frequency) -#endif - #if defined(NRF_APPLICATION) static inline void power_and_clock_configuration(void) { @@ -183,18 +176,16 @@ int nordicsemi_nrf54l_init(void) /* Update the SystemCoreClock global variable with current core clock * retrieved from hardware state. */ +#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(__NRF_TFM__) + /* Currently not supported for non-secure */ + SystemCoreClockUpdate(); +#endif #ifdef __NRF_TFM__ /* TF-M enables the instruction cache from target_cfg.c, so we * don't need to enable it here. */ #else - - /* Update SystemCoreClock in Zephyr based on device tree to avoid SystemCoreClock - * being overwritten with default value when initializing with TF-M - */ - SystemCoreClock = DEVICE_DT_CLOCK_FREQ; - /* Enable ICACHE */ sys_cache_instr_enable(); #endif From f58566c41f8cf22f67496eed702e9611f56ca49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Fri, 13 Dec 2024 09:19:13 +0100 Subject: [PATCH 3/9] Revert "[nrf noup] soc: nordic: nrf54l: Port Soc.c to be compatible with TFM" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ee23470a8947f4a98445b7543798e084fa8a6ff8. Signed-off-by: Michał Stasiak --- soc/nordic/nrf54l/soc.c | 65 ++++++++++------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 6905bd020f5..76749c1983a 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -12,21 +12,13 @@ * for the Nordic Semiconductor nRF54L family processor. */ -#ifdef __NRF_TFM__ -#include -#endif - #include #include #include #include #include #include - -#ifndef __NRF_TFM__ #include -#endif - #include #if defined(NRF_APPLICATION) @@ -48,9 +40,17 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); #define HFXO_NODE DT_NODELABEL(hfxo) #endif -#if defined(NRF_APPLICATION) -static inline void power_and_clock_configuration(void) +static int nordicsemi_nrf54l_init(void) { + /* Update the SystemCoreClock global variable with current core clock + * retrieved from hardware state. + */ + SystemCoreClockUpdate(); + +#if defined(NRF_APPLICATION) + /* Enable ICACHE */ + sys_cache_instr_enable(); + #if DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, internal) uint32_t xosc32ktrim = NRF_FICR->XOSC32KTRIM; @@ -77,16 +77,16 @@ static inline void power_and_clock_configuration(void) * NOTE: The desired capacitance value is used in encoded from in INTCAP calculation formula * That is different than in case of HFXO. */ - uint32_t cap_val_encoded = - (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL) * 2UL) / 1000UL); + uint32_t cap_val_encoded = (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL) + * 2UL) / 1000UL); /* Calculation of INTCAP code before rounding. Min that calculations here are done on * values multiplied by 2^9, e.g. 0.765625 * 2^9 = 392. * offset_k should be divided by 2^6, but to add it to value shifted by 2^9 we have to * multiply it be 2^3. */ - uint32_t mid_val = - (cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL) + (offset_k << 3UL); + uint32_t mid_val = (cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL) + + (offset_k << 3UL); /* Get integer part of the INTCAP code */ uint32_t lfxo_intcap = mid_val >> 9UL; @@ -132,9 +132,8 @@ static inline void power_and_clock_configuration(void) */ uint32_t cap_val_femto_f = DT_PROP(HFXO_NODE, load_capacitance_femtofarad); - uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL)) + - (offset_m << 2UL) * 1000UL) >> - 8UL; + uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL)) + + (offset_m << 2UL) * 1000UL) >> 8UL; /* Convert the calculated value to piko Farads */ uint32_t hfxo_intcap = mid_val_intcap / 1000; @@ -168,40 +167,8 @@ static inline void power_and_clock_configuration(void) #if defined(CONFIG_ELV_GRTC_LFXO_ALLOWED) nrf_regulators_elv_mode_allow_set(NRF_REGULATORS, NRF_REGULATORS_ELV_ELVGRTCLFXO_MASK); #endif /* CONFIG_ELV_GRTC_LFXO_ALLOWED */ -} #endif /* NRF_APPLICATION */ -int nordicsemi_nrf54l_init(void) -{ - /* Update the SystemCoreClock global variable with current core clock - * retrieved from hardware state. - */ -#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(__NRF_TFM__) - /* Currently not supported for non-secure */ - SystemCoreClockUpdate(); -#endif - -#ifdef __NRF_TFM__ - /* TF-M enables the instruction cache from target_cfg.c, so we - * don't need to enable it here. - */ -#else - /* Enable ICACHE */ - sys_cache_instr_enable(); -#endif - - /* NRF_REGULATORS and NRF_OSCILLATORS are configured to be secure - * as NRF_REGULATORS.POFCON is needed by the secure domain to - * prevent glitches when the power supply is attacked. - * - * NRF_OSCILLATORS is also configured as secure because of a HW limitation - * that requires them to be configured with the same security property. - */ -#if (defined(NRF_APPLICATION) && !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)) || \ - defined(__NRF_TFM__) - power_and_clock_configuration(); -#endif - return 0; } From a799fa285dbbff2362d8b584ba57f78cdf8aeed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Fri, 13 Dec 2024 09:19:51 +0100 Subject: [PATCH 4/9] Revert "[nrf noup] soc: nrf54l: Add custom section for KMU" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4279ea34588eb8a8339fbcb069a4e18039aac1d1. Signed-off-by: Michał Stasiak --- soc/nordic/nrf54l/CMakeLists.txt | 9 --------- soc/nordic/nrf54l/kmu_push_area_section.ld | 19 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 soc/nordic/nrf54l/kmu_push_area_section.ld diff --git a/soc/nordic/nrf54l/CMakeLists.txt b/soc/nordic/nrf54l/CMakeLists.txt index bf2eaa1d820..f1c18291fc6 100644 --- a/soc/nordic/nrf54l/CMakeLists.txt +++ b/soc/nordic/nrf54l/CMakeLists.txt @@ -10,12 +10,3 @@ zephyr_include_directories(.) if(CONFIG_ELV_GRTC_LFXO_ALLOWED) message(WARNING "WARNING! ELV mode feature is EXPERIMENTAL and may brick your device!") endif() - -# We need a buffer in memory in a static location which can be used by -# the KMU peripheral. The KMU has a static destination address, we chose -# this address to be 0x20000000, which is the first address in the SRAM. -if(NOT CONFIG_BUILD_WITH_TFM AND CONFIG_PSA_NEED_CRACEN_KMU_DRIVER) -# Exclamation mark is printable character with the lowest number in ASCII table. -# We are sure that this file will be included first. -zephyr_linker_sources(RAM_SECTIONS SORT_KEY ! kmu_push_area_section.ld) -endif() diff --git a/soc/nordic/nrf54l/kmu_push_area_section.ld b/soc/nordic/nrf54l/kmu_push_area_section.ld deleted file mode 100644 index e8c8cd9f09a..00000000000 --- a/soc/nordic/nrf54l/kmu_push_area_section.ld +++ /dev/null @@ -1,19 +0,0 @@ -# This section must be loaded first of all the -# custom sections because we want it to be placed -# at the top address of RAM. -SECTION_PROLOGUE(NRF_KMU_RESERVED_PUSH_SECTION,(NOLOAD) ,) -{ - __nrf_kmu_reserved_push_area = .; - *(.nrf_kmu_reserved_push_area) - __nrf_kmu_reserved_push_area_end = .; -} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) - -# It doesn't seem to be possible to enforce placing a section -# at a specific address in memory using the Zephyr SECTION macros. -# So this assert is necessary to avoid accidentatly moving this -# section to a different address. -ASSERT(__nrf_kmu_reserved_push_area == RAM_ADDR, "Error: \ - The section NRF_KMU_RESERVED_PUSH_SECTION needs to be \ - placed on the top RAM address but it is not, please edit \ - your linker scripts to make sure that it is placed on \ - the to RAM address.") From 6430450d7c9bddaea5a70b7617d8cacc0dc14924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Wed, 4 Dec 2024 14:15:31 +0100 Subject: [PATCH 5/9] [nrf fromtree] soc: nordic: nrf54l: remove redundant ELV code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed dead ELV code from nRF54L soc. Signed-off-by: Michał Stasiak (cherry picked from commit 4c96cbb79ba1f7a3f50c37c9c34cebecf3f13fac) --- soc/nordic/nrf54l/CMakeLists.txt | 4 ---- soc/nordic/nrf54l/Kconfig | 14 -------------- soc/nordic/nrf54l/soc.c | 3 --- 3 files changed, 21 deletions(-) diff --git a/soc/nordic/nrf54l/CMakeLists.txt b/soc/nordic/nrf54l/CMakeLists.txt index f1c18291fc6..cebbda571b6 100644 --- a/soc/nordic/nrf54l/CMakeLists.txt +++ b/soc/nordic/nrf54l/CMakeLists.txt @@ -6,7 +6,3 @@ zephyr_library_sources( ../validate_rram_partitions.c ) zephyr_include_directories(.) - -if(CONFIG_ELV_GRTC_LFXO_ALLOWED) - message(WARNING "WARNING! ELV mode feature is EXPERIMENTAL and may brick your device!") -endif() diff --git a/soc/nordic/nrf54l/Kconfig b/soc/nordic/nrf54l/Kconfig index ab5f1c745b9..9a2306b6adc 100644 --- a/soc/nordic/nrf54l/Kconfig +++ b/soc/nordic/nrf54l/Kconfig @@ -82,18 +82,4 @@ config SOC_NRF_FORCE_CONSTLAT of base resources on while in sleep. The advantage of having a constant and predictable latency will be at the cost of having increased power consumption. -if NRF_GRTC_TIMER - -config ELV_GRTC_LFXO_ALLOWED - bool - depends on POWEROFF - select EXPERIMENTAL - help - This feature allows using ELV mode when GRTC operates with the LFXO as - a low-frequency clock source. The LFXO is automatically activated when - preparing to system-off. - WARNING! This feature is EXPERIMENTAL and may brick your device! - -endif # NRF_GRTC_TIMER - endif # SOC_SERIES_NRF54LX diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 76749c1983a..abb0f778ac3 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -164,9 +164,6 @@ static int nordicsemi_nrf54l_init(void) nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); #endif -#if defined(CONFIG_ELV_GRTC_LFXO_ALLOWED) - nrf_regulators_elv_mode_allow_set(NRF_REGULATORS, NRF_REGULATORS_ELV_ELVGRTCLFXO_MASK); -#endif /* CONFIG_ELV_GRTC_LFXO_ALLOWED */ #endif /* NRF_APPLICATION */ return 0; From b09f227ecbd1c8cf66236465408bad8f9e88d220 Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Fri, 21 Jun 2024 13:25:22 +0200 Subject: [PATCH 6/9] [nrf noup] soc: nrf54l: Add custom section for KMU Add a custom section in the linker which should always be placed in the top of RAM. This will be used by the KMU to push keys into it. Since when you provision a key into the KMU you need to set specific a memory location for the PUSH operation we need to keep this memory location static across images/dfus. This is a noup since the KMU is not supported upstream. Ref: NCSDK-25121 Signed-off-by: Georgios Vasilakis (cherry picked from commit 9ce3906acd7ebb3d82ae699b24965d6eff2a47f1) (cherry picked from commit 95d3bde051b31af162a12a2e194555bf82be566e) --- soc/nordic/nrf54l/CMakeLists.txt | 9 +++++++++ soc/nordic/nrf54l/kmu_push_area_section.ld | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 soc/nordic/nrf54l/kmu_push_area_section.ld diff --git a/soc/nordic/nrf54l/CMakeLists.txt b/soc/nordic/nrf54l/CMakeLists.txt index cebbda571b6..c8badc8d61d 100644 --- a/soc/nordic/nrf54l/CMakeLists.txt +++ b/soc/nordic/nrf54l/CMakeLists.txt @@ -6,3 +6,12 @@ zephyr_library_sources( ../validate_rram_partitions.c ) zephyr_include_directories(.) + +# We need a buffer in memory in a static location which can be used by +# the KMU peripheral. The KMU has a static destination address, we chose +# this address to be 0x20000000, which is the first address in the SRAM. +if(NOT CONFIG_BUILD_WITH_TFM AND CONFIG_PSA_NEED_CRACEN_KMU_DRIVER) +# Exclamation mark is printable character with the lowest number in ASCII table. +# We are sure that this file will be included first. +zephyr_linker_sources(RAM_SECTIONS SORT_KEY ! kmu_push_area_section.ld) +endif() diff --git a/soc/nordic/nrf54l/kmu_push_area_section.ld b/soc/nordic/nrf54l/kmu_push_area_section.ld new file mode 100644 index 00000000000..e8c8cd9f09a --- /dev/null +++ b/soc/nordic/nrf54l/kmu_push_area_section.ld @@ -0,0 +1,19 @@ +# This section must be loaded first of all the +# custom sections because we want it to be placed +# at the top address of RAM. +SECTION_PROLOGUE(NRF_KMU_RESERVED_PUSH_SECTION,(NOLOAD) ,) +{ + __nrf_kmu_reserved_push_area = .; + *(.nrf_kmu_reserved_push_area) + __nrf_kmu_reserved_push_area_end = .; +} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) + +# It doesn't seem to be possible to enforce placing a section +# at a specific address in memory using the Zephyr SECTION macros. +# So this assert is necessary to avoid accidentatly moving this +# section to a different address. +ASSERT(__nrf_kmu_reserved_push_area == RAM_ADDR, "Error: \ + The section NRF_KMU_RESERVED_PUSH_SECTION needs to be \ + placed on the top RAM address but it is not, please edit \ + your linker scripts to make sure that it is placed on \ + the to RAM address.") From 815ee522b46a1590ef7167269e07cefe9aac1f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Fri, 24 May 2024 15:34:47 +0200 Subject: [PATCH 7/9] [nrf noup] soc: nordic: nrf54l: Port Soc.c to be compatible with TFM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this patch we do several things to be able to configure power and clocks when NRF_OSCILLATORS and NRF_REGULATORS is secure. We port soc.c to TF-M so that the TF-M image can do the same configuration that would normally be done by the Zephyr image. This is done by explicitly including autoconf.h for instance. We also ifdef-out the configuration when nordicsemi_nrf54l_init is invoked from a non-secure image, because the peripherals are secure. Signed-off-by: Sebastian Bøe (cherry picked from commit 962fa00fcd23a4a758c3489fc40c1b2e94e07810) (cherry picked from commit 028f0c4c054e79e0c1fae1f0f905112c4b12544c) --- soc/nordic/nrf54l/soc.c | 66 ++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index abb0f778ac3..26248018f6b 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -12,13 +12,21 @@ * for the Nordic Semiconductor nRF54L family processor. */ +#ifdef __NRF_TFM__ +#include +#endif + #include #include #include #include #include #include + +#ifndef __NRF_TFM__ #include +#endif + #include #if defined(NRF_APPLICATION) @@ -40,17 +48,9 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); #define HFXO_NODE DT_NODELABEL(hfxo) #endif -static int nordicsemi_nrf54l_init(void) -{ - /* Update the SystemCoreClock global variable with current core clock - * retrieved from hardware state. - */ - SystemCoreClockUpdate(); - #if defined(NRF_APPLICATION) - /* Enable ICACHE */ - sys_cache_instr_enable(); - +static inline void power_and_clock_configuration(void) +{ #if DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, internal) uint32_t xosc32ktrim = NRF_FICR->XOSC32KTRIM; @@ -77,16 +77,16 @@ static int nordicsemi_nrf54l_init(void) * NOTE: The desired capacitance value is used in encoded from in INTCAP calculation formula * That is different than in case of HFXO. */ - uint32_t cap_val_encoded = (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL) - * 2UL) / 1000UL); + uint32_t cap_val_encoded = + (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL) * 2UL) / 1000UL); /* Calculation of INTCAP code before rounding. Min that calculations here are done on * values multiplied by 2^9, e.g. 0.765625 * 2^9 = 392. * offset_k should be divided by 2^6, but to add it to value shifted by 2^9 we have to * multiply it be 2^3. */ - uint32_t mid_val = (cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL) - + (offset_k << 3UL); + uint32_t mid_val = + (cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL) + (offset_k << 3UL); /* Get integer part of the INTCAP code */ uint32_t lfxo_intcap = mid_val >> 9UL; @@ -132,8 +132,9 @@ static int nordicsemi_nrf54l_init(void) */ uint32_t cap_val_femto_f = DT_PROP(HFXO_NODE, load_capacitance_femtofarad); - uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL)) - + (offset_m << 2UL) * 1000UL) >> 8UL; + uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL)) + + (offset_m << 2UL) * 1000UL) >> + 8UL; /* Convert the calculated value to piko Farads */ uint32_t hfxo_intcap = mid_val_intcap / 1000; @@ -163,9 +164,40 @@ static int nordicsemi_nrf54l_init(void) #endif nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); #endif - +} #endif /* NRF_APPLICATION */ +int nordicsemi_nrf54l_init(void) +{ + /* Update the SystemCoreClock global variable with current core clock + * retrieved from hardware state. + */ +#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(__NRF_TFM__) + /* Currently not supported for non-secure */ + SystemCoreClockUpdate(); +#endif + +#ifdef __NRF_TFM__ + /* TF-M enables the instruction cache from target_cfg.c, so we + * don't need to enable it here. + */ +#else + /* Enable ICACHE */ + sys_cache_instr_enable(); +#endif + + /* NRF_REGULATORS and NRF_OSCILLATORS are configured to be secure + * as NRF_REGULATORS.POFCON is needed by the secure domain to + * prevent glitches when the power supply is attacked. + * + * NRF_OSCILLATORS is also configured as secure because of a HW limitation + * that requires them to be configured with the same security property. + */ +#if (defined(NRF_APPLICATION) && !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)) || \ + defined(__NRF_TFM__) + power_and_clock_configuration(); +#endif + return 0; } From dc3973e6bf5bede143ce4e71a1f1eaf001e22bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Erik=20Gj=C3=B8rvad?= Date: Thu, 12 Dec 2024 10:25:00 +0100 Subject: [PATCH 8/9] [nrf noup] soc: nordic: nrf54l Fix for wait lasting half expected time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Noup as it patches code that does not exist in zephyr arch_busy_wait and k_busy_wait waited half the expected time due to SystemCoreClock being set back to the default value when ns builds. Changed to rely on device tree as to avoid hardcoded clock frequencies Signed-off-by: Dag Erik Gjørvad --- soc/nordic/nrf54l/soc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 26248018f6b..d7f3005d1f4 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -48,6 +48,13 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); #define HFXO_NODE DT_NODELABEL(hfxo) #endif +/* Building for cpuflpr with ns uses cpu_1 instead of cpu_0 */ +#if DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) +#define DEVICE_DT_CLOCK_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) +#elif DT_PROP(DT_PATH(cpus, cpu_1), clock_frequency) +#define DEVICE_DT_CLOCK_FREQ DT_PROP(DT_PATH(cpus, cpu_1), clock_frequency) +#endif + #if defined(NRF_APPLICATION) static inline void power_and_clock_configuration(void) { @@ -172,16 +179,18 @@ int nordicsemi_nrf54l_init(void) /* Update the SystemCoreClock global variable with current core clock * retrieved from hardware state. */ -#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(__NRF_TFM__) - /* Currently not supported for non-secure */ - SystemCoreClockUpdate(); -#endif #ifdef __NRF_TFM__ /* TF-M enables the instruction cache from target_cfg.c, so we * don't need to enable it here. */ #else + + /* Update SystemCoreClock in Zephyr based on device tree to avoid SystemCoreClock + * being overwritten with default value when initializing with TF-M + */ + SystemCoreClock = DEVICE_DT_CLOCK_FREQ; + /* Enable ICACHE */ sys_cache_instr_enable(); #endif From 3ac74e49b4dfc89e17d6c6f450ce1a0d78fdc8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Audun=20Kvamtr=C3=B8?= Date: Thu, 5 Sep 2024 15:06:57 +0200 Subject: [PATCH 9/9] [nrf noup] samples: bluetooth: update autoconf.h header path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update path for autoconf.h which is now in zephyr/autoconf.h Signed-off-by: Frank Audun Kvamtrø (cherry picked from commit b22c113e035ffef20c2dd9ad9ce4eebae992f6db) (cherry picked from commit 02f8b45f35322b72378f9fe641057779a36476bd) --- samples/bluetooth/bap_unicast_client/src/stream_tx.c | 2 +- samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c | 2 +- samples/bluetooth/cap_acceptor/src/main.c | 2 +- samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c | 2 +- samples/bluetooth/cap_initiator/src/main.c | 2 +- soc/nordic/nrf54l/soc.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/bluetooth/bap_unicast_client/src/stream_tx.c b/samples/bluetooth/bap_unicast_client/src/stream_tx.c index 06ea3a3c349..eba7273a0c6 100644 --- a/samples/bluetooth/bap_unicast_client/src/stream_tx.c +++ b/samples/bluetooth/bap_unicast_client/src/stream_tx.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c index cbdb859eb8f..aad077a0aed 100644 --- a/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c +++ b/samples/bluetooth/cap_acceptor/src/cap_acceptor_unicast.c @@ -7,7 +7,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_acceptor/src/main.c b/samples/bluetooth/cap_acceptor/src/main.c index 6ca5f59282e..df4600f09bb 100644 --- a/samples/bluetooth/cap_acceptor/src/main.c +++ b/samples/bluetooth/cap_acceptor/src/main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c index 39b7a68aef6..60509beb258 100644 --- a/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c +++ b/samples/bluetooth/cap_initiator/src/cap_initiator_unicast.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include #include diff --git a/samples/bluetooth/cap_initiator/src/main.c b/samples/bluetooth/cap_initiator/src/main.c index 1b35ea7981f..8eab76938bc 100644 --- a/samples/bluetooth/cap_initiator/src/main.c +++ b/samples/bluetooth/cap_initiator/src/main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index d7f3005d1f4..eab3bf18a14 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -13,7 +13,7 @@ */ #ifdef __NRF_TFM__ -#include +#include #endif #include