arduino / ArduinoModule-CMSIS-Atmel

Atmel Smart ARM devices CMSIS module for Arduino IDE
BSD 2-Clause "Simplified" License
23 stars 36 forks source link

CMSIS Error using WDT #11

Open trlafleur opened 6 years ago

trlafleur commented 6 years ago

This simple test of the PM->RCAUSE.bit.WDT bit cause an error in a CMSIS Macro... Other bits in RCAUSE work fine...

Arduino 1.85 SAMD21 1.6.19 CMSIS-Atmel 1.1.0

void setup() {

if (PM->RCAUSE.bit.WDT) {}

}

void loop() {

}

// error messages below...

///Users/lafleur/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os  -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10805 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Zero"' "-I/Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/" "-I/Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/" "-I/Users/lafleur/Library/Arduino15/packages/arduino/hardware/samd/1.6.19/cores/arduino" "-I/Users/lafleur/Library/Arduino15/packages/arduino/hardware/samd/1.6.19/variants/arduino_zero" "/var/folders/53/f8mlg0xn1xv3fsm58phqmtb40000gn/T/arduino_build_786181/sketch/WDT-Reset-Test.ino.cpp" -o "/var/folders/53/f8mlg0xn1xv3fsm58phqmtb40000gn/T/arduino_build_786181/sketch/WDT-Reset-Test.ino.cpp.o"
//In file included from /Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
//                 from /Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd.h:105,
//                 from /Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/sam.h:470,
//                 from /Users/lafleur/Library/Arduino15/packages/arduino/hardware/samd/1.6.19/cores/arduino/Arduino.h:48,
//                 from /var/folders/53/f8mlg0xn1xv3fsm58phqmtb40000gn/T/arduino_build_786181/sketch/WDT-Reset-Test.ino.cpp:1:
///Users/lafleur/Desktop/MySensor-Arduino-development/MCCI/WDT-Reset-Test/WDT-Reset-Test.ino: In function 'void setup()':
///Users/lafleur/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:520:27: error: expected unqualified-id before '(' token
// #define WDT               ((Wdt      *)0x40001000UL) /**< \brief (WDT) APB Base Address */
//                           ^
///Users/lafleur/Desktop/MySensor-Arduino-development/MCCI/WDT-Reset-Test/WDT-Reset-Test.ino:4:20: note: in expansion of macro 'WDT'
// if (PM->RCAUSE.bit.WDT) {}
//                    ^
//exit status 1
//Error compiling for board Arduino/Genuino Zero (Native USB Port).
facchinm commented 6 years ago

Hi @trlafleur , it looks like the D21 (and probably all Atmel/Microchip CortexM0 family) defines WDT as the watchdog register, thus shadowing the original WDT bitfield definition. Adding

#ifdef WDT
#undef WDT
#endif

at the top of the sketch makes the code compile as expected, however I agree that this is ugly. I'll contact Microchip for a clarification but I doubt they'll be willing to change the define since it could break user code/libraries.