From 6c754e636fa700e856300db897c8d30a068b0b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Thu, 12 Dec 2024 14:37:55 +0100 Subject: [PATCH] hal_nordic: nrfs: dvfs: Update SystemCoreClock on frequency change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update SystemCoreClock to match current core frequency. This MDK variable is used by nrfx_coredep_delay_us which performs busy waiting and is used by k_busy_wait. Signed-off-by: Krzysztof Chruściński --- modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c b/modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c index 2d74d6fd0cc..f83874f3473 100644 --- a/modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c +++ b/modules/hal_nordic/nrfs/dvfs/ld_dvfs_handler.c @@ -139,9 +139,19 @@ static void dvfs_service_handler_scaling_background_job(enum dvfs_frequency_sett } } +/* Update MDK variable which is used by nrfx_coredep_delay_us (k_busy_wait). */ +static void dvfs_service_update_core_clock(enum dvfs_frequency_setting oppoint_freq) +{ + extern uint32_t SystemCoreClock; + + SystemCoreClock = oppoint_freq == DVFS_FREQ_HIGH ? 320000000 : + oppoint_freq == DVFS_FREQ_MEDLOW ? 128000000 : 64000000; +} + /* Perform scaling finnish procedure. */ static void dvfs_service_handler_scaling_finish(enum dvfs_frequency_setting oppoint_freq) { + LOG_DBG("Scaling finnish oppoint freq %d", oppoint_freq); ld_dvfs_scaling_finish(dvfs_service_handler_is_downscaling(oppoint_freq)); if (!dvfs_service_handler_is_downscaling(oppoint_freq)) { @@ -153,6 +163,7 @@ static void dvfs_service_handler_scaling_finish(enum dvfs_frequency_setting oppo } dvfs_service_handler_clear_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS); current_freq_setting = oppoint_freq; + dvfs_service_update_core_clock(oppoint_freq); LOG_DBG("Current LD freq setting: %d", current_freq_setting); if (dvfs_frequency_change_applied_clb) { dvfs_frequency_change_applied_clb(current_freq_setting); @@ -215,6 +226,7 @@ static void nrfs_dvfs_evt_handler(nrfs_dvfs_evt_t const *p_evt, void *context) dvfs_service_handler_clear_state_bit(DVFS_SERV_HDL_FREQ_CHANGE_REQ_PENDING_BIT_POS); LOG_DBG("DVFS handler EVT_OPPOINT_REQ_CONFIRMED %d", (uint32_t)p_evt->freq); if (dvfs_service_handler_get_requested_oppoint() == p_evt->freq) { + dvfs_service_update_core_clock(p_evt->freq); if (dvfs_frequency_change_applied_clb) { dvfs_frequency_change_applied_clb(p_evt->freq); }