Skip to content

Commit 9098d3d

Browse files
committed
Arduino C6 ULP example
1 parent ab68ffd commit 9098d3d

File tree

12 files changed

+273
-0
lines changed

12 files changed

+273
-0
lines changed

.github/workflows/examples.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- "examples/espidf-arduino-matter-light"
2727
- "examples/espidf-arduino-blink"
2828
- "examples/espidf-arduino-littlefs"
29+
- "examples/espidf-arduino-C6-ULP-blink"
2930
- "examples/espidf-blink"
3031
- "examples/espidf-coap-server"
3132
- "examples/espidf-exceptions"
@@ -44,6 +45,8 @@ jobs:
4445
example: "examples/espidf-ulp-lp"
4546
- os: windows-latest
4647
example: "examples/espidf-ulp-riscv"
48+
- os: windows-latest
49+
example: "examples/espidf-arduino-C6-ULP-blink"
4750
- os: windows-latest
4851
example: "examples/espidf-arduino-matter-light"
4952
runs-on: ${{ matrix.os }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode
3+
.dependencies.lock
4+
sdkconfig.esp32c6
5+
managed_components
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.16.0)
2+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
3+
project(espidf-arduino-c6-ulp-blink)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Arduino ULP Example for the ESP32-C6
2+
3+
This example shows how to run a C program on the ESP32-C6 ULP core with Arduino (as an component of ESP-IDF)
4+
5+
## Two programs run parallel
6+
7+
1. **Arduino on the High Power Core (HP Core):** The Arduino program blinks the onboard RGB
8+
2. **C Program on the Ultra-Low Power Core (ULP):** The ULP C program blinks an external LED connected to GPIO3
9+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter, extra scripting
4+
; Upload options: custom port, speed, and extra flags
5+
; Library options: dependencies, extra library storages
6+
;
7+
; Documentation: https://docs.platformio.org/page/projectconf.html
8+
9+
[env:esp32c6]
10+
platform = espressif32
11+
framework = arduino, espidf
12+
board = esp32-c6-devkitc-1
13+
monitor_speed = 115200
14+
lib_deps =
15+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# C6 devkit has 8 MB flash
2+
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
3+
4+
# Enable ULP
5+
CONFIG_ULP_COPROC_ENABLED=y
6+
CONFIG_ULP_COPROC_TYPE_LP_CORE=y
7+
CONFIG_ULP_COPROC_RESERVE_MEM=8192
8+
9+
# Set log level
10+
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
11+
CONFIG_BOOTLOADER_LOG_LEVEL=2
12+
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
13+
CONFIG_LOG_DEFAULT_LEVEL=2
14+
15+
# Arduino settings
16+
CONFIG_AUTOSTART_ARDUINO=y
17+
CONFIG_FREERTOS_HZ=1000
18+
CONFIG_MBEDTLS_PSK_MODES=y
19+
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
idf_component_register(SRCS "main.cpp")
2+
3+
#
4+
# ULP support additions to component CMakeLists.txt.
5+
#
6+
# 1. The ULP app name must be "ulp_main"
7+
set(ulp_app_name ulp_main)
8+
#
9+
# 2. Specify all assembly source files.
10+
# Paths are relative because ULP files are placed into a special directory "ulp"
11+
# in the root of the project
12+
set(ulp_s_sources "../ulp/blink.c")
13+
#
14+
# 3. List all the component source files which include automatically
15+
# generated ULP export file, ${ulp_app_name}.h:
16+
set(ulp_exp_dep_srcs "main.c")
17+
#
18+
# 4. Call function to build ULP binary and embed in project using the argument
19+
# values above.
20+
ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs})
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <Arduino.h>
2+
#include <Adafruit_NeoPixel.h>
3+
#include "ulp_lp_core.h"
4+
#include "esp_err.h"
5+
6+
// Define the built-in RGB LED pin and number of LEDs
7+
#define LED_PIN 8
8+
#define NUM_LEDS 1
9+
10+
Adafruit_NeoPixel rgbLed(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
11+
12+
// Define some colors
13+
struct RGB {
14+
uint8_t r, g, b;
15+
};
16+
17+
constexpr RGB COLOR_RED = {255, 0, 0};
18+
constexpr RGB COLOR_GREEN = {0, 255, 0};
19+
constexpr RGB COLOR_BLUE = {0, 0, 255};
20+
constexpr RGB COLOR_OFF = {0, 0, 0};
21+
22+
extern const uint8_t bin_start[] asm("_binary_ulp_main_bin_start"); //refering to app name ulp_main defined in CMakelists.txt
23+
extern const uint8_t bin_end[] asm("_binary_ulp_main_bin_end"); //refering to app name ulp_main defined in CMakelists.txt
24+
25+
void start_ulp_program() {
26+
// Change: Load the ULP binary into RTC memory
27+
ESP_ERROR_CHECK(ulp_lp_core_load_binary(bin_start, (bin_end - bin_start)));
28+
29+
// Change: Configure the ULP LP core wake-up source and timer
30+
ulp_lp_core_cfg_t cfg = {
31+
.wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER, // Wake up using LP timer
32+
.lp_timer_sleep_duration_us = 1000000, // 1-second sleep duration
33+
};
34+
35+
// Change: Start the ULP LP core program
36+
ESP_ERROR_CHECK(ulp_lp_core_run(&cfg));
37+
}
38+
39+
void setColor(const RGB& color) {
40+
rgbLed.setPixelColor(0, rgbLed.Color(color.r, color.g, color.b));
41+
rgbLed.show();
42+
}
43+
44+
void setup() {
45+
Serial.begin(115200);
46+
Serial.println("Starting ULP Program...");
47+
start_ulp_program();
48+
Serial.println("Starting RGB LED blinking...");
49+
rgbLed.begin(); // Initialize the NeoPixel library
50+
rgbLed.show(); // Turn off all LEDs initially
51+
}
52+
53+
void loop() {
54+
Serial.println("Setting color to RED");
55+
setColor(COLOR_RED);
56+
delay(1000);
57+
58+
Serial.println("Setting color to GREEN");
59+
setColor(COLOR_GREEN);
60+
delay(1000);
61+
62+
Serial.println("Setting color to BLUE");
63+
setColor(COLOR_BLUE);
64+
delay(1000);
65+
66+
Serial.println("Turning off LED");
67+
setColor(COLOR_OFF);
68+
delay(1000);
69+
}

0 commit comments

Comments
 (0)