esp32-H2 timer reboot forever

ZodiacGSK
Posts: 3
Joined: Sun Feb 18, 2024 11:48 pm

esp32-H2 timer reboot forever

Postby ZodiacGSK » Mon Feb 19, 2024 12:10 am

I have a problem, i'm using an esp32-H2 devkit and i made a simple program to make a chrono with a timer (i'm using the 3.0.0 alpha Arduino core, they changed the timer library). The problem is that if i put this line :(timerAttachInterrupt(timer, &AddSecondTimer);), i got this in the console in loop :
  1. ESP-ROM:esp32h2-20221101
  2. Build:Nov  1 2022
  3. rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT)
  4. Saved PC:0x400031b6
  5. SPIWP:0xee
  6. mode:DIO, clock div:1
  7. load:0x4083cfd0,len:0xb68
  8. load:0x4083efd0,len:0x2718
  9. load:0x408460e8,len:0x590
  10. entry 0x4083cfd0
  11. -------------------
  12. Initialization (0%)
  13. Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.
  14.  
  15. Core  0 register dump:
  16. MEPC    : 0x42001972  RA      : 0x42000042  SP      : 0x408146d0  GP      : 0x4080bd60  
  17. TP      : 0x4080896c  T0      : 0x400184be  T1      : 0x77270000  T2      : 0x00000000  
  18. S0/FP   : 0x00000000  S1      : 0x00000000  A0      : 0x00000000  A1      : 0x40800258  
  19. A2      : 0x00000000  A3      : 0xfffffffd  A4      : 0x0020001f  A5      : 0x4080025a  
  20. A6      : 0xfbdf0000  A7      : 0x000000fb  S2      : 0x00000000  S3      : 0x00000000  
  21. S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
  22. S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
  23. T3      : 0x4084e530  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000  
  24. MSTATUS : 0x00001881  MTVEC   : 0x40800001  MCAUSE  : 0x00000005  MTVAL   : 0x0000000c  
  25. MHARTID : 0x00000000  
  26. Stack memory:
  27. 408146d0: 0x00000000 0x4080c5b0 0x00000000 0x4080025a 0x00000000 0x00000000 0x00000000 0x4200002e
  28. 408146f0: 0x00000000 0x00000000 0x00000000 0x42002544 0x00000000 0x00000000 0x00000000 0x00000000
  29. 40814710: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
  30. 40814730: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0x00038c35 0x4080dbe4 0x4080dbe4
  31. 40814750: 0x2a40c24e 0xb5f82a4e 0x623ddc8d 0x83d6d812 0x253eb1d0 0x893576c2 0xfb0d9ab7 0xc70964f5
  32. 40814770: 0x41077229 0xeb94c6be 0xfdaf2cdb 0xbde1ed95 0x331ab35c 0xb0cf0919 0xc913d8c6 0xf290ca77
  33. 40814790: 0x2617a9dc 0x3262cc32 0xa3c46155 0x83a5ce1c 0x469de453 0x30088b5e 0x6d8f8a66 0x9df5a2ac
  34. 408147b0: 0x9d9bcc26 0x5b6592e6 0x07196bd6 0xdd7103b6 0x9a9c0c32 0x824601e1 0x94372a63 0x1cc258e1
  35. 408147d0: 0x8c7129e4 0xebd88e2a 0xb53b37e7 0x8aa8aaf1 0xa1676ae8 0x4db5715d 0xedadbae1 0x29854fd0
  36. 408147f0: 0xc175e726 0x5ba84343 0x9c68fbfb 0x70424984 0xc927b543 0xa833ae79 0xba66579b 0x27e762e8
  37. 40814810: 0x1c37b1dd 0xa44c2aab 0xf826a6b8 0x48f88a3f 0xf9b4edf9 0xdd8352c4 0xbf4490b8 0x623b46d1
  38. 40814830: 0x2e225854 0x343f4a1e 0x66a52879 0x8a85b676 0x6c8f1f2e 0x13e4b6cd 0x9cd68807 0x1bb9b0bb
  39. 40814850: 0xb7eccdfe 0xd20fe7d3 0xec9e7bdf 0x7e74e56e 0x9eab1673 0xa0ce8c71 0x12eee1dc 0xcee38452
  40. 40814870: 0x3170e725 0x49de1828 0xa5bf2d24 0x87807879 0xad450068 0x864fc28a 0x64f84e35 0xdcdd15dd
  41. 40814890: 0xa4071a44 0x0aade563 0x1c489ea6 0x8a57b0ce 0x3be7b880 0x25b889c6 0xd8144dc8 0xd3044e8b
  42. 408148b0: 0x05e3898a 0x1e8d4557 0xc461af7a 0xa7c76255 0x4eed4efb 0x2e1c6ac7 0xf15ef47f 0x3b6fe5d5
  43. 408148d0: 0x06b5cad3 0x6e4520c7 0x24cf32bf 0x9f2de4b3 0x32095f44 0x321d8c48 0xb465a83f 0xfe3192bb
  44. 408148f0: 0x2eb17522 0x162a21ab 0x80f2fde9 0x29742d28 0x06d83094 0xaf9b84e0 0xdbf4c33e 0xf0eb92cd
  45. 40814910: 0x1031429d 0x4b8da38b 0x8cf109aa 0x6144fae0 0xce606e4f 0x9dcb69cc 0x6d1bfee4 0xbf1657a8
  46. 40814930: 0x186a1e67 0x11c388f1 0x16307a08 0x33cfc436 0x5600d049 0xdac44cf8 0x0b530643 0xfdec219c
  47. 40814950: 0x142c3b83 0xd5949d85 0xc4d5d7c8 0xeb241daa 0x4294eaa3 0x3a5fb0b1 0xc58ec621 0x43b43cb5
  48. 40814970: 0x07ff43be 0xd1389007 0xc04e760b 0x5f8f4b52 0x1e2098e8 0x285a0a99 0xe622dc10 0xc4b7671a
  49. 40814990: 0xb1e449d1 0x3450a7b2 0x1f539882 0x46d0e970 0x2af83dfc 0xb687f3a6 0xa3919615 0xf258827d
  50. 408149b0: 0xbbbbba08 0x00f51a91 0xd3d68d5a 0x2348b9aa 0x1e1c5ccb 0xd8b42c02 0xdf6a83b2 0x2fc022bd
  51. 408149d0: 0xe49923b9 0x2490b526 0xd634e8f0 0xd5f33809 0xf9ec43fd 0xdf12348f 0x874fd1c2 0x1332aa7c
  52. 408149f0: 0x1cb5d1c5 0xc44c9ca2 0x6187d5ff 0x3f3779b5 0x90f5b36a 0x87774caa 0xa0fb1507 0xbcb64bd1
  53. 40814a10: 0x53254eba 0x9ccba018 0x63bea8b2 0x9792971d 0x1bf2504f 0xd65e1921 0xd26eb63c 0x4cf378ce
  54. 40814a30: 0x31bf4733 0x52d174a5 0xae0ffa42 0x54491b1b 0x3ac201ca 0xaa65c8d0 0x6a667faf 0x66ba8f1a
  55. 40814a50: 0x672366f2 0x911f57ea 0xebbc3ff2 0x1c447ae9 0x0bde6484 0x770af7fb 0xb278a79f 0x1d23c290
  56. 40814a70: 0x41285dee 0x209ddb4e 0xa0d10b3d 0x2478d472 0x82e499f3 0xa9592098 0x0dfa111c 0x71ee1897
  57. 40814a90: 0x26553823 0x981cac89 0x32a0f6c7 0x6f188415 0x6e961415 0x7e13b72b 0x0f9e4ece 0xf7234ac6
  58. 40814ab0: 0xaed40f06 0xaa05efe5 0xcd1cfb5d 0x70c2ddaa 0xc1bf09bb 0x3e2e5321 0xfa8eeb62 0x8adce929
  59.  
  60.  
  61.  
  62. ELF file SHA256: d383a8f0b1ac7154
  63.  
  64. Rebooting...
Here is the full code :
  1. hw_timer_t * timer = NULL;
  2.  
  3. void IRAM_ATTR AddSecondTimer()
  4. {
  5.   Serial.println("Tick");
  6. }
  7.  
  8. void PauseChrono()
  9. {
  10.   // Let's try to make this code work before
  11. }
  12.  
  13. void SetupTimer()
  14. {
  15.   timer = timerBegin(80);
  16.   // timerAttachInterrupt(timer, &AddSecondTimer);
  17.   // timerAlarm(timer, 1000000, true, 0);
  18.  
  19.   Serial.println("Initialization (100%)");
  20.   Serial.println("---------------------");
  21. }
  22.  
  23. void setup()
  24. {
  25.   Serial.begin(115200);
  26.   Serial.println("-------------------");
  27.   Serial.println("Initialization (0%)");
  28.   SetupTimer();
  29. }
  30.  
  31. void loop()
  32. {
  33.   //empty
  34. }
I'm a student and i'm not experienced, so it's maybe something really simple to resolve. Also if i put a value of 1000 or more to timerBegin(), no more error but AddSecondTimer() is never called.

ESP_Sprite
Posts: 9723
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32-H2 timer reboot forever

Postby ESP_Sprite » Mon Feb 19, 2024 3:25 am

Code: Select all

  Serial.println("Tick");
I think the issue us that you cannot call that code from an ISR.

ZodiacGSK
Posts: 3
Joined: Sun Feb 18, 2024 11:48 pm

Re: esp32-H2 timer reboot forever

Postby ZodiacGSK » Mon Feb 19, 2024 12:56 pm

So i tried changing the code and the problem still the same. I tried event without anything in AddSecondTimer, and same problem. I looked about this on internet
  1. Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.
, and people say it's maybe a "heap corruption". Here is the library behind
  1. /*
  2.  Arduino.h - Main include file for the Arduino SDK
  3.  Copyright (c) 2005-2013 Arduino Team.  All right reserved.
  4.  
  5.  This library is free software; you can redistribute it and/or
  6.  modify it under the terms of the GNU Lesser General Public
  7.  License as published by the Free Software Foundation; either
  8.  version 2.1 of the License, or (at your option) any later version.
  9.  
  10.  This library is distributed in the hope that it will be useful,
  11.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  Lesser General Public License for more details.
  14.  
  15.  You should have received a copy of the GNU Lesser General Public
  16.  License along with this library; if not, write to the Free Software
  17.  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18.  */
  19.  
  20. #pragma once
  21.  
  22. #include "soc/soc_caps.h"
  23. #if SOC_GPTIMER_SUPPORTED
  24.  
  25. #include "esp32-hal.h"
  26. #include "driver/gptimer_types.h"
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. struct timer_struct_t;
  33. typedef struct timer_struct_t hw_timer_t;
  34.  
  35. hw_timer_t * timerBegin(uint32_t frequency);
  36. void timerEnd(hw_timer_t * timer);
  37.  
  38. void timerStart(hw_timer_t * timer);
  39. void timerStop(hw_timer_t * timer);
  40. void timerRestart(hw_timer_t * timer);
  41. void timerWrite(hw_timer_t * timer, uint64_t val);
  42.  
  43. uint64_t timerRead(hw_timer_t * timer);
  44. uint64_t timerReadMicros(hw_timer_t * timer);
  45. uint64_t timerReadMilis(hw_timer_t * timer);
  46. double timerReadSeconds(hw_timer_t * timer);
  47.  
  48. uint32_t timerGetFrequency(hw_timer_t * timer);
  49.  
  50. void timerAttachInterrupt(hw_timer_t * timer, void (*userFunc)(void));
  51. void timerAttachInterruptArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg);
  52. void timerDetachInterrupt(hw_timer_t * timer);
  53.  
  54. void timerAlarm(hw_timer_t * timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count);
  55.  
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59.  
  60. #endif /* SOC_GPTIMER_SUPPORTED */
Any idea of what i'm doing wrong ?

ZodiacGSK
Posts: 3
Joined: Sun Feb 18, 2024 11:48 pm

Re: esp32-H2 timer reboot forever

Postby ZodiacGSK » Mon Feb 19, 2024 2:22 pm

I found the documentation for this version (https://docs.espressif.com/projects/ard ... timer.html) and even the exemple is not working.
  1. /*
  2.  Repeat timer example
  3.  
  4.  This example shows how to use hardware timer in ESP32. The timer calls onTimer
  5.  function every second. The timer can be stopped with button attached to PIN 0
  6.  (IO0).
  7.  
  8.  This example code is in the public domain.
  9.  */
  10.  
  11. // Stop button is attached to PIN 0 (IO0)
  12. #define BTN_STOP_ALARM    0
  13.  
  14. hw_timer_t * timer = NULL;
  15. volatile SemaphoreHandle_t timerSemaphore;
  16. portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
  17.  
  18. volatile uint32_t isrCounter = 0;
  19. volatile uint32_t lastIsrAt = 0;
  20.  
  21. void ARDUINO_ISR_ATTR onTimer(){
  22.   // Increment the counter and set the time of ISR
  23.   portENTER_CRITICAL_ISR(&timerMux);
  24.   isrCounter = isrCounter + 1;
  25.   lastIsrAt = millis();
  26.   portEXIT_CRITICAL_ISR(&timerMux);
  27.   // Give a semaphore that we can check in the loop
  28.   xSemaphoreGiveFromISR(timerSemaphore, NULL);
  29.   // It is safe to use digitalRead/Write here if you want to toggle an output
  30. }
  31.  
  32. void setup() {
  33.   Serial.begin(115200);
  34.  
  35.   // Set BTN_STOP_ALARM to input mode
  36.   pinMode(BTN_STOP_ALARM, INPUT);
  37.  
  38.   // Create semaphore to inform us when the timer has fired
  39.   timerSemaphore = xSemaphoreCreateBinary();
  40.  
  41.   // Set timer frequency to 1Mhz
  42.   timer = timerBegin(1000000);
  43.  
  44.   // Attach onTimer function to our timer.
  45.   timerAttachInterrupt(timer, &onTimer);
  46.  
  47.   // Set alarm to call onTimer function every second (value in microseconds).
  48.   // Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
  49.   timerAlarm(timer, 1000000, true, 0);
  50. }
  51.  
  52. void loop() {
  53.   // If Timer has fired
  54.   if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE){
  55.     uint32_t isrCount = 0, isrTime = 0;
  56.     // Read the interrupt count and time
  57.     portENTER_CRITICAL(&timerMux);
  58.     isrCount = isrCounter;
  59.     isrTime = lastIsrAt;
  60.     portEXIT_CRITICAL(&timerMux);
  61.     // Print it
  62.     Serial.print("onTimer no. ");
  63.     Serial.print(isrCount);
  64.     Serial.print(" at ");
  65.     Serial.print(isrTime);
  66.     Serial.println(" ms");
  67.   }
  68.   // If button is pressed
  69.   if (digitalRead(BTN_STOP_ALARM) == LOW) {
  70.     // If timer is still running
  71.     if (timer) {
  72.       // Stop and free timer
  73.       timerEnd(timer);
  74.       timer = NULL;
  75.     }
  76.   }
  77. }
I'm lost, it's probably an option in my arduino IDE but i don't know which one could be responsible.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: esp32-H2 timer reboot forever

Postby lbernstone » Mon Feb 19, 2024 6:21 pm

Since you are using 3.0, you should use the example from 3.0. Setting the frequency to 80Hz should generate an error rather than a crash.
As Sprite_TM says, Serial.print is a bad idea in an ISR. Use ets_printf.
H2 is still experimental, and does have some issues with the clock timing. Open an issue on the repo if the unmodified example crashes.
If you don't need a high precision timer, Ticker is a much more forgiving method that doesn't use hardware interrupts.

Who is online

Users browsing this forum: ESP_Alvin, Google [Bot] and 91 guests