Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Compile error with noInterrupts() and interrupts()

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    2

    Compile error with noInterrupts() and interrupts()

    Hi, I'm trying to get the watchdog timer working on my teensy 3.6. After doing a little digging around I stumbled upon this post:
    https://forum.pjrc.com/threads/57131...981#post211981
    I decided to copy-paste the code to give it a try but when I tried compiling it I got the following errors:

    Code:
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:34:0,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:39,
    
                     from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
    
                     from C:\Users\MNI~1\AppData\Local\Temp\arduino_build_294619\pch\Arduino.h:6:
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:5675:56: error: expected ')' before '::' token
    
     #define __disable_irq() __asm__ __volatile__ ("CPSID i":::"memory");
    
                                                            ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:158:24: note: in expansion of macro '__disable_irq'
    
     #define noInterrupts() __disable_irq()
    
                            ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:38:1: note: in expansion of macro 'noInterrupts'
    
     noInterrupts();
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected unqualified-id before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:39:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xA602;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected ')' before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:39:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xA602;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected ')' before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:39:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xA602;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected unqualified-id before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:40:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xB480;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected ')' before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:40:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xB480;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:2615:26: error: expected ')' before 'volatile'
    
     #define WDOG_REFRESH  (*(volatile uint16_t *)0x4005200C) // Watchdog Refresh register
    
                              ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:40:1: note: in expansion of macro 'WDOG_REFRESH'
    
     WDOG_REFRESH = 0xB480;
    
     ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/kinetis.h:5676:55: error: expected ')' before '::' token
    
     #define __enable_irq() __asm__ __volatile__ ("CPSIE i":::"memory");
    
                                                           ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:157:22: note: in expansion of macro '__enable_irq'
    
     #define interrupts() __enable_irq()
    
                          ^
    
    E:\Projects\Plane\Flight Software\Various tests\WatchdogTest\WatchdogTest\WatchdogTest.ino:41:1: note: in expansion of macro 'interrupts'
    
     interrupts();
    
     ^
    
    WatchdogTest: In function 'void startup_early_hook()':
    WatchdogTest:63: warning: unused variable 'toval' 
         uint16_t toval = 1000;
    
                  ^
    
    Error compiling for board Teensy 3.6.
    Most of these errors originate in the kinetis.h file. I tried googling around to see if something was wrong with the syntax in the kinetis file but found nothing.
    Can anyone give any help with solving this issue?
    For the curious, I'm using Arduino 1.8.12 and Teensyduino 1.52 on a Windows 10 computer.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,985
    It compiles here without any errors on Linux.

    Click image for larger version. 

Name:	sc.png 
Views:	74 
Size:	80.6 KB 
ID:	20422

    This really should work on Windows too. My best guess is your Teensyduino install might be corrupted. Maybe Windows Defender or some other anti-virus interfered with the installer writing some of the files?

    My Windows test laptop currently needs some work (not booting...) so I can't easily test this on Windows right now. Maybe Defragster or something else with Windows can confirm?

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    2
    I just compiled on a different windows computer and the code compiled fine, must be an issue with the install on my end then.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,139
    Just used this the other day to work - compiling for T_4.0 on Win 10 w/IDE 1.8.12 and TS 1.52:
    Code:
        __disable_irq();
        mtCountL = mtCount;
        mtCount = 0;
        mtCountLB = mtCountB;
        mtCountB = 0;
        __enable_irq();
    Just changed to this and it also compiles:
    Code:
        noInterrupts();
        mtCountL = mtCount;
        mtCount = 0;
        mtCountLB = mtCountB;
        mtCountB = 0;
        interrupts();
    Just recompiled for T_3.6 and the second also works.


    Separate Issue but it was for the 500KHZ interrupt thread - the T_3.6 is WAY FASTER than the T_4.0. Will look for that thread and post results there.

    The T_3.6 can do two of these and have loop() cycles counts to spare!:
    Code:
    T:\tCode\Interrupts\IntTimerSample\IntTimerSample.ino Jun  2 2020 11:11:52
    mt#=1334453 with LoopCount=1866817	mtB#=1334558
    mt#=1333134 with LoopCount=1864782	mtB#=1333232
    Timer _isr()'s - the T_4.0 cannot run this:
    Code:
      MyTimer.begin(mt_isr, 0.75);
      MyTimerB.begin(mt_isrB, 0.75);
    T_4.0 can this:
    Code:
      MyTimer.begin(mt_isr, 0.75);
      MyTimerB.begin(mt_isrB, 2);
    T_4 (and T_4.1) is running this today - but less overhead for loop()'s - it looked like it failed the other day but can run:
    Code:
    T:\tCode\Interrupts\IntTimerSample\IntTimerSample.ino Jun  2 2020 11:20:21
    mt#=1143975 with LoopCount=349182	mtB#=1144058
    mt#=1142836 with LoopCount=348687	mtB#=1142915

    with slower loop() cycle count:
    Code:
    T:\tCode\Interrupts\IntTimerSample\IntTimerSample.ino Jun  2 2020 11:07:36
    mt#=1334663 with LoopCount=1000782	mtB#=500498
    mt#=1333335 with LoopCount=999635	mtB#=500001
    With those same two times the T_3.6 gives:
    Code:
    T:\tCode\Interrupts\IntTimerSample\IntTimerSample.ino Jun  2 2020 11:15:09
    mt#=1334623 with LoopCount=2291905	mtB#=500496
    mt#=1333308 with LoopCount=2289473	mtB#=500000
    Last edited by defragster; 06-02-2020 at 06:27 PM.

  5. #5
    I realise I'm resurrecting an old post here, but just to say that I encountered the same error compiling for Teensy 3.6 with PlatformIO under Windows (using PlatformIO Teensy version 4.13.1).

    I was already using a task library in the project, so I made the watchdog kick function a task, using a lambda function:

    Code:
    /* Watchdog kick using lambda function */
    static Task wdt_kick_task(10, []()
    {
        noInterrupts();
        WDOG_REFRESH = 0xA602;
        WDOG_REFRESH = 0xB480;
        interrupts();
    });
    
    void loop()
    {
        /* <snip> application code */
        wdt_kick_task.run(millis()); // Kick the WDT every 10ms
    }
    
    void startup_early_hook() {
        WDOG_TOVALL = 200;
        WDOG_TOVALH = 0;
        WDOG_STCTRLH = (WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN); // Enable WDG
    }
    This resulted in the compile error described above.

    The problem turned out to be the lambda function. If I moved the kick code to a "normal" function, the code compiles successfully:

    Code:
    /* Watchdog kick using normal function */
    static void kick_wdt()
    {
        noInterrupts();
        WDOG_REFRESH = 0xA602;
        WDOG_REFRESH = 0xB480;
        interrupts();
    }
    
    static Task wdt_kick_task(10, wdt_kick);
    I'm not sure it's that's the issue the OP had, but putting it here in case anyone else has a similar issue.
    Last edited by James Fowkes; 10-11-2021 at 05:26 PM. Reason: Comment fix

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •