Skip to content

Commit aa5cc30

Browse files
Re-add FreeRTOS examples, update spellcheck
1 parent 361a366 commit aa5cc30

File tree

5 files changed

+566
-2
lines changed

5 files changed

+566
-2
lines changed

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
- name: Run codespell
2121
uses: codespell-project/actions-codespell@v2
2222
with:
23-
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./.git,./libraries/FatFS/lib/fatfs,./libraries/FatFS/src/diskio.h,./libraries/FatFS/src/ff.cpp,./libraries/FatFS/src/ffconf.h,./libraries/FatFS/src/ffsystem.cpp,./libraries/FatFS/src/ff.h,./libraries/lwIP_WINC1500/src/driver,./libraries/lwIP_WINC1500/src/common,./libraries/lwIP_WINC1500/src/bus_wrapper,./libraries/lwIP_WINC1500/src/spi_flash,./libraries/WiFi/examples/BearSSL_Validation/certs.h
24-
ignore_words_list: ser,dout,shiftIn,acount,froms
23+
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./.git,./libraries/FatFS/lib/fatfs,./libraries/FatFS/src/diskio.h,./libraries/FatFS/src/ff.cpp,./libraries/FatFS/src/ffconf.h,./libraries/FatFS/src/ffsystem.cpp,./libraries/FatFS/src/ff.h,./libraries/lwIP_WINC1500/src/driver,./libraries/lwIP_WINC1500/src/common,./libraries/lwIP_WINC1500/src/bus_wrapper,./libraries/lwIP_WINC1500/src/spi_flash,./libraries/WiFi/examples/BearSSL_Validation/certs.h
24+
ignore_words_list: ser,dout,shiftIn,acount,froms,ThirdParty
2525
- name: Check boards.txt was not edited after makeboards.py
2626
run: |
2727
./tools/makeboards.py
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Demonstrates a simple use of the setup1()/loop1() functions
2+
// for a multiprocessor run.
3+
4+
// Will output something like, where C0 is running on core 0 and
5+
// C1 is on core 1, in parallel.
6+
7+
// 11:23:07.507 -> C0: Blue leader standing by...
8+
// 11:23:07.507 -> C1: Red leader standing by...
9+
// 11:23:07.507 -> C1: Stay on target...
10+
// 11:23:08.008 -> C1: Stay on target...
11+
// 11:23:08.505 -> C0: Blue leader standing by...
12+
// 11:23:08.505 -> C1: Stay on target...
13+
// 11:23:09.007 -> C1: Stay on target...
14+
// 11:23:09.511 -> C0: Blue leader standing by...
15+
// 11:23:09.511 -> C1: Stay on target...
16+
// 11:23:10.015 -> C1: Stay on target...
17+
18+
// Released to the public domain
19+
#include <FreeRTOS.h>
20+
#include <task.h>
21+
#include <map>
22+
#include <EEPROM.h>
23+
24+
std::map<eTaskState, const char *> eTaskStateName { {eReady, "Ready"}, { eRunning, "Running" }, {eBlocked, "Blocked"}, {eSuspended, "Suspended"}, {eDeleted, "Deleted"} };
25+
void ps() {
26+
int tasks = uxTaskGetNumberOfTasks();
27+
TaskStatus_t *pxTaskStatusArray = new TaskStatus_t[tasks];
28+
unsigned long runtime;
29+
tasks = uxTaskGetSystemState( pxTaskStatusArray, tasks, &runtime );
30+
Serial.printf("# Tasks: %d\n", tasks);
31+
Serial.println("ID, NAME, STATE, PRIO, CYCLES");
32+
for (int i=0; i < tasks; i++) {
33+
Serial.printf("%d: %-16s %-10s %d %lu\n", i, pxTaskStatusArray[i].pcTaskName, eTaskStateName[pxTaskStatusArray[i].eCurrentState], (int)pxTaskStatusArray[i].uxCurrentPriority, pxTaskStatusArray[i].ulRunTimeCounter);
34+
}
35+
delete[] pxTaskStatusArray;
36+
}
37+
38+
39+
void blink(void *param) {
40+
(void) param;
41+
delay(500);
42+
pinMode(LED_BUILTIN, OUTPUT);
43+
while (true) {
44+
digitalWrite(LED_BUILTIN, LOW);
45+
delay(750);
46+
digitalWrite(LED_BUILTIN, HIGH);
47+
delay(250);
48+
}
49+
}
50+
51+
52+
void setup() {
53+
TaskHandle_t blinkTask;
54+
Serial.begin(115200);
55+
xTaskCreate(blink, "BLINK", 256, nullptr, 1, &blinkTask);
56+
#if defined(PICO_CYW43_SUPPORTED)
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
60+
delay(5000);
61+
}
62+
63+
volatile int val = 0;
64+
void loop() {
65+
Serial.printf("C0: Blue leader standing by...\n");
66+
ps();
67+
Serial.printf("val: %d\n", val);
68+
delay(1000);
69+
}
70+
71+
// Running on core1
72+
void setup1() {
73+
delay(5000);
74+
Serial.printf("C1: Red leader standing by...\n");
75+
}
76+
77+
void loop1() {
78+
static int x = 0;
79+
Serial.printf("C1: Stay on target...\n");
80+
val++;
81+
if (++x < 10) {
82+
EEPROM.begin(512);
83+
EEPROM.write(0,x);
84+
EEPROM.commit();
85+
}
86+
delay(1000);
87+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
PSRAM Test
3+
4+
This section of code tests the onboard ram of RP2350 based boards with external
5+
PSRAM.
6+
7+
This example code is in the public domain.
8+
9+
*/
10+
11+
#if !defined(RP2350_PSRAM_CS)
12+
13+
void setup() {
14+
Serial.println("This example needs an RP2350 with PSRAM attached");
15+
}
16+
17+
void loop() {
18+
}
19+
20+
#else
21+
22+
#define CHUNK_SIZE 131072
23+
uint8_t tmp[CHUNK_SIZE];
24+
uint8_t mems[1024 * 1024 * 8] PSRAM;
25+
26+
// the setup function runs once when you press reset or power the board
27+
void setup() {
28+
// initialize digital pin LED_BUILTIN as an output.
29+
pinMode(LED_BUILTIN, OUTPUT);
30+
while (!Serial) {
31+
delay(10);
32+
}
33+
Serial.begin(115200);
34+
Serial.printf("Memory size: %d\r\n", rp2040.getPSRAMSize());
35+
}
36+
37+
// the loop function runs over and over again forever
38+
void loop() {
39+
int i;
40+
static int cntr = 1;
41+
42+
uint8_t *mem = mems;
43+
Serial.printf("%05d: Filling %d memory locations @0x%p with random values and verifying in %d byte chunks.\r\n", cntr++, rp2040.getPSRAMSize(), mem, CHUNK_SIZE);
44+
45+
for (size_t m = 0; m < (rp2040.getPSRAMSize() / CHUNK_SIZE); m++) {
46+
for (i = 0; i < CHUNK_SIZE; i++) {
47+
tmp[i] = (char)random(0, 255);
48+
mem[i] = tmp[i];
49+
}
50+
51+
for (i = 0; i < CHUNK_SIZE; i++) {
52+
if (mem[i] != tmp[i]) {
53+
Serial.printf("Memory error @0x%p(%d), was 0x%02x, should be 0x%02x\n", mem, i, *mem, tmp[i]);
54+
delay(10);
55+
}
56+
}
57+
Serial.write('.');
58+
Serial.flush();
59+
mem += CHUNK_SIZE;
60+
}
61+
Serial.printf("\nDone, testing %d bytes again\r\n", rp2040.getPSRAMSize());
62+
}
63+
64+
#endif // RAM_CHIP_SELECT
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* The code in this example is mostly derived from the official FreeRTOS
2+
* code examples.
3+
*
4+
* For more information on static allocation and to read the original
5+
* code visit the following links:
6+
* https://www.freertos.org/Static_Vs_Dynamic_Memory_Allocation.html
7+
* https://www.freertos.org/xTaskCreateStatic.html
8+
* https://www.freertos.org/xSemaphoreCreateMutexStatic.html
9+
*/
10+
11+
#include <FreeRTOS.h>
12+
#include <task.h>
13+
#include <semphr.h>
14+
15+
#define SERIAL_PORT Serial
16+
#define BLINK_ON_TIME 250
17+
#define BLINK_OFF_TIME 500
18+
19+
/* Dimensions of the buffer that the task being created will use as its stack.
20+
NOTE: This is the number of words the stack will hold, not the number of
21+
bytes. For example, if each stack item is 32-bits, and this is set to 100,
22+
then 400 bytes (100 * 32-bits) will be allocated. */
23+
#define STACK_SIZE 200
24+
25+
/* Structure that will hold the TCB of the task being created. */
26+
StaticTask_t xTaskBuffer_A;
27+
StaticTask_t xTaskBuffer_B;
28+
29+
/* Buffer that the task being created will use as its stack. Note this is
30+
an array of StackType_t variables. The size of StackType_t is dependent on
31+
the RTOS port. */
32+
StackType_t xStack_A[ STACK_SIZE ];
33+
StackType_t xStack_B[ STACK_SIZE ];
34+
35+
SemaphoreHandle_t xSemaphore = NULL;
36+
StaticSemaphore_t xMutexBuffer;
37+
38+
TaskHandle_t ledOnTask, ledOffTask;
39+
40+
void setup() {
41+
SERIAL_PORT.begin(115200);
42+
pinMode(LED_BUILTIN, OUTPUT);
43+
44+
/* Create a mutex semaphore without using any dynamic memory
45+
allocation. The mutex's data structures will be saved into
46+
the xMutexBuffer variable. */
47+
xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
48+
49+
ledOnTask = xTaskCreateStatic(led_ON, "led_ON", STACK_SIZE, NULL, configMAX_PRIORITIES - 1, xStack_A, &xTaskBuffer_A);
50+
#if defined(PICO_CYW43_SUPPORTED)
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+
#if defined(PICO_CYW43_SUPPORTED)
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+
}
60+
61+
void led_ON(void *pvParameters)
62+
{
63+
(void) pvParameters;
64+
delay(100);
65+
while (1)
66+
{
67+
xSemaphoreTake( xSemaphore, ( TickType_t ) portMAX_DELAY );
68+
SERIAL_PORT.println("LED ON!");
69+
digitalWrite(LED_BUILTIN, HIGH);
70+
delay(BLINK_ON_TIME);
71+
xSemaphoreGive( xSemaphore );
72+
delay(1);
73+
}
74+
}
75+
76+
void led_OFF(void *pvParameters)
77+
{
78+
(void) pvParameters;
79+
delay(100);
80+
while (1)
81+
{
82+
xSemaphoreTake( xSemaphore, ( TickType_t ) portMAX_DELAY );
83+
SERIAL_PORT.println("LED OFF!");
84+
digitalWrite(LED_BUILTIN, LOW);
85+
delay(BLINK_OFF_TIME);
86+
xSemaphoreGive( xSemaphore );
87+
delay(1);
88+
}
89+
}
90+
91+
void loop() {
92+
SERIAL_PORT.println("Hello!");
93+
delay(1000);
94+
}

0 commit comments

Comments
 (0)