From b9db23b983211fa3273362145b310a6d35607577 Mon Sep 17 00:00:00 2001 From: mkolchurin <33422855+mkolchurin@users.noreply.github.com> Date: Tue, 20 Feb 2024 04:34:25 +0300 Subject: [PATCH] zephyr: Use zephyr sys_cache instead of CMSIS (#3162) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running AOT code in Zephyr on STM32H743VIT6 without CONFIG_CACHE_MANAGEMENT=y, a hard fault occurs, which leads to SCB_CleanDCache(). It’s better to use the functions built into Zephyr. --- core/shared/platform/zephyr/platform_internal.h | 6 ++++++ core/shared/platform/zephyr/zephyr_platform.c | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/shared/platform/zephyr/platform_internal.h b/core/shared/platform/zephyr/platform_internal.h index a5d563a6..85ca39be 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -50,6 +50,12 @@ #include #endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */ +#if KERNEL_VERSION_NUMBER >= 0x030300 /* version 3.3.0 */ +#if defined(CONFIG_CPU_CORTEX_M7) && defined(CONFIG_ARM_MPU) +#include +#endif +#endif /* end of KERNEL_VERSION_NUMBER > 0x030300 */ + #ifdef CONFIG_ARM_MPU #if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ #include diff --git a/core/shared/platform/zephyr/zephyr_platform.c b/core/shared/platform/zephyr/zephyr_platform.c index 1a5b6621..e91a4230 100644 --- a/core/shared/platform/zephyr/zephyr_platform.c +++ b/core/shared/platform/zephyr/zephyr_platform.c @@ -202,10 +202,14 @@ void os_dcache_flush() { #if defined(CONFIG_CPU_CORTEX_M7) && defined(CONFIG_ARM_MPU) +#if KERNEL_VERSION_NUMBER < 0x030300 /* version 3.3.0 */ uint32 key; key = irq_lock(); SCB_CleanDCache(); irq_unlock(key); +#else + sys_cache_data_flush_all(); +#endif #elif defined(CONFIG_SOC_CVF_EM7D) && defined(CONFIG_ARC_MPU) \ && defined(CONFIG_CACHE_FLUSHING) __asm__ __volatile__("sync"); @@ -216,7 +220,11 @@ os_dcache_flush() void os_icache_flush(void *start, size_t len) -{} +{ +#if KERNEL_VERSION_NUMBER >= 0x030300 /* version 3.3.0 */ + sys_cache_instr_flush_range(start, len); +#endif +} void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,