Hello all,
I usually assemble my programs with avra under linux.
Now I am trying to assemble a program that I wrote for an atmega328 with PlatformIO in VSC instead.
Some assembler directives do not work, for example the .equ I found I have to use #define (c precompiler)
Also the HIGH() and LOW() commands do not work and I have no idea what to use instead.
Is there a manual for the assembler used by the PlatformIO toolchain?
It does not look like the avr-asm of the avr toolchain.
.S files are assembled by PlatformIO with avr-gcc -x assembler-with-cpp, as can be observed when executing the project task Advanced → Verbose Build. So it’s a combination of the C pre-processor with avr-as (AVR GNU assembler). See avr-libc: avr-libc and assembler programs and Top (Using as).
Thank you maxgerhardt,
this is exactly the problem:
the “Using as” document gives the .equ directive, but it does not work on PlatformIO
the avr-libc document gives hi8() and lo8() (these were the high and low I was looking for) but they don’t seem work on PlatformIO
I try to compile this:
#define SPL 0x3d ;stack pointer low
#define SPH 0x3e ;stack pointer high
#define RAMEND 0x08ff
MAIN:
LDI R16,hi8(RAMEND) ;line 152
OUT SPH,R16
LDI R16,lo8(RAMEND)
OUT SPL,R16 ;stack pointer
But I get this error:
Processing ATmega328 (platform: atmelavr; board: ATmega328)
-------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega328.html
PLATFORM: Atmel AVR (3.4.0) > ATmega328
HARDWARE: ATMEGA328 16MHz, 2KB RAM, 32KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/ATmega328/src/main.o
src/main.S: Assembler messages:
src/main.S:152: Error: `)' required
src/main.S:153: Error: `,' required
src/main.S:153: Error: constant value required
src/main.S:153: Error: garbage at end of line
src/main.S:154: Error: `)' required
src/main.S:155: Error: `,' required
src/main.S:155: Error: constant value required
src/main.S:155: Error: garbage at end of line
src/main.S:187: Error: garbage at end of line
src/main.S:189: Error: garbage at end of line
src/main.S:230: Error: garbage at end of line
src/main.S:232: Error: garbage at end of line
*** [.pio/build/ATmega328/src/main.o] Error 1
============================ [FAILED] Took 0.74 seconds ============================
The terminal process "platformio 'run'" terminated with exit code: 1.
I found my error for .equ, I wrote
.equ SPL = 0x3d, like for avra, instead of .equ SPL,0x3d
Since I changed the #define with .equ I don’t get the error for LDI R16,hi8(RAMEND) anymore.
Now I get an error :
Building in release mode
Linking .pio/build/ATmega328/firmware.elf
/home/reto/.platformio/packages/toolchain-atmelavr/bin/…/lib/gcc/avr/7.3.0/…/…/…/…/avr/lib/avr5/crtatmega328.o:(.init9+0x0): undefined reference to `main’
collect2: error: ld returned 1 exit status
*** [.pio/build/ATmega328/firmware.elf] Error 1
Done, it looks like it will a lowercase main (I used MAIN).
Also the lo8 and hi8 have to be lowercase (they are probably defined for gcc, so case sensitive)
For the comments I can let ; and it works
What’s your platformio.ini? Based on the register names you are working with an ATmega8 (since those registers / bit names don’t e.g. exist on a atmega328). When I take your code, add the missing defines you didn’t show and correct the OUT instruction to an STS instruction since the I/O address is beyond 0x3F, it assembles normally.