Skip to content
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

noInterrupts() not implemented - can not turn off interrupts #7211

Closed
caternuson opened this issue Sep 2, 2022 · 2 comments · Fixed by #7226
Closed

noInterrupts() not implemented - can not turn off interrupts #7211

caternuson opened this issue Sep 2, 2022 · 2 comments · Fixed by #7226
Assignees
Labels
Status: To be implemented Selected for Development Type: Bug 🐛 All bugs

Comments

@caternuson
Copy link
Contributor

Board

ESP32-PICO-MINI-02

Device Description

Adafruit Feather ESP32 V2
https://www.adafruit.com/product/5400

Hardware Configuration

No additional hardware attached. However, to run the example sketch to demonstrate the issue, two digital pins need to be connected together somehow. This was done on a breadboard using a jumper wire.

Version

v2.0.4

IDE Name

Arduino IDE

Operating System

Ubuntu

Flash frequency

n/a

PSRAM enabled

yes

Upload speed

921600

Description

The Arduino methods for disabling/enabling interrupts are no implemented:
https://www.arduino.cc/reference/en/language/functions/interrupts/nointerrupts/
https://www.arduino.cc/reference/en/language/functions/interrupts/interrupts/

Interrupts are "always on".

Sketch

#define OUT_PIN 14
#define IN_PIN 32

int count = 0;

void counter() {
  count++;
}

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

  pinMode(OUT_PIN, OUTPUT);
  digitalWrite(OUT_PIN, LOW);
  pinMode(IN_PIN, INPUT);

  attachInterrupt(digitalPinToInterrupt(IN_PIN), counter, RISING);

  for (int i=0; i<50; i++) {
    digitalWrite(OUT_PIN, HIGH);
    digitalWrite(OUT_PIN, LOW);
  }

  noInterrupts();

  for (int i=0; i<50; i++) {
    digitalWrite(OUT_PIN, HIGH);
    digitalWrite(OUT_PIN, LOW);
  }

  Serial.print("count = "); Serial.println(count);
}

void loop() {
}

Debug Message

No debug messages. Sketch runs without issue. However, the expected output is 50, not 100.


count = 100


### Other Steps to Reproduce

This is the same issue reported in this older thread:
https://github.com/espressif/arduino-esp32/issues/832
that was closed claiming it's not a BSP issue.

### I have checked existing issues, online documentation and the Troubleshooting Guide

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@caternuson caternuson added the Status: Awaiting triage Issue is waiting for triage label Sep 2, 2022
@SuGlider SuGlider added Status: To be implemented Selected for Development Type: Bug 🐛 All bugs and removed Status: Awaiting triage Issue is waiting for triage labels Sep 3, 2022
@SuGlider SuGlider self-assigned this Sep 3, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Sep 3, 2022

@caternuson - thanks for reporting this issue.

I see there is some simple code for it, but it may not be working for all cases...
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Arduino.h#L84-L85

I'll test it further and try to find a fix for it.

@SuGlider
Copy link
Collaborator

SuGlider commented Sep 5, 2022

portDISABLE_INTERRUPTS(); and portENABLE_INTERRUPTS(); are the equivalent to noInterrupts() and interrupts()

ESP32 runs FreeRTOS, thus, the sketch must be VERY careful using noInterrups() ...
Disabling Interrupts will lead to potential problems for most Arduino sketches such as WDT panic.

The example of this issue results in WDT Panic with a Guru Mediation Error.

count = 50
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1).

This code does what you want:

#define OUT_PIN 14
#define IN_PIN 32

int count = 0;

void counter() {
  count++;
}

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

  pinMode(OUT_PIN, OUTPUT);
  digitalWrite(OUT_PIN, LOW);
  pinMode(IN_PIN, INPUT);

  attachInterrupt(digitalPinToInterrupt(IN_PIN), counter, RISING);

  for (int i=0; i<50; i++) {
    digitalWrite(OUT_PIN, HIGH);
    digitalWrite(OUT_PIN, LOW);
  }

  noInterrupts();
  portDISABLE_INTERRUPTS();

  for (int i=0; i<50; i++) {
    digitalWrite(OUT_PIN, HIGH);
    digitalWrite(OUT_PIN, LOW);
  }

  Serial.print("count = "); Serial.println(count);

  interrupts();
  portENABLE_INTERRUPTS();
}

void loop() {
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: To be implemented Selected for Development Type: Bug 🐛 All bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants