@@ -190,8 +190,8 @@ class RP2040 {
190190 RP2040 () { /* noop */ }
191191 ~RP2040 () { /* noop */ }
192192
193- void begin () {
194- _epoch = 0 ;
193+ void begin (int cpuid ) {
194+ _epoch[cpuid] = 0 ;
195195#if !defined(__riscv) && !defined(__PROFILE)
196196 if (!__isFreeRTOS) {
197197 // Enable SYSTICK exception
@@ -200,11 +200,14 @@ class RP2040 {
200200 systick_hw->rvr = 0x00FFFFFF ;
201201 } else {
202202#endif
203- int off = 0 ;
204- _ccountPgm = new PIOProgram (&ccount_program);
205- _ccountPgm->prepare (&_pio, &_sm, &off);
206- ccount_program_init (_pio, _sm, off);
207- pio_sm_set_enabled (_pio, _sm, true );
203+ // Only start 1 instance of the PIO SM
204+ if (cpuid == 0 ) {
205+ int off = 0 ;
206+ _ccountPgm = new PIOProgram (&ccount_program);
207+ _ccountPgm->prepare (&_pio, &_sm, &off);
208+ ccount_program_init (_pio, _sm, off);
209+ pio_sm_set_enabled (_pio, _sm, true );
210+ }
208211#if !defined(__riscv) && !defined(__PROFILE)
209212 }
210213#endif
@@ -241,7 +244,7 @@ class RP2040 {
241244 /* *
242245 @brief CPU cycle counter epoch (24-bit cycle). For internal use
243246 */
244- volatile uint64_t _epoch = 0 ;
247+ volatile uint64_t _epoch[ 2 ] = {} ;
245248 /* *
246249 @brief Get the count of CPU clock cycles since power on.
247250
@@ -258,9 +261,9 @@ class RP2040 {
258261 uint32_t epoch;
259262 uint32_t ctr;
260263 do {
261- epoch = (uint32_t )_epoch;
264+ epoch = (uint32_t )_epoch[sio_hw-> cpuid ] ;
262265 ctr = systick_hw->cvr ;
263- } while (epoch != (uint32_t )_epoch);
266+ } while (epoch != (uint32_t )_epoch[sio_hw-> cpuid ] );
264267 return epoch + (1 << 24 ) - ctr; /* CTR counts down from 1<<24-1 */
265268 } else {
266269#endif
@@ -280,9 +283,9 @@ class RP2040 {
280283 uint64_t epoch;
281284 uint64_t ctr;
282285 do {
283- epoch = _epoch;
286+ epoch = _epoch[sio_hw-> cpuid ] ;
284287 ctr = systick_hw->cvr ;
285- } while (epoch != _epoch);
288+ } while (epoch != _epoch[sio_hw-> cpuid ] );
286289 return epoch + (1LL << 24 ) - ctr;
287290 } else {
288291#endif
@@ -666,8 +669,8 @@ class RP2040 {
666669
667670
668671private:
669- static void _SystickHandler () {
670- rp2040._epoch += 1LL << 24 ;
672+ static void __no_inline_not_in_flash_func ( _SystickHandler) () {
673+ rp2040._epoch [sio_hw-> cpuid ] += 1LL << 24 ;
671674 }
672675 PIO _pio;
673676 int _sm;
0 commit comments