Skip to content

digitalPinToInterrupt doesn't accept pin 48 #8560

@sparvanders

Description

@sparvanders

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions