From 507f946fb1178636e83d90d653ecdbffecddf4c2 Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Thu, 7 Jul 2022 13:07:32 -0700 Subject: [PATCH 1/5] Compile error if CONFIG_FREERTOS_HZ != 1000 --- cores/esp32/esp32-hal-misc.c | 4 ++++ docs/source/esp-idf_component.rst | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 1a71b0e86f9..ee8bab4f2fc 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -175,6 +175,10 @@ unsigned long ARDUINO_ISR_ATTR millis() void delay(uint32_t ms) { + _Static_assert( + portTICK_PERIOD_MS == 1, + "esp32-arduino requires 1ms tick (CONFIG_FREERTOS_HZ=1000)" + ); vTaskDelay(ms / portTICK_PERIOD_MS); } diff --git a/docs/source/esp-idf_component.rst b/docs/source/esp-idf_component.rst index f153f267e6b..e2049b4e2bf 100644 --- a/docs/source/esp-idf_component.rst +++ b/docs/source/esp-idf_component.rst @@ -140,8 +140,7 @@ If you are writing code that does not require Arduino to compile and you want yo FreeRTOS Tick Rate (Hz) ----------------------- -You might notice that Arduino-esp32's `delay()` function will only work in multiples of 10ms. That is because, by default, esp-idf handles task events 100 times per second. -To fix that behavior, you need to set FreeRTOS tick rate to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`. +The Arduino component requires the FreeRTOS tick rate `CONFIG_FREERTOS_HZ` set to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`. Compilation Errors ------------------ From 2fd573e2bd84285f3acfb51778c1ea6c247d6516 Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Fri, 8 Jul 2022 10:30:20 -0700 Subject: [PATCH 2/5] add a check at the CMake level, per feedback --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c324db580..3352b596bb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,12 @@ set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl b idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) +if(NOT CONFIG_FREERTOS_HZ EQUAL 1000 AND NOT "$ENV{ARDUINO_SKIP_TICK_CHECK}") + # See delay() in cores/esp32/esp32-hal-misc.c. + message(FATAL_ERROR "esp32-arduino requires CONFIG_FREERTOS_HZ=1000 " + "(currently ${CONFIG_FREERTOS_HZ}") +endif() + string(TOUPPER ${CONFIG_ARDUINO_VARIANT} idf_target_caps) target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 From 75398cbe54599d098ff1df7c9b6875911199a198 Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Fri, 8 Jul 2022 10:31:18 -0700 Subject: [PATCH 3/5] fix a punctuation glitch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3352b596bb3..8e065f90605 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,7 @@ idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_incl if(NOT CONFIG_FREERTOS_HZ EQUAL 1000 AND NOT "$ENV{ARDUINO_SKIP_TICK_CHECK}") # See delay() in cores/esp32/esp32-hal-misc.c. message(FATAL_ERROR "esp32-arduino requires CONFIG_FREERTOS_HZ=1000 " - "(currently ${CONFIG_FREERTOS_HZ}") + "(currently ${CONFIG_FREERTOS_HZ})") endif() string(TOUPPER ${CONFIG_ARDUINO_VARIANT} idf_target_caps) From 4f487e0c2a64cb3bc40438a3f6158282926db661 Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Wed, 24 Aug 2022 18:06:23 -0400 Subject: [PATCH 4/5] Remove `_Static_assert` per feedback --- cores/esp32/esp32-hal-misc.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index ee8bab4f2fc..1a71b0e86f9 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -175,10 +175,6 @@ unsigned long ARDUINO_ISR_ATTR millis() void delay(uint32_t ms) { - _Static_assert( - portTICK_PERIOD_MS == 1, - "esp32-arduino requires 1ms tick (CONFIG_FREERTOS_HZ=1000)" - ); vTaskDelay(ms / portTICK_PERIOD_MS); } From 4266a8edf695b03fadc09369ecfed260526bab03 Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Thu, 25 Aug 2022 22:34:55 -0400 Subject: [PATCH 5/5] Set CONFIG_FREERTOS_HZ=1000 in CI test of Arduino-as-component --- .github/workflows/push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f2f75d7b1ac..c2fe46df8c7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -104,4 +104,5 @@ jobs: run: | . ${IDF_PATH}/export.sh idf.py create-project test + echo CONFIG_FREERTOS_HZ=1000 > test/sdkconfig.defaults idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build