Skip to content

Allow calls to timer functions within ISR #11629

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
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

angelnu
Copy link

@angelnu angelnu commented Jul 22, 2025

Description of Change

This PR allows to call some of the timer functions within interrupt context. TSee https://github.com/espressif/esp-idf/blob/master/components/esp_driver_gptimer/linker.lf for what functions are running in RAM.

I had to remove the logs of the functions. The alternative would be creating _isr alternative functions.

Tests scenarios

I have tested my Pull Request on Arduino-esp32 core v3.1.13 with ESP32 and ESP32-WROM Board with this scenario

Related links

NA

@angelnu angelnu requested a review from a team as a code owner July 22, 2025 19:46
@CLAassistant
Copy link

CLAassistant commented Jul 22, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Jul 22, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello angelnu, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against e3a0a3a

Copy link
Contributor

github-actions bot commented Jul 22, 2025

Test Results

 76 files   76 suites   13m 11s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commit e3a0a3a.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jul 23, 2025

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32C5000.000.00000.000.00
ESP32P4000.000.00000.000.00
ESP32S3💚 -1600.000.00000.000.00
ESP32S2000.000.00000.000.00
ESP32C3000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32H2000.000.00000.000.00
ESP32000.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
EEPROM/examples/eeprom_class00--00--00000000
EEPROM/examples/eeprom_extra00--00--00000000
EEPROM/examples/eeprom_write00--00--00000000
ESP32/examples/AnalogOut/LEDCFade00--00--00000000
ESP32/examples/AnalogOut/LEDCGammaFade00--------0000--
ESP32/examples/AnalogOut/LEDCSingleChannel00--00--00000000
ESP32/examples/AnalogOut/LEDCSoftwareFade00--00--00000000
ESP32/examples/AnalogOut/SigmaDelta000000--00000000
ESP32/examples/AnalogOut/ledcFrequency000000--00000000
ESP32/examples/AnalogOut/ledcWrite_RGB000000--00000000
ESP32/examples/AnalogRead000000--00000000
ESP32/examples/AnalogReadContinuous0000000000000000
ESP32/examples/ArduinoStackSize0000000000000000
ESP32/examples/CI/CIBoardsTest0000000000000000
ESP32/examples/ChipID/GetChipID0000000000000000
ESP32/examples/DeepSleep/TimerWakeUp000000000000--00
ESP32/examples/FreeRTOS/BasicMultiThreading0000000000000000
ESP32/examples/FreeRTOS/Mutex0000000000000000
ESP32/examples/FreeRTOS/Queue0000000000000000
ESP32/examples/FreeRTOS/Semaphore0000000000000000
ESP32/examples/GPIO/BlinkRGB0000000000000000
ESP32/examples/GPIO/FunctionalInterrupt0000000000000000
ESP32/examples/GPIO/FunctionalInterruptLambda0000000000000000
ESP32/examples/GPIO/FunctionalInterruptStruct0000000000000000
ESP32/examples/GPIO/GPIOInterrupt0000000000000000
ESP32/examples/HWCDC_Events000000--000000--
ESP32/examples/MacAddress/GetMacAddress0000000000000000
ESP32/examples/RMT/Legacy_RMT_Driver_Compatible0000000000000000
ESP32/examples/RMT/RMTCallback0000000000000000
ESP32/examples/RMT/RMTLoopback0000000000000000
ESP32/examples/RMT/RMTReadXJT0000000000000000
ESP32/examples/RMT/RMTWrite_RGB_LED0000000000000000
ESP32/examples/RMT/RMT_CPUFreq_Test0000000000000000
ESP32/examples/RMT/RMT_EndOfTransmissionState0000000000000000
ESP32/examples/RMT/RMT_LED_Blink0000000000000000
ESP32/examples/ResetReason/ResetReason0000000000000000
ESP32/examples/ResetReason/ResetReason20000000000000000
ESP32/examples/Serial/BaudRateDetect_Demo0000000000000000
ESP32/examples/Serial/OnReceiveError_BREAK_Demo0000000000000000
ESP32/examples/Serial/OnReceive_Demo0000000000000000
ESP32/examples/Serial/RS485_Echo_Demo000000000000--00
ESP32/examples/Serial/RxFIFOFull_Demo000000000000--00
ESP32/examples/Serial/RxTimeout_Demo000000000000--00
ESP32/examples/Serial/Serial_All_CPU_Freqs000000000000--00
ESP32/examples/Serial/Serial_STD_Func_OnReceive000000000000--00
ESP32/examples/Serial/onReceiveExample000000000000--00
ESP32/examples/Template/ExampleTemplate000000000000--00
ESP32/examples/Time/SimpleTime000000000000----
ESP32/examples/Timer/RepeatTimer000000000000----
ESP32/examples/Timer/WatchdogTimer000000000000----
ESP32/examples/Utilities/HEXBuilder00--00000000----
ESP32/examples/Utilities/MD5Builder00--00000000----
ESP32/examples/Utilities/SHA1Builder00--00000000----
ESP_I2S/examples/ES8388_loopback00--0000--00----
ESP_I2S/examples/Simple_tone00--0000--00----
ESP_NOW/examples/ESP_NOW_Broadcast_Master00--0000--00----
ESP_NOW/examples/ESP_NOW_Broadcast_Slave00--0000--00----
ESP_NOW/examples/ESP_NOW_Network00----00--00----
ESP_NOW/examples/ESP_NOW_Serial00----00--00----
ESPmDNS/examples/mDNS-SD_Extended00----00--00----
ESPmDNS/examples/mDNS_Web_Server00----00--00----
Ethernet/examples/ETH_W5500_Arduino_SPI00----00--00----
Ethernet/examples/ETH_W5500_IDF_SPI00----00--------
Ethernet/examples/ETH_WIFI_BRIDGE00----00--------
Zigbee/examples/Zigbee_Pressure_Flow_Sensor00--------00----
Zigbee/examples/Zigbee_Range_Extender00--00000000--00
Zigbee/examples/Zigbee_Scan_Networks00--------00----
Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy00--------00----
Zigbee/examples/Zigbee_Temperature_Sensor00--------00----
Zigbee/examples/Zigbee_Thermostat00--000000000000
Zigbee/examples/Zigbee_Vibration_Sensor00--------0000--
Zigbee/examples/Zigbee_Wind_Speed_Sensor00--------0000--
Zigbee/examples/Zigbee_Window_Covering00--------0000--
ESP32/examples/DeepSleep/TouchWakeUp--000000------00
ESP32/examples/TWAI/TWAIreceive--0000000000--00
ESP32/examples/TWAI/TWAItransmit--0000000000--00
ESP32/examples/Touch/TouchInterrupt--000000--------
ESP32/examples/Touch/TouchRead--000000--------
WiFi/examples/WiFiTelnetToSerial--00------------
WiFi/examples/WiFiUDPClient--00------------
Wire/examples/WireMaster--00------------
Wire/examples/WireScan--00------------
Wire/examples/WireSlave--00------------
Wire/examples/WireSlaveFunctionalCallback--00------------
ESP32/examples/Camera/CameraWebServer (1)----0000------00
ESP32/examples/Camera/CameraWebServer (2)----0000------00
ESP32/examples/Camera/CameraWebServer (3)----00----------
ESP32/examples/DeepSleep/ExternalWakeUp----0000------00
ESP_I2S/examples/Record_to_WAV----00----------
Zigbee/examples/Zigbee_Analog_Input_Output----00----------
Zigbee/examples/Zigbee_Color_Dimmer_Switch----00--------00
Zigbee/examples/Zigbee_Electrical_AC_Sensor----00--00----00
Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase----00--00----00
Zigbee/examples/Zigbee_Fan_Control----000000----00
Zigbee/examples/Zigbee_Gateway----💚 -1600000----00
Zigbee/examples/Zigbee_On_Off_MultiSwitch----000000----00
Zigbee/examples/Zigbee_On_Off_Switch----000000----00
Zigbee/examples/Zigbee_Power_Outlet----00000000--00
FFat/examples/FFat_Test------00--------
BLE/examples/iBeacon--------00--00--
DNSServer/examples/CaptivePortal--------00----00
BluetoothSerial/examples/DiscoverConnect--------------00
BluetoothSerial/examples/GetLocalMAC--------------00
BluetoothSerial/examples/SerialToSerialBT--------------00
BluetoothSerial/examples/SerialToSerialBTM--------------00
BluetoothSerial/examples/SerialToSerialBT_Legacy--------------00
BluetoothSerial/examples/SerialToSerialBT_SSP--------------00
BluetoothSerial/examples/bt_classic_device_discovery--------------00
BluetoothSerial/examples/bt_remove_paired_devices--------------00
ESP32/examples/DeepSleep/SmoothBlink_ULP_Code--------------00

@me-no-dev
Copy link
Member

me-no-dev commented Jul 23, 2025

All GP_TIMER functions are not by default it IRAM. They are put in IRAM only when CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is set in sdkconfig (which is not true for Arduino). In order to accept this PR, functions should be put in IRAM only when CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM is enabled. Something like:

#if CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
#define TIMER_IRAM IRAM_ATTR
#else
#define TIMER_IRAM
#endif

inline TIMER_IRAM uint64_t timerRead(hw_timer_t *timer) {
//......

Also do not remove error logs. They can be disabled if IRAM is in use (or make them conditional like above)

#ifndef CONFIG_GPTIMER_CTRL_FUNC_IN_IRAM
  log_e("Timer handle is NULL");
#endif

@lucasssvaz lucasssvaz added the Status: Pending Merge Pull Request is ready to be merged label Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Merge Pull Request is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants