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 :

Code: log.txt Select all

ESP-ROM:esp32h2-20221101
Build:Nov 1 2022
rst:0xc (SW_CPU),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x400031b6
SPIWP:0xee
mode:DIO, clock div:1
load:0x4083cfd0,len:0xb68
load:0x4083efd0,len:0x2718
load:0x408460e8,len:0x590
entry 0x4083cfd0
-------------------
Initialization (0%)
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.

Core 0 register dump:
MEPC : 0x42001972 RA : 0x42000042 SP : 0x408146d0 GP : 0x4080bd60
TP : 0x4080896c T0 : 0x400184be T1 : 0x77270000 T2 : 0x00000000
S0/FP : 0x00000000 S1 : 0x00000000 A0 : 0x00000000 A1 : 0x40800258
A2 : 0x00000000 A3 : 0xfffffffd A4 : 0x0020001f A5 : 0x4080025a
A6 : 0xfbdf0000 A7 : 0x000000fb S2 : 0x00000000 S3 : 0x00000000
S4 : 0x00000000 S5 : 0x00000000 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x4084e530 T4 : 0x00000000 T5 : 0x00000000 T6 : 0x00000000
MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000005 MTVAL : 0x0000000c
MHARTID : 0x00000000
Stack memory:
408146d0: 0x00000000 0x4080c5b0 0x00000000 0x4080025a 0x00000000 0x00000000 0x00000000 0x4200002e
408146f0: 0x00000000 0x00000000 0x00000000 0x42002544 0x00000000 0x00000000 0x00000000 0x00000000
40814710: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
40814730: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0x00038c35 0x4080dbe4 0x4080dbe4
40814750: 0x2a40c24e 0xb5f82a4e 0x623ddc8d 0x83d6d812 0x253eb1d0 0x893576c2 0xfb0d9ab7 0xc70964f5
40814770: 0x41077229 0xeb94c6be 0xfdaf2cdb 0xbde1ed95 0x331ab35c 0xb0cf0919 0xc913d8c6 0xf290ca77
40814790: 0x2617a9dc 0x3262cc32 0xa3c46155 0x83a5ce1c 0x469de453 0x30088b5e 0x6d8f8a66 0x9df5a2ac
408147b0: 0x9d9bcc26 0x5b6592e6 0x07196bd6 0xdd7103b6 0x9a9c0c32 0x824601e1 0x94372a63 0x1cc258e1
408147d0: 0x8c7129e4 0xebd88e2a 0xb53b37e7 0x8aa8aaf1 0xa1676ae8 0x4db5715d 0xedadbae1 0x29854fd0
408147f0: 0xc175e726 0x5ba84343 0x9c68fbfb 0x70424984 0xc927b543 0xa833ae79 0xba66579b 0x27e762e8
40814810: 0x1c37b1dd 0xa44c2aab 0xf826a6b8 0x48f88a3f 0xf9b4edf9 0xdd8352c4 0xbf4490b8 0x623b46d1
40814830: 0x2e225854 0x343f4a1e 0x66a52879 0x8a85b676 0x6c8f1f2e 0x13e4b6cd 0x9cd68807 0x1bb9b0bb
40814850: 0xb7eccdfe 0xd20fe7d3 0xec9e7bdf 0x7e74e56e 0x9eab1673 0xa0ce8c71 0x12eee1dc 0xcee38452
40814870: 0x3170e725 0x49de1828 0xa5bf2d24 0x87807879 0xad450068 0x864fc28a 0x64f84e35 0xdcdd15dd
40814890: 0xa4071a44 0x0aade563 0x1c489ea6 0x8a57b0ce 0x3be7b880 0x25b889c6 0xd8144dc8 0xd3044e8b
408148b0: 0x05e3898a 0x1e8d4557 0xc461af7a 0xa7c76255 0x4eed4efb 0x2e1c6ac7 0xf15ef47f 0x3b6fe5d5
408148d0: 0x06b5cad3 0x6e4520c7 0x24cf32bf 0x9f2de4b3 0x32095f44 0x321d8c48 0xb465a83f 0xfe3192bb
408148f0: 0x2eb17522 0x162a21ab 0x80f2fde9 0x29742d28 0x06d83094 0xaf9b84e0 0xdbf4c33e 0xf0eb92cd
40814910: 0x1031429d 0x4b8da38b 0x8cf109aa 0x6144fae0 0xce606e4f 0x9dcb69cc 0x6d1bfee4 0xbf1657a8
40814930: 0x186a1e67 0x11c388f1 0x16307a08 0x33cfc436 0x5600d049 0xdac44cf8 0x0b530643 0xfdec219c
40814950: 0x142c3b83 0xd5949d85 0xc4d5d7c8 0xeb241daa 0x4294eaa3 0x3a5fb0b1 0xc58ec621 0x43b43cb5
40814970: 0x07ff43be 0xd1389007 0xc04e760b 0x5f8f4b52 0x1e2098e8 0x285a0a99 0xe622dc10 0xc4b7671a
40814990: 0xb1e449d1 0x3450a7b2 0x1f539882 0x46d0e970 0x2af83dfc 0xb687f3a6 0xa3919615 0xf258827d
408149b0: 0xbbbbba08 0x00f51a91 0xd3d68d5a 0x2348b9aa 0x1e1c5ccb 0xd8b42c02 0xdf6a83b2 0x2fc022bd
408149d0: 0xe49923b9 0x2490b526 0xd634e8f0 0xd5f33809 0xf9ec43fd 0xdf12348f 0x874fd1c2 0x1332aa7c
408149f0: 0x1cb5d1c5 0xc44c9ca2 0x6187d5ff 0x3f3779b5 0x90f5b36a 0x87774caa 0xa0fb1507 0xbcb64bd1
40814a10: 0x53254eba 0x9ccba018 0x63bea8b2 0x9792971d 0x1bf2504f 0xd65e1921 0xd26eb63c 0x4cf378ce
40814a30: 0x31bf4733 0x52d174a5 0xae0ffa42 0x54491b1b 0x3ac201ca 0xaa65c8d0 0x6a667faf 0x66ba8f1a
40814a50: 0x672366f2 0x911f57ea 0xebbc3ff2 0x1c447ae9 0x0bde6484 0x770af7fb 0xb278a79f 0x1d23c290
40814a70: 0x41285dee 0x209ddb4e 0xa0d10b3d 0x2478d472 0x82e499f3 0xa9592098 0x0dfa111c 0x71ee1897
40814a90: 0x26553823 0x981cac89 0x32a0f6c7 0x6f188415 0x6e961415 0x7e13b72b 0x0f9e4ece 0xf7234ac6
40814ab0: 0xaed40f06 0xaa05efe5 0xcd1cfb5d 0x70c2ddaa 0xc1bf09bb 0x3e2e5321 0xfa8eeb62 0x8adce929



ELF file SHA256: d383a8f0b1ac7154

Rebooting...
Here is the full code :

Code: MyCode.cpp Select all

hw_timer_t * timer = NULL;

void IRAM_ATTR AddSecondTimer()
{
Serial.println("Tick");
}

void PauseChrono()
{
// Let's try to make this code work before
}

void SetupTimer()
{
timer = timerBegin(80);
// timerAttachInterrupt(timer, &AddSecondTimer);
// timerAlarm(timer, 1000000, true, 0);

Serial.println("Initialization (100%)");
Serial.println("---------------------");
}

void setup()
{
Serial.begin(115200);
Serial.println("-------------------");
Serial.println("Initialization (0%)");
SetupTimer();
}

void loop()
{
//empty
}
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.

Sprite
Espressif staff
Espressif staff
Posts: 10599
Joined: Thu Nov 26, 2015 4:08 am

Re: esp32-H2 timer reboot forever

Postby 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

Code: Untitled.txt Select all

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

Code: esp32-hal-timer.h.cpp Select all

/*
Arduino.h - Main include file for the Arduino SDK
Copyright (c) 2005-2013 Arduino Team. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include "soc/soc_caps.h"
#if SOC_GPTIMER_SUPPORTED

#include "esp32-hal.h"
#include "driver/gptimer_types.h"

#ifdef __cplusplus
extern "C" {
#endif

struct timer_struct_t;
typedef struct timer_struct_t hw_timer_t;

hw_timer_t * timerBegin(uint32_t frequency);
void timerEnd(hw_timer_t * timer);

void timerStart(hw_timer_t * timer);
void timerStop(hw_timer_t * timer);
void timerRestart(hw_timer_t * timer);
void timerWrite(hw_timer_t * timer, uint64_t val);

uint64_t timerRead(hw_timer_t * timer);
uint64_t timerReadMicros(hw_timer_t * timer);
uint64_t timerReadMilis(hw_timer_t * timer);
double timerReadSeconds(hw_timer_t * timer);

uint32_t timerGetFrequency(hw_timer_t * timer);

void timerAttachInterrupt(hw_timer_t * timer, void (*userFunc)(void));
void timerAttachInterruptArg(hw_timer_t * timer, void (*userFunc)(void*), void * arg);
void timerDetachInterrupt(hw_timer_t * timer);

void timerAlarm(hw_timer_t * timer, uint64_t alarm_value, bool autoreload, uint64_t reload_count);

#ifdef __cplusplus
}
#endif

#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.

Code: Untitled.cpp Select all

/*
Repeat timer example

This example shows how to use hardware timer in ESP32. The timer calls onTimer
function every second. The timer can be stopped with button attached to PIN 0
(IO0).

This example code is in the public domain.
*/

// Stop button is attached to PIN 0 (IO0)
#define BTN_STOP_ALARM 0

hw_timer_t * timer = NULL;
volatile SemaphoreHandle_t timerSemaphore;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

volatile uint32_t isrCounter = 0;
volatile uint32_t lastIsrAt = 0;

void ARDUINO_ISR_ATTR onTimer(){
// Increment the counter and set the time of ISR
portENTER_CRITICAL_ISR(&timerMux);
isrCounter = isrCounter + 1;
lastIsrAt = millis();
portEXIT_CRITICAL_ISR(&timerMux);
// Give a semaphore that we can check in the loop
xSemaphoreGiveFromISR(timerSemaphore, NULL);
// It is safe to use digitalRead/Write here if you want to toggle an output
}

void setup() {
Serial.begin(115200);

// Set BTN_STOP_ALARM to input mode
pinMode(BTN_STOP_ALARM, INPUT);

// Create semaphore to inform us when the timer has fired
timerSemaphore = xSemaphoreCreateBinary();

// Set timer frequency to 1Mhz
timer = timerBegin(1000000);

// Attach onTimer function to our timer.
timerAttachInterrupt(timer, &onTimer);

// Set alarm to call onTimer function every second (value in microseconds).
// Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
timerAlarm(timer, 1000000, true, 0);
}

void loop() {
// If Timer has fired
if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE){
uint32_t isrCount = 0, isrTime = 0;
// Read the interrupt count and time
portENTER_CRITICAL(&timerMux);
isrCount = isrCounter;
isrTime = lastIsrAt;
portEXIT_CRITICAL(&timerMux);
// Print it
Serial.print("onTimer no. ");
Serial.print(isrCount);
Serial.print(" at ");
Serial.print(isrTime);
Serial.println(" ms");
}
// If button is pressed
if (digitalRead(BTN_STOP_ALARM) == LOW) {
// If timer is still running
if (timer) {
// Stop and free timer
timerEnd(timer);
timer = NULL;
}
}
}
I'm lost, it's probably an option in my arduino IDE but i don't know which one could be responsible.

lbernstone
Posts: 1131
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: Barkrowler, ChatGPT-User and 3 guests