Teensy and sleep mode

Im trying to implement a simple sleep mode with interrupt wake up on my Teensy 3.2 but when i try to compile i get this error:

D:\_a\Arduino\hardware\teensy\avr\cores\teensy3/avr/sleep.h:36:23: error: expected primary-expression before 'asm'

 #define sleep_cpu()  (asm("wfi"))

                       ^

D:\_a\Arduino\hardware\teensy\avr\cores\teensy3/avr/sleep.h:38:23: note: in expansion of macro 'sleep_cpu'

 #define sleep_mode()  sleep_cpu()

                       ^

d:\Users\SIMETRI_DEV\Documents\Arduino\InterSleep\InterSleep.ino:26:3: note: in expansion of macro 'sleep_mode'

   sleep_mode();

   ^

D:\_a\Arduino\hardware\teensy\avr\cores\teensy3/avr/sleep.h:36:23: error: expected ')' before 'asm'

 #define sleep_cpu()  (asm("wfi"))

                       ^

D:\_a\Arduino\hardware\teensy\avr\cores\teensy3/avr/sleep.h:38:23: note: in expansion of macro 'sleep_cpu'

 #define sleep_mode()  sleep_cpu()

                       ^

d:\Users\SIMETRI_DEV\Documents\Arduino\InterSleep\InterSleep.ino:26:3: note: in expansion of macro 'sleep_mode'

   sleep_mode();

   ^

Error compiling for board Teensy 3.2 / 3.1.

And here is my code:

#include <avr/sleep.h>
#include <avr/interrupt.h>

#define SWITCH 14
#define LED    15
#define LED2   16

void func(void)
{
  digitalWrite(LED, HIGH);
  //sleep_disable();
}

void setup() {
  pinMode(SWITCH, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(LED2, OUTPUT);
  
  set_sleep_mode(SLEEP_MODE_IDLE);
  sleep_enable();
  attachInterrupt(SWITCH, func, LOW);
}

void loop() {
  sleep_mode();
  digitalWrite(LED, LOW);

  digitalWrite(LED2, HIGH);
  delay(1000);
  digitalWrite(LED2, LOW);
  delay(1000);
}

thunderbootyclap:
...my Teensy 3.2...

#include <avr/sleep.h>
#include <avr/interrupt.h>

Does the Teensy 3.2 have an AVR processor?

The AVR code won't work because the Teensy 3.2 is an ARM processor. You should ask this on the Teensy forum forum.pjrc.com

Pete

cores/teensy3/avr/sleep.h

/* Simple compatibility headers for AVR code used with ARM chips
 * Copyright (c) 2015 Paul Stoffregen <paul@pjrc.com>
...

One could reasonably expect that the code at least compiles.

However, the functionality might not be exactly the same as on AVR:

#define SLEEP_MODE_IDLE         0
#define SLEEP_MODE_ADC          0
#define SLEEP_MODE_PWR_DOWN     1
#define SLEEP_MODE_PWR_SAVE     1
#define SLEEP_MODE_STANDBY      1
#define SLEEP_MODE_EXT_STANDBY  1

#define set_sleep_mode(mode)    // TODO: actually set the mode...
#define sleep_enable()
#define sleep_disable()
...

This is what causes the error:

#define sleep_cpu()             (asm("wfi"))

It turns out that the compiler does not like the () around asm().

Indeed Paul has done a huge amount of work to make transition from AVR to ARM as painless as possible.
I had the vague memory that the sleep modes and how to enter them with ARM was a lot different than AVR and so it would be a good idea to ask on the PJRC forum about putting a T3.2 to sleep.
Although I have multiple Teensys of various flavours, I have only used sleep on the Teensy2 and Teensy2++, which is AVR, and not on the Teensy 3.x which are ARM.

I think there was another post recently in which someone ran afoul of a macro which surrounded its argument with parentheses. Has the compiler changed or was the code ported from something in which that is acceptable?

Pete

#define sleep_cpu()  do { asm("wfi") } while(0)

The other is actually valid C(++) syntax. For example...

  (Serial.begin(250000));

Apparently, "asm" side steps the parser.