-
Notifications
You must be signed in to change notification settings - Fork 6
Add preliminary support for ESP IDF and FreeRTOS #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sbgaia
wants to merge
24
commits into
main
Choose a base branch
from
esp32
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9e35f8b
Add support for the ESP32 platform and related example projects.
sbgaia d3f0a58
Add sdkconfig to .gitignore
sbgaia 9aadfc8
Remove IDF setup from buildAll.sh script
sbgaia eb59df8
Refactor platform name from ESP32 to ESPIDF, updating related CMake a…
sbgaia a6772fc
Add platform support to include FreeRTOS and ESP-IDF, updating CMake …
sbgaia 15aefa0
Revert unused parameter handling to (void)super for consistency.
sbgaia 91feffc
Format code.
sbgaia ef8c296
Remove sdkconfig
sbgaia 9922666
Update CPU clock frequency in FreeRTOSConfig.h for raspberry pico
sbgaia 08e341b
Improve comments for unused parameter suppression in CMakeLists.txt
sbgaia 7821fbc
Refactor timeout handling in CMakeLists.txt files and update build sc…
sbgaia ee4ca35
Add README.md for Reactor-UC examples
sbgaia e5e19ee
Add startup reaction in TimerSource for initialization procedures (e.…
sbgaia 039fcb2
Add startup reaction in hello and blink examples
sbgaia ca7e405
Enable tick hook and add overflow handling for 32-bit architectures i…
sbgaia d1b2c3c
Enable tick hook in FreeRTOSConfig
sbgaia 7b593ba
Refactor pico_toggle_led invoked in startup reaction
sbgaia 435f07c
Refactor pico_toggle_led invoked in startup reaction
sbgaia 42785c9
Enable USB and UART for blinky example
sbgaia 8f09e15
Add TimerSource startup reaction
sbgaia a7e1763
Add startup reaction in riot examples
sbgaia eb84f3e
Add startup reaction in zephyr examples
sbgaia ea9bb7c
Format code
sbgaia ba85baa
Fix platform default to FREERTOS in CMakeLists.txt
sbgaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ cmake-build-release | |
| doc/html | ||
| doc/latex | ||
| doc/markdown/platform | ||
| sdkconfig | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
|
|
||
sbgaia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
| set(PLATFORM "ESP_IDF" CACHE STRING "Platform to target") | ||
| set(BUILD_EXAMPLES OFF CAHCHE BOOL) | ||
| set(TIMEOUT "1" ON CACHE STRING "Timeout in seconds, disable for infinite") | ||
sbgaia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if(TIMEOUT) | ||
| add_compile_definitions(TIMEOUT=${TIMEOUT}) | ||
| else() | ||
| add_compile_definitions(TIMEOUT_FOREVER) | ||
| endif() | ||
|
|
||
| set(IDF_COMPONENTS "freertos" "esptool_py" "driver" "led_strip") | ||
|
|
||
| if(DEFINED ENV{IDF_PATH}) | ||
| else() | ||
| message(FATAL_ERROR "IDF_PATH environment variable not set") | ||
| endif() | ||
|
|
||
| # Include for ESP-IDF build system functions | ||
| include($ENV{IDF_PATH}/tools/cmake/idf.cmake) | ||
| # Set led_strip component path | ||
| set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../idf-extra-components/led_strip) | ||
| idf_build_component($ENV{IDF_PATH}/../idf-extra-components/led_strip) | ||
|
|
||
| project(blink) | ||
|
|
||
| # Create idf::{target} and idf::freertos static libraries | ||
| idf_build_process(${IDF_TARGET} | ||
| COMPONENTS ${IDF_COMPONENTS} | ||
| SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig | ||
| BUILD_DIR ${CMAKE_BINARY_DIR}) | ||
|
|
||
| add_subdirectory(../../../ reactor-uc) | ||
|
|
||
| # suppress unused parameter warnings | ||
| target_compile_options(reactor-uc PRIVATE -Wno-unused-parameter) | ||
|
|
||
| set(elf_file ${CMAKE_PROJECT_NAME}.elf) | ||
| add_executable(${elf_file} main.c) | ||
| target_link_libraries(${elf_file} PRIVATE reactor-uc idf::led_strip idf::driver) | ||
|
|
||
| idf_build_executable(${elf_file}) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #include <stdio.h> | ||
| #include <inttypes.h> | ||
| #include "sdkconfig.h" | ||
| #include "freertos/FreeRTOS.h" | ||
| #include "freertos/task.h" | ||
| #include "esp_chip_info.h" | ||
| #include "esp_flash.h" | ||
| #include "esp_system.h" | ||
| #include "reactor-uc/reactor-uc.h" | ||
| #include "reactor-uc/environment.h" | ||
sbgaia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include "sys/time.h" | ||
| #include "esp_timer.h" | ||
| #include "../../common/timer_source.h" | ||
| #include "led_strip.h" | ||
| #include "driver/gpio.h" | ||
|
|
||
| #define BLINK_GPIO 8 | ||
| #define CONFIG_BLINK_LED_STRIP 1 | ||
| #define CONFIG_BLINK_LED_STRIP_BACKEND_SPI 1 | ||
| static uint8_t s_led_state = 0; | ||
|
|
||
| #ifdef CONFIG_BLINK_LED_STRIP | ||
|
|
||
| static led_strip_handle_t led_strip; | ||
|
|
||
| static void blink_led(void) | ||
| { | ||
| /* If the addressable LED is enabled */ | ||
| if (s_led_state) { | ||
| /* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */ | ||
| led_strip_set_pixel(led_strip, 0, 16, 16, 16); | ||
| /* Refresh the strip to send data */ | ||
| led_strip_refresh(led_strip); | ||
| } else { | ||
| /* Set all LED off to clear all pixels */ | ||
| led_strip_clear(led_strip); | ||
| } | ||
| } | ||
|
|
||
| static void configure_led(void) | ||
| { | ||
| printf("Example configured to blink addressable LED!"); | ||
| /* LED strip initialization with the GPIO and pixels number*/ | ||
| led_strip_config_t strip_config = { | ||
| .strip_gpio_num = BLINK_GPIO, | ||
| .max_leds = 1, // at least one LED on board | ||
| }; | ||
| #if CONFIG_BLINK_LED_STRIP_BACKEND_RMT | ||
| led_strip_rmt_config_t rmt_config = { | ||
| .resolution_hz = 10 * 1000 * 1000, // 10MHz | ||
| .flags.with_dma = false, | ||
| }; | ||
| ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); | ||
| #elif CONFIG_BLINK_LED_STRIP_BACKEND_SPI | ||
| led_strip_spi_config_t spi_config = { | ||
| .spi_bus = SPI2_HOST, | ||
| .flags.with_dma = true, | ||
| }; | ||
| ESP_ERROR_CHECK(led_strip_new_spi_device(&strip_config, &spi_config, &led_strip)); | ||
| #else | ||
| #error "unsupported LED strip backend" | ||
| #endif | ||
| /* Set all LED off to clear all pixels */ | ||
| led_strip_clear(led_strip); | ||
| } | ||
|
|
||
| #elif CONFIG_BLINK_LED_GPIO | ||
|
|
||
| static void blink_led(void) | ||
| { | ||
| /* Set the GPIO level according to the state (LOW or HIGH)*/ | ||
| gpio_set_level(BLINK_GPIO, s_led_state); | ||
| } | ||
|
|
||
| static void configure_led(void) | ||
| { | ||
| ESP_LOGI(TAG, "Example configured to blink GPIO LED!"); | ||
| gpio_reset_pin(BLINK_GPIO); | ||
| /* Set the GPIO as a push/pull output */ | ||
| gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); | ||
| } | ||
|
|
||
| #else | ||
| #error "unsupported LED type" | ||
| #endif | ||
|
|
||
| LF_DEFINE_REACTION_BODY(TimerSource, r) { | ||
| LF_SCOPE_SELF(TimerSource); | ||
| LF_SCOPE_ENV(); | ||
| printf("Turning the LED %s! @ lt=%lld, pt=%lld\n", s_led_state == true ? "ON" : "OFF", env->get_elapsed_logical_time(env), env->get_physical_time(env)); | ||
| blink_led(); | ||
| /* Toggle the LED state */ | ||
| s_led_state = !s_led_state; | ||
| } | ||
|
|
||
| void app_main(void) | ||
| { | ||
| configure_led(); | ||
sbgaia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lf_start(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Set the target platform | ||
| IDF_TARGET="esp32c6" | ||
| # List of folders | ||
| FOLDERS=("hello" "blink") | ||
|
|
||
| # Iterate over each folder and execute the command | ||
| for dir in "${FOLDERS[@]}"; do | ||
| echo "Entering $dir" | ||
| pushd $dir | ||
|
|
||
| rm -rf build && mkdir build && cd build | ||
| cmake .. -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-${IDF_TARGET}.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPLATFORM=ESP_IDF -DIDF_TARGET=${IDF_TARGET} -GNinja | ||
| cmake --build . -j | ||
| popd | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| cmake_minimum_required(VERSION 3.20.0) | ||
| set(PLATFORM "ESP_IDF" CACHE STRING "Platform to target") | ||
| set(BUILD_EXAMPLES OFF CAHCHE BOOL) | ||
| set(TIMEOUT "1" ON CACHE STRING "Timeout in seconds, disable for infinite") | ||
|
|
||
| if(TIMEOUT) | ||
| add_compile_definitions(TIMEOUT=${TIMEOUT}) | ||
| else() | ||
| add_compile_definitions(TIMEOUT_FOREVER) | ||
| endif() | ||
|
|
||
| set(IDF_COMPONENTS "freertos" "esptool_py") | ||
|
|
||
| if(DEFINED ENV{IDF_PATH}) | ||
| else() | ||
| message(FATAL_ERROR "IDF_PATH environment variable not set") | ||
| endif() | ||
|
|
||
| # Include for ESP-IDF build system functions | ||
| include($ENV{IDF_PATH}/tools/cmake/idf.cmake) | ||
|
|
||
| project(hello) | ||
|
|
||
| # Create idf::{target} and idf::freertos static libraries | ||
| idf_build_process(${IDF_TARGET} | ||
| COMPONENTS ${IDF_COMPONENTS} | ||
| SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig | ||
| BUILD_DIR ${CMAKE_BINARY_DIR}) | ||
|
|
||
| add_subdirectory(../../../ reactor-uc) | ||
|
|
||
| # suppress unused parameter warnings | ||
| target_compile_options(reactor-uc PRIVATE -Wno-unused-parameter) | ||
|
|
||
| set(elf_file ${CMAKE_PROJECT_NAME}.elf) | ||
| add_executable(${elf_file} main.c) | ||
| target_link_libraries(${elf_file} PRIVATE reactor-uc) | ||
|
|
||
| idf_build_executable(${elf_file}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #include <stdio.h> | ||
| #include <inttypes.h> | ||
| #include "sdkconfig.h" | ||
| #include "freertos/FreeRTOS.h" | ||
| #include "freertos/task.h" | ||
| #include "esp_chip_info.h" | ||
| #include "esp_flash.h" | ||
| #include "esp_system.h" | ||
| #include "reactor-uc/reactor-uc.h" | ||
| #include "reactor-uc/environment.h" | ||
| #include "sys/time.h" | ||
| #include "esp_timer.h" | ||
| #include "../../common/timer_source.h" | ||
|
|
||
| LF_DEFINE_REACTION_BODY(TimerSource, r) { | ||
| LF_SCOPE_SELF(TimerSource); | ||
| LF_SCOPE_ENV(); | ||
| printf("Hello World @ lt=%lld, pt=%lld\n", env->get_elapsed_logical_time(env), env->get_physical_time(env)); | ||
|
|
||
| /* Print chip information */ | ||
| esp_chip_info_t chip_info; | ||
| uint32_t flash_size; | ||
| esp_chip_info(&chip_info); | ||
|
|
||
| printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", | ||
| CONFIG_IDF_TARGET, | ||
| chip_info.cores, | ||
| (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "", | ||
| (chip_info.features & CHIP_FEATURE_BT) ? "BT" : "", | ||
| (chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "", | ||
| (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : ""); | ||
|
|
||
| unsigned major_rev = chip_info.revision / 100; | ||
| unsigned minor_rev = chip_info.revision % 100; | ||
| printf("silicon revision v%d.%d, ", major_rev, minor_rev); | ||
|
|
||
| if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) { | ||
| printf("Get flash size failed"); | ||
| return; | ||
| } | ||
|
|
||
| printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), | ||
| (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); | ||
|
|
||
| printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); | ||
| } | ||
|
|
||
| void app_main(void) | ||
| { | ||
| lf_start(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Set the target board | ||
| PICO_BOARD="pico_w" | ||
| PICO_FOLDER="pico" | ||
| echo "Entering $PICO_FOLDER" | ||
| pushd $PICO_FOLDER | ||
|
|
||
| rm -rf build && mkdir build && cd build | ||
| cmake -DPICO_BOARD=pico_w -DPLATFORM=FREERTOS -DTIMEOUT=OFF .. | ||
| cmake --build . -j | ||
| popd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| cmake_minimum_required(VERSION 3.20.0) | ||
| set(PLATFORM "PICO" CACHE STRING "Platform to target") | ||
| set(BUILD_EXAMPLES OFF CAHCHE BOOL) | ||
| set(TIMEOUT "1" ON CACHE STRING "Timeout in seconds, disable for infinite") | ||
|
|
||
| if(TIMEOUT) | ||
| add_compile_definitions(TIMEOUT=${TIMEOUT}) | ||
| else() | ||
| add_compile_definitions(TIMEOUT_FOREVER) | ||
| endif() | ||
|
|
||
| if (DEFINED ENV{PICO_SDK_PATH}) | ||
| include("$ENV{PICO_SDK_PATH}/pico_sdk_init.cmake") | ||
| else() | ||
| message(FATAL_ERROR "PICO_SDK_PATH environment variable not set") | ||
| endif() | ||
|
|
||
| if (DEFINED ENV{FREERTOS_KERNEL_PATH}) | ||
| include("$ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake") | ||
| else() | ||
| message(FATAL_ERROR "FREERTOS_KERNEL_PATH environment variable not set") | ||
| endif() | ||
|
|
||
| if (NOT DEFINED ENV{FREERTOS_DEMO_PATH}) | ||
| message(FATAL_ERROR "FREERTOS_DEMO_PATH environment variable not set") | ||
| endif() | ||
|
|
||
| project(reactor-uc-pico) | ||
| pico_sdk_init() | ||
|
|
||
| add_executable(blinky src/blinky.c) | ||
|
|
||
| pico_enable_stdio_usb(blinky 1) | ||
| pico_enable_stdio_uart(blinky 0) | ||
| target_include_directories(blinky PRIVATE | ||
| ${CMAKE_CURRENT_LIST_DIR} | ||
| $ENV{FREERTOS_DEMO_PATH}/Common/include) | ||
|
|
||
| # Set FreeRTOSConfig path for the reactor-uc library | ||
| set(FREERTOS_CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/include) | ||
|
|
||
| add_subdirectory(../../../ reactor-uc) | ||
| target_link_libraries(blinky PRIVATE reactor-uc pico_stdlib pico_sync) | ||
|
|
||
| if (PICO_CYW43_SUPPORTED) | ||
| target_link_libraries(blinky PRIVATE pico_cyw43_arch_none) | ||
| endif() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.