`error: value '64' out of range for constraint 'I'` in `avr/include/avr/wdt.h`
KOLANICH opened this issue · 5 comments
https://github.com/arduino/toolchain-avr/issues
When tryint to setup a CMake toolchain file to compile to avr target using clang-15 I got the following errors:
In file included from ./1.8.19/hardware/arduino/avr/cores/arduino/CDC.cpp:20:
./1.8.19/hardware/tools/avr/lib/gcc/avr/7.3.0/../../../../avr/include/avr/wdt.h:464:12: error: value '64' out of range for constraint 'I'
: "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(in wdt_disable)
In file included from ./1.8.19/hardware/arduino/avr/cores/arduino/CDC.cpp:20:
./1.8.19/hardware/tools/avr/lib/gcc/avr/7.3.0/../../../../avr/include/avr/wdt.h:507:23: error: value '64' out of range for constraint 'I'
: [WDTREG] "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(in wdt_disable)
I guess
& 0b111111is needed for runtime dispatch to calm down the compiler.- I also wonder if we somehow can utilize
if constexprfor the case of C++ to do dispatch in compile time.
Yer not trying to compiler that library on a modern/post2016 AVR are you? That won't work, they haven't updated the library.
Yer not trying to compiler that library on a modern/post2016 AVR are you?
The mcu I compile for is atmega2560.
That won't work, they haven't updated the library.
What do you mean? Should not clang link well to any standard library gcc links well?
If I understand right, the issue mentioned here can happen if clang has stricter checks than gcc has (and it is often tye case).
No library that uses _SFR_TO_IO_ADDR on a special function register that doesn't reside in the I/O spacve will ever work.
And yeah apparently that's the case on the 2560. It's 0x60. But 0x3F is the highest number allowed for the I constraint, which specifies the address of a locatrion within the I/O space. On the 2560, the WDT control registrer is not located within the I/O space, and the assembly that is being used to access it cannot work. On claqssic AVRs it's almost universal that they are, but not 100%, and on modern AVRs they never are.
Thanks for the info.
-
I guess I have mistaken,
arduino/toolchain-avris the wrong repo to fill an issue against. I probably should have created the issue in https://github.com/avrdudes/avr-libc -
The func has 2 branches: https://github.com/avrdudes/avr-libc/blob/960a359d854001399b8fb445a9ad0ce3ea80f4d0/include/avr/wdt.h#L450-L532 , one uses
outand another one usessts, I guess on this board the one usingstsis expected to be taken, but the content ofifis not a constexpr, and if I rewrite it toif constexprit errors because#define _SFR_MEM_ADDR(sfr) ((uint16_t) &(sfr))is not a constexpr.
The issue has already been filed by someoje else there: avrdudes/avr-libc#678