Compile Error: ‘digitalPinToInterrupt’ was not declared in this scope

keypunch
Sun Jun 18, 2017 9:10 pm
I tried to compile a sketch I coded for Arduino for targets Maple Mini, Maple (Rev 3), Maple (RET6), and Generic STM32F103C. All failed with:
In function 'void setup()':
error: 'digitalPinToInterrupt' was not declared in this scope
attachInterrupt ( digitalPinToInterrupt ( PulseTimeIrqPin ), InterruptPulseTime, PulseTrigger ) ;

vitor_boss
Tue Jun 20, 2017 4:00 am
Try this:
inline unsigned char digitalPinToInterrupt(unsigned char Interrupt_pin) { return Interrupt_pin; } //This isn't included in the stm32duino libs (yet)
#define portOutputRegister(port) (volatile byte *)( &(port->regs->ODR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value
#define portInputRegister(port) (volatile byte *)( &(port->regs->IDR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value

keypunch
Tue Jun 20, 2017 4:51 am
Vitor,

I tried the code you suggested:

inline unsigned char digitalPinToInterrupt(unsigned char Interrupt_pin) { return Interrupt_pin; } //This isn't included in the stm32duino libs (yet)
#define portOutputRegister(port) (volatile byte *)( &(port->regs->ODR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value
#define portInputRegister(port) (volatile byte *)( &(port->regs->IDR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value

#define LED 13 // Arduino

#define IrqPin 7
#define Trigger RISING

volatile unsigned long MSCurrent ;
volatile int Detect ;

// Interrupt Routine
void InterruptTime()
{
MSCurrent = millis() ;
digitalWrite ( LED, HIGH ) ;
Detect = 1 ;
}

void setup ()
{

Serial.begin ( 115200 );

delay ( 250 ) ;

pinMode ( LED, OUTPUT ) ;
pinMode ( IrqPin, INPUT ) ;
attachInterrupt ( digitalPinToInterrupt ( IrqPin ), InterruptTime, Trigger ) ;
}

void loop()
{

if ( Detect == 1 )
{
detachInterrupt ( digitalPinToInterrupt ( IrqPin ) ) ;
Detect = 0 ;
delay ( 150 ) ;
digitalWrite ( LED, LOW ) ;
delay ( 1500 ) ;
attachInterrupt ( digitalPinToInterrupt ( IrqPin ), InterruptTime, Trigger ) ;
}

}


RogerClark
Tue Jun 20, 2017 5:50 am
I’m not sure what this function (macro) is supposed to do

For the Arduino SAM (due) board its defined as

#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)


fpiSTM
Tue Jun 20, 2017 6:43 am
For STM32, there is one EXTi per GPIO pin number. So, 16 EXTI (PX0 to Px15).
Warning: set an EXTI on PA0 and PB0 will raised the same EXTI without way to know which GPIO port it is.

RogerClark
Tue Jun 20, 2017 7:08 am
[fpiSTM – Tue Jun 20, 2017 6:43 am] –
For STM32, there is one EXTi per GPIO pin number. So, 16 EXTI (PX0 to Px15).
Warning: set an EXTI on PA0 and PB0 will raised the same EXTI without way to know which GPIO port it is.

Thanks Frederic

So apart from the problem of an Interrupt on the same pin mask on different ports, then this function should just return the pin number.

I’ve checked the Arduino API https://www.arduino.cc/en/Reference/AttachInterrupt and attachInterrupt does not return a value :-(

So even if the core checked had an error because of PA0 and PB0 (or I presume PB1 and PC1 etc), then it could not be reported.

I just the core could just ASSERT if that happened, but I don’t know the “Arduino” way to handle this

Really we need an API change so that attachInterrupt can return bool, but Arduino are not usually happy to change their API


fpiSTM
Tue Jun 20, 2017 8:44 am
Right.
The question is “Is it required to handle this check?”
If a user attach interrupt twice on pin number ‘x’ with a different GPIO port PYx, I think irq handler x will be called only one time (tbc).

RogerClark
Tue Jun 20, 2017 9:54 am
Even it it checks, it can’t report the problem unless it Assets

So its probably not worth even checking


vitor_boss
Wed Jun 21, 2017 7:05 pm
[keypunch – Tue Jun 20, 2017 4:51 am] –
Vitor,

I tried the code you suggested:


Is this the expected result?

Regards,

John L. Males
Toronto, Ontario
Canada
20 June 2017 00:51 EDT
20 June 2017 00:54 EDT Added sketch code with suggested code additions.

Yes, it give those warnings but works here, did yours worked?


vitor_boss
Wed Jun 21, 2017 7:08 pm
[RogerClark – Tue Jun 20, 2017 7:08 am] –

[fpiSTM – Tue Jun 20, 2017 6:43 am] –
For STM32, there is one EXTi per GPIO pin number. So, 16 EXTI (PX0 to Px15).
Warning: set an EXTI on PA0 and PB0 will raised the same EXTI without way to know which GPIO port it is.


Really we need an API change so that attachInterrupt can return bool, but Arduino are not usually happy to change their API

Did you looked at STAR repo? IMAO they should have it working for their STM board


RogerClark
Mon Nov 13, 2017 1:02 am
Long overdue, but I’ve now added

#define digitalPinToInterrupt(pin) (pin)


Leave a Reply

Your email address will not be published. Required fields are marked *