Reputation: 11
I am learning AVR assembly on an Arduino Uno. I came across a compiler error while writing my program, and it seems that I am misunderstanding the proper implementation of macros. I am attempting to call a macro that consists of a list of other macros, and I keep getting a compilation error that's hinting toward the compiler not understanding or recognizing the macro. For example:
Within tftMain.s:
#include "avr/io.h"
#include "tftVars.s"
#define __SFR_OFFSET 0
.global tft_reset
tft_reset:
SET_WRITE_DIR
CTL_INIT
CS_IDLE
RD_IDLE
WR_IDLE
RESET_IDLE
WRITE_CMD
RET
Within tftVars.s:
.macro PIN_HIGH port, pin ; (port, pin)
SBI @0, @1
.endm
.macro CS_IDLE
PIN_HIGH CS_PORT CS_PIN
.endm
.macro SET_WRITE_DIR
IN R16, DDRB
OR R16, BMASK
IN R17, DDRD
OR R17, DMASK
OUT DDRB, R16
OUT DDRD, R17
.endm
.macro CTL_INIT
RD_OUTPUT
WR_OUTPUT
CD_OUTPUT
CS_OUTPUT
RESET_OUTPUT
.endm
...
So as seen within the code, I have a file tftMain.s
which includes the file tftVars.s
. The compiler error looks like this:
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:30: Error: bad expression
src\tftMain.s:30: Error: `,' required
src\tftMain.s:30: Error: constant value required
src\tftMain.s:30: Error: garbage at end of line
src\tftMain.s:31: Error: bad expression
...
This is on repeat for every line that calls a macro. I feel like my problem boils down to formatting- what am I doing wrong?
Upvotes: 0
Views: 314
Reputation: 1979
For what it's worth after almost 2 years since you posted the question. In case someone else hits this problem (as I did), this is the kind of syntax that worked for me on MacOS, Arduino IDE 2.3.2
:
#define CS_PORT PORTA
#define CS_PIN 0B11
.macro PIN_HIGH port, pin // (port, pin)
SBI &port, &pin
.endm
.macro CS_IDLE
PIN_HIGH CS_PORT, CS_PIN
.endm
Here's a snippet of the generated assembly code:
CS_IDLE
180: 13 9a sbi 0x02, 3 ; 2
Upvotes: 0
Reputation: 11
Within macro SET_WRITE_DIR
:
.macro SET_WRITE_DIR
IN R16, DDRB
OR R16, BMASK
IN R17, DDRD
OR R17, DMASK
OUT DDRB, R16
OUT DDRD, R17
.endm
Misuse of or
- should have used ori
. Beginners mistake!
Upvotes: 0