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

digitalPinToInterrupt doesn't accept pin 48 #8560

Closed
1 task done
sparvanders opened this issue Aug 24, 2023 · 2 comments · Fixed by #8600 or #8726
Closed
1 task done

digitalPinToInterrupt doesn't accept pin 48 #8560

sparvanders opened this issue Aug 24, 2023 · 2 comments · Fixed by #8600 or #8726
Assignees
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Status: Solved Type: Bug 🐛 All bugs
Milestone

Comments

@sparvanders
Copy link

Board

bpi_leaf_s3, and other ESP32-S2 and ESP-S3 variants

Device Description

Not relevant

Hardware Configuration

A pushbutton on IO48.

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Any

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

5000000

Description

In many variants for ESP32S2 and ESP32S3, digitalPinToInterrupt is defined as:

#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
But pin 48 is also valid as interrupt source.
Without a fix, this crashes:

attachInterrupt(digitalPinToInterrupt(48), Callback, FALLING);

The line should read:
#define digitalPinToInterrupt(p) (((p)<=48)?(p):-1)

Furthermore, returning -1 doesn't play nice with attachInterrupt() that accepts an uint8_t. attachInterrupt lacks a bounds check for array access so this gives undefined behavior (for me, a crash).

Sketch

// Not a working sketch

void IRAM_ATTR Callback() {
}

void setup() {
  //This does not work:
  attachInterrupt(digitalPinToInterrupt(48), Callback, FALLING);
  //This works:
  attachInterrupt(48, Callback, FALLING);
}

Debug Message

Crash

Other Steps to Reproduce

No response

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@sparvanders sparvanders added the Status: Awaiting triage Issue is waiting for triage label Aug 24, 2023
@SuGlider SuGlider self-assigned this Aug 24, 2023
@SuGlider SuGlider added Type: Bug 🐛 All bugs Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Area: Peripherals API Relates to peripheral's APIs. and removed Status: Awaiting triage Issue is waiting for triage labels Aug 24, 2023
@SuGlider
Copy link
Collaborator

@sparvanders - Thanks for reporting this bug! It shall be fixed as you wrote.

@VojtechBartoska
Copy link
Contributor

For S3 SoCs, issue is solved in 2.0.12 release. I am closing this issue, for other boards this will be addressed in 3.X release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment