Hello Everyone,
On a pico RP2040 W , I managed to run the systick counter on each core separately successfully( see code enclosed )
but when i try to run both simultaneously, i'm stuck on that hard assert error
i know internal clock could be used easily with the sdk but i really want to understand why
i thought at the begining that vector table is common to both core, but
exception_get_vtable_handler(SYSTICK_EXCEPTION) function give different result for each core which make me conclude that each core has its own NVIC + VECTOR table
can someone confirm ? did someone managed to do it ? if yes any help would be welcome ! (Mistra AI and Claude doesnt seem to have any idea on that
)
thank you !!
On a pico RP2040 W , I managed to run the systick counter on each core separately successfully( see code enclosed )
but when i try to run both simultaneously, i'm stuck on that hard assert error
i know internal clock could be used easily with the sdk but i really want to understand why
i thought at the begining that vector table is common to both core, but
exception_get_vtable_handler(SYSTICK_EXCEPTION) function give different result for each core which make me conclude that each core has its own NVIC + VECTOR table
can someone confirm ? did someone managed to do it ? if yes any help would be welcome ! (Mistra AI and Claude doesnt seem to have any idea on that
thank you !!
Code:
#include <stdio.h>#include <stdint.h>#include "pico/stdlib.h"#include "pico/multicore.h"#include "hardware/timer.h"#include "hardware/structs/systick.h"#include "hardware/exception.h"#define CSR_SYSTICK_ENABLE (1u << 0)#define CSR_SYSTICK_DISABLE 0#define CSR_DISABLE_EXCEPTION 0#define CSR_ENABLE_EXCEPTION (1u << 1)#define CSR_CLKSOURCE (1u << 2)#define CSR_COUNTFLAG_MASK (1U << 16)#define RVR_RELOAD 124999#define CVR_CLEAR 0volatile uint32_t counter = 0;volatile uint32_t countdown = 0;volatile uint32_t core1countdown = 0;static exception_handler_t original_systick_handler = NULL;void horlogeSystickMs(uint32_t ms){ systick_hw->rvr = RVR_RELOAD; systick_hw->cvr = CVR_CLEAR; systick_hw->csr = (CSR_SYSTICK_ENABLE | CSR_DISABLE_EXCEPTION | CSR_CLKSOURCE); for (int i = 0; i < ms; i++) { while (((systick_hw->csr) & CSR_COUNTFLAG_MASK) == 0) { }; }; systick_hw->csr = CSR_SYSTICK_DISABLE;}void counter_systick_exception_handler(void){ counter++;}void countdown_systick_exception_handler(void){ countdown++;}void core1_countdown_systick_exception_handler(void){ core1countdown++;}void systick_exception_init(int counterOrcountDown){ original_systick_handler = exception_get_vtable_handler(SYSTICK_EXCEPTION); systick_hw->rvr = RVR_RELOAD; systick_hw->cvr = CVR_CLEAR; systick_hw->csr = (CSR_SYSTICK_ENABLE | CSR_ENABLE_EXCEPTION | CSR_CLKSOURCE); if (counterOrcountDown == 0) { exception_set_exclusive_handler(SYSTICK_EXCEPTION, counter_systick_exception_handler); } else if (counterOrcountDown == 1) { exception_set_exclusive_handler(SYSTICK_EXCEPTION, countdown_systick_exception_handler); } exception_set_priority(SYSTICK_EXCEPTION, 255);}void systick_exception_deinit(void){ systick_hw->csr = CSR_SYSTICK_DISABLE; exception_restore_handler(SYSTICK_EXCEPTION, original_systick_handler);}bool isCountdownElapsed(uint32_t msDelay){ static bool is_first_call = true; if (is_first_call == true) { countdown = 0; systick_exception_init(1); is_first_call = false; return false; } else if (countdown >= msDelay) { systick_exception_deinit(); is_first_call = true; return true; } return false;}uint32_t ms_delay_passed(bool start){ if (start == true) { counter = 0; systick_exception_init(0); return 0; } else { systick_exception_deinit(); return counter; };}void core1IsCountdownElapsed(void){ exception_handler_t core1_original_systick_handler = exception_get_vtable_handler(SYSTICK_EXCEPTION); systick_hw->rvr = RVR_RELOAD; systick_hw->cvr = CVR_CLEAR; systick_hw->csr = (CSR_SYSTICK_ENABLE | CSR_ENABLE_EXCEPTION | CSR_CLKSOURCE); core1countdown = 0; exception_set_exclusive_handler(SYSTICK_EXCEPTION, core1_countdown_systick_exception_handler); exception_set_priority(SYSTICK_EXCEPTION, 254); uint32_t elapsedTime = 5000; while (core1countdown <= elapsedTime) { multicore_fifo_push_blocking(0); } multicore_fifo_push_blocking(1); systick_hw->csr = CSR_SYSTICK_DISABLE; exception_restore_handler(SYSTICK_EXCEPTION, core1_original_systick_handler);}int main(){ stdio_init_all(); // start systick on first core ms_delay_passed(true); // start systick on second core multicore_launch_core1(core1IsCountdownElapsed); uint8_t fifo; bool countdown_finished = false; while (!countdown_finished) { fifo = multicore_fifo_pop_blocking(); if (fifo == 0) { printf("countdown from core 1 =%d\n", core1countdown); printf("countdown from core 0 =%d\n", counter); } else { countdown_finished = true; ms_delay_passed(false); } };}Statistics: Posted by Michael13 — Tue Nov 18, 2025 4:57 pm — Replies 4 — Views 104