Skip to content

Commit d96c0e6

Browse files
Update FreeRTOS examples for PicoW (#2557)
The PicoW can't access the LED from core 1, because it is driven by the CYW43 chip, so make sure any blinking is on core 0. Fixes #2553
1 parent 599c226 commit d96c0e6

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

libraries/FreeRTOS/examples/Multicore-FreeRTOS/Multicore-FreeRTOS.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void ps() {
3838

3939
void blink(void *param) {
4040
(void) param;
41+
delay(500);
4142
pinMode(LED_BUILTIN, OUTPUT);
4243
while (true) {
4344
digitalWrite(LED_BUILTIN, LOW);
@@ -49,12 +50,17 @@ void blink(void *param) {
4950

5051

5152
void setup() {
53+
TaskHandle_t blinkTask;
5254
Serial.begin(115200);
53-
xTaskCreate(blink, "BLINK", 128, nullptr, 1, nullptr);
55+
xTaskCreate(blink, "BLINK", 256, nullptr, 1, &blinkTask);
56+
#ifdef ARDUINO_RASPBERRY_PI_PICO_W
57+
// The PicoW WiFi chip controls the LED, and only core 0 can make calls to it safely
58+
vTaskCoreAffinitySet(blinkTask, 1 << 0);
59+
#endif
5460
delay(5000);
5561
}
5662

57-
volatile int val= 0;
63+
volatile int val = 0;
5864
void loop() {
5965
Serial.printf("C0: Blue leader standing by...\n");
6066
ps();

libraries/FreeRTOS/examples/StaticMulticore-FreeRTOS/StaticMulticore-FreeRTOS.ino

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ StackType_t xStack_B[ STACK_SIZE ];
3535
SemaphoreHandle_t xSemaphore = NULL;
3636
StaticSemaphore_t xMutexBuffer;
3737

38+
TaskHandle_t ledOnTask, ledOffTask;
39+
3840
void setup() {
3941
SERIAL_PORT.begin(115200);
4042
pinMode(LED_BUILTIN, OUTPUT);
@@ -44,13 +46,22 @@ void setup() {
4446
the xMutexBuffer variable. */
4547
xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
4648

47-
xTaskCreateStatic(led_ON, "led_ON", STACK_SIZE, NULL, configMAX_PRIORITIES - 1, xStack_A, &xTaskBuffer_A);
48-
xTaskCreateStatic(led_OFF, "led_OFF", STACK_SIZE, NULL, configMAX_PRIORITIES - 1, xStack_B, &xTaskBuffer_B);
49-
}
49+
ledOnTask = xTaskCreateStatic(led_ON, "led_ON", STACK_SIZE, NULL, configMAX_PRIORITIES - 1, xStack_A, &xTaskBuffer_A);
50+
#ifdef ARDUINO_RASPBERRY_PI_PICO_W
51+
// The PicoW WiFi chip controls the LED, and only core 0 can make calls to it safely
52+
vTaskCoreAffinitySet(ledOnTask, 1 << 0);
53+
#endif
54+
ledOffTask = xTaskCreateStatic(led_OFF, "led_OFF", STACK_SIZE, NULL, configMAX_PRIORITIES - 1, xStack_B, &xTaskBuffer_B);
55+
#ifdef ARDUINO_RASPBERRY_PI_PICO_W
56+
// The PicoW WiFi chip controls the LED, and only core 0 can make calls to it safely
57+
vTaskCoreAffinitySet(ledOffTask, 1 << 0);
58+
#endif
59+
}
5060

5161
void led_ON(void *pvParameters)
5262
{
5363
(void) pvParameters;
64+
delay(100);
5465
while (1)
5566
{
5667
xSemaphoreTake( xSemaphore, ( TickType_t ) portMAX_DELAY );
@@ -65,6 +76,7 @@ void led_ON(void *pvParameters)
6576
void led_OFF(void *pvParameters)
6677
{
6778
(void) pvParameters;
79+
delay(100);
6880
while (1)
6981
{
7082
xSemaphoreTake( xSemaphore, ( TickType_t ) portMAX_DELAY );

0 commit comments

Comments
 (0)