Compile Error: 'digitalPinToInterrupt' was not declared in this scope

keypunch
Posts: 67
Joined: Tue Aug 02, 2016 2:26 am

Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by 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:

Code: Select all

In function 'void setup()':
error: 'digitalPinToInterrupt' was not declared in this scope
       attachInterrupt ( digitalPinToInterrupt ( PulseTimeIrqPin ), InterruptPulseTime, PulseTrigger ) ;
Using:

1) Arduino Linux64 V1.8.3
2) Arduino_STM32-master.zip "Latest commit aef93f7 5 days ago" as at 18 June 2017 00:50 EDT.
3) Distilled version of code that causes the "Error: 'digitalPinToInterrupt' was not declared in this scope":

Code: Select all

#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 ) ;
         }

     }
 
Same sketch and distilled version of sketch compiles fine for Arduino Uno, Zero, M0, and Due.

I can compile the Blink sketch for any Arduino board, Maple Mini, Maple (RET6), Maple (Rev 3), and any of the Generic STM32F103 boards.

Regards,

John L. Males
Toronto, Ontario
Canada
18 June 2017 17:10 EDT

vitor_boss
Posts: 61
Joined: Wed Apr 19, 2017 9:50 am

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by vitor_boss » Tue Jun 20, 2017 4:00 am

Try this:

Code: Select all

  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
Posts: 67
Joined: Tue Aug 02, 2016 2:26 am

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by keypunch » Tue Jun 20, 2017 4:51 am

Vitor,

I tried the code you suggested:

Code: Select all

  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 ) ;
         }

     }
with the following results:

Code: Select all

AttachInterruptError-STM32duino/AttachInterruptError-STM32duino.ino:2:0: warning: "portOutputRegister" redefined [enabled by default]
   #define portOutputRegister(port) (volatile byte *)( &(port->regs->ODR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value
 ^
In file included from arduino-1.8.3/hardware/Arduino_STM32/STM32F1/cores/maple/Arduino.h:42:0,
                 from sketch/AttachInterruptError-STM32duino.ino.cpp:1:
arduino-1.8.3/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:6:0: note: this is the location of the previous definition
 #define portOutputRegister(port)   ( &(port->regs->ODR) )
 ^
AttachInterruptError-STM32duino/AttachInterruptError-STM32duino.ino:3:0: warning: "portInputRegister" redefined [enabled by default]
   #define portInputRegister(port) (volatile byte *)( &(port->regs->IDR) ) //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value
 ^
In file included from arduino-1.8.3/hardware/Arduino_STM32/STM32F1/cores/maple/Arduino.h:42:0,
                 from sketch/AttachInterruptError-STM32duino.ino.cpp:1:
arduino-1.8.3/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:7:0: note: this is the location of the previous definition
 #define portInputRegister(port)    ( &(port->regs->IDR) )
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.

User avatar
RogerClark
Posts: 7443
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by 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

Code: Select all

#define digitalPinToInterrupt(p)  ((p) < NUM_DIGITAL_PINS ? (p) : -1)
For AVR boards its defined for be different things depending on which board it is

https://github.com/arduino/Arduino/sear ... rupt&type=

For example

Code: Select all

#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
For SAM (ARM) boards, all it does is return the same number that its passed, unless the number is higher than the total number of pins.

I don't know if the STM32 has any limitation on which pins can have an interrupt assigned to them, but I suspect that our macro for this should be the same as the Arduino SAM (due) version

fpiSTM
Posts: 247
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by 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.

User avatar
RogerClark
Posts: 7443
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by RogerClark » Tue Jun 20, 2017 7:08 am

fpiSTM wrote:
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
Posts: 247
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by 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).

User avatar
RogerClark
Posts: 7443
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by 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
Posts: 61
Joined: Wed Apr 19, 2017 9:50 am

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by vitor_boss » Wed Jun 21, 2017 7:05 pm

keypunch wrote:
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
Posts: 61
Joined: Wed Apr 19, 2017 9:50 am

Re: Compile Error: 'digitalPinToInterrupt' was not declared in this scope

Post by vitor_boss » Wed Jun 21, 2017 7:08 pm

RogerClark wrote:
Tue Jun 20, 2017 7:08 am
fpiSTM wrote:
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

Post Reply