Loading...
Searching...
No Matches
Multicore

setup1(), loop1() and rp2040: running code on both RP2040 cores. More...

Classes

class  RP2040FifoClass
 Passes 32-bit values between the two cores: rp2040.fifo. More...
class  RP2040Class
 The second core and the chip: rp2040. More...

Functions

void setup1 (void) __attribute__((weak))
 Written by the sketch (optional): runs once on core 1, at the same time as setup() on core 0.
void loop1 (void) __attribute__((weak))
 Written by the sketch (optional): runs over and over on core 1 after setup1().

Variables

RP2040Class rp2040

Detailed Description

setup1(), loop1() and rp2040: running code on both RP2040 cores.

The RP2040 has two cores. setup() and loop() run on core 0. If the sketch also defines setup1() and loop1(), core 1 runs them at the same time:

void setup() { Serial.begin(115200); }
void loop() { Serial.println(rp2040.fifo.pop()); } // waits for core 1
void setup1() {}
void loop1() { rp2040.fifo.push(analogRead(A0)); delay(500); }
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
int analogRead(pin_size_t pinNumber)
Reads the voltage on an analog pin.
void setup1(void) __attribute__((weak))
Written by the sketch (optional): runs once on core 1, at the same time as setup() on core 0.
RP2040Class rp2040
void loop1(void) __attribute__((weak))
Written by the sketch (optional): runs over and over on core 1 after setup1().
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.

The names are those of the arduino-pico core, so multicore sketches written for it build here too (ADR 009).

Tools > Operating System: None FreeRTOS (SMP), or with CMSIS-RTOS2
setup()/loop() core 0, 4 KB stack task pinned to core 0, 8 KB stack, priority 1 (CMSIS-RTOS2: osPriorityNormal)
setup1()/loop1() core 1, 4 KB stack, started just before setup() task pinned to core 1, 8 KB stack, priority 1 (CMSIS-RTOS2: osPriorityNormal)
delay() waits, calling yield() blocks the task: other tasks run

Both cores share the pins, peripherals and memory:

  • Variables shared between the cores must be volatile, or passed through rp2040.fifo.
  • Serial (USB) can be used from both cores. Serial1 and Serial2 can be read on either core, whichever called begin().
  • Other peripherals (analog pins, SPI, Wire, a PWM pin or tone()) should be used from one core at a time.
  • noInterrupts() stops interrupts on the calling core only.
  • Do not use the pico-sdk's multicore_fifo_*() functions: the hardware FIFO is used by rp2040.idleOtherCore() and by FreeRTOS.

Function Documentation

◆ setup1()

void setup1 ( void )

Written by the sketch (optional): runs once on core 1, at the same time as setup() on core 0.

Defining setup1() or loop1() starts core 1. Core 1 has its own 4 KB stack (8 KB task stack with FreeRTOS).

Examples
MulticoreBasics.ino.

Variable Documentation

◆ rp2040

RP2040Class rp2040
extern

The second core, inter-core FIFO and chip information (arduino-pico compatible).

Examples
FreeRtosTasks.ino, MulticoreBasics.ino, and MulticoreFifo.ino.