Page 1 of 1

IOPORT8 Compilation Error

Posted: Sat Feb 14, 2015 8:49 am
by major4x
Hi,

I am using the PAL driver on an Arduino AVR ATMEGA2560. For some reason when I use:

palClearPad(IOPORT2, 2);

everything compiles (and works) OK, but when I use:

palClearPad(IOPORT8, 6);

then I get the following compilation error:

avr-gcc -c -mmcu=atmega2560 -I. -x c++ -gdwarf-2 -DF_CPU=16000000UL -O2 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-exceptions -Wall -Wa,-adhlns=./main.lst -Iport -Ikernel/include -Ihal/include -Iplatform -Iboard -I/os/various -MMD -MP -MF .dep/main.o.d main.cpp -o main.o
main.cpp: In function 'int main()':
main.cpp:221:28: warning: asm operand 0 probably doesn't match constraints [enabled by default]
palClearPad(IOPORT8, 6);
^
main.cpp:221:28: error: impossible constraint in 'asm'

I was wondering if I am doing something wrong? I am trying to communicate with a digital output on PINH.

Thanks a lot for your help,

-- Alex

Re: IOPORT8 Compilation Error

Posted: Mon Feb 16, 2015 8:52 am
by major4x
I know what the problem is.

palClearPad() on AVR translates to assembly instruction "cbi" (clear a bit in an I/O register). Problem is that the operand of cbi is 8 bit and it does not support I/O ports in the upper address space. That's why I get the error. The proper way to use port H is:

palClearPort(IOPORT8, (1 << PH6));

Of course, this gets translated to several assembly instructions and the operation is not atomic anymore, so one should take care of synchronicity...