Porting Atmel Studio code to the PlatformIO(native)

Hello.
I want to use Atmel Studio code on PlatformIO(as native and NOT arduino). This code compiles successfully on Atmel Studio and include asm code inside C code. When I port this code on PlatformIO, the compiler marks all register names r0…r#(inside asm) as errors “unknown register name ‘r0’”

As I understand, such error already has been on this ticket and later developers fixed the problem:

But now this error appeared on my way with PlatformIO (latest and updated).

You can see my details in new ticket:

Please help me deal with the problem…

1 Like

Does your project compile when using pio run (aka the “Build” button) or does the VSCode Intellisense just complain about a “problem”? If it’s a compile error, can you post the complete compile error?

Log "pio run -v"
C:\Users\Dima\Documents\PlatformIO\Projects\HumidityAttiny25>pio run -v
Processing attiny25 (platform: atmelavr; board: attiny25; board_build.f_cpu: 1000000L; upload_protocol: usbasp; upload_flags: -Pusb)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny25.html
PLATFORM: Atmel AVR 2.0.0 > Generic ATtiny25
HARDWARE: ATTINY25 1MHz, 128B RAM, 2KB Flash
PACKAGES:
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
avr-gcc -o .pio\build\attiny25\src\main.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=attiny25 -DF_CPU=1000000L -DPLATFORMIO=40301 -DARDUINO_AVR_ATTINYX5 -Iinclude -Isrc src\main.c
avr-gcc -o .pio\build\attiny25\src\softuart.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=attiny25 -DF_CPU=1000000L -DPLATFORMIO=40301 -DARDUINO_AVR_ATTINYX5 -Iinclude -Isrc src\softuart.c
In file included from src\softuart.c:50:0:
src\softuart.h:53:0: warning: "F_CPU" redefined
 #define F_CPU  8000000UL
 ^
<command-line>:0:0: note: this is the location of the previous definition
In file included from src\main.c:15:0:
src\softuart.h:53:0: warning: "F_CPU" redefined
 #define F_CPU  8000000UL
 ^
<command-line>:0:0: note: this is the location of the previous definition
src\main.c: In function 'main':
src\main.c:29:16: warning: pointer targets in passing argument 1 of 'softuart_send' differ in signedness [-Wpointer-sign]
  softuart_send("Hello.\n");
                ^
In file included from src\main.c:15:0:
src\softuart.h:70:6: note: expected 'const uint8_t * {aka const unsigned char *}' but argument is of type 'char *'
 void softuart_send(const uint8_t *s);
      ^
src\main.c:32:20: warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast [-Wint-conversion]
  eeprom_write_byte(0x127, 0xBB);
                    ^
In file included from src\main.c:13:0:
c:\users\dima\.platformio\packages\toolchain-atmelavr\avr\include\avr\eeprom.h:166:6: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'int'
 void eeprom_write_byte (uint8_t *__p, uint8_t __value);
      ^
avr-gcc -o .pio\build\attiny25\firmware.elf -Os -mmcu=attiny25 -Wl,--gc-sections -flto -fuse-linker-plugin .pio\build\attiny25\src\main.o .pio\build\attiny25\src\softuart.o -L.pio\build\attiny25 -Wl,--start-group -lm -Wl,--end-group
C:\Users\Dima\AppData\Local\Temp\cc2brKbE.s: Assembler messages:
C:\Users\Dima\AppData\Local\Temp\cc2brKbE.s:114: Error: register number above 15 required
lto-wrapper.exe: fatal error: avr-gcc returned 1 exit status
compilation terminated.
c:/users/dima/.platformio/packages/toolchain-atmelavr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\attiny25\firmware.elf] Error 1
======================================================================================== [FAILED] Took 3.07 seconds ========================================================================================

C:\Users\Dima\Documents\PlatformIO\Projects\HumidityAttiny25>

Also I have installed plugin for Sublime Text (Deviot) - and I have the same kind error.

Used this softuart library with asm code:

Links

tinnymodbus/softuart.c at master · cbalint13/tinnymodbus · GitHub
tinnymodbus/softuart.h at master · cbalint13/tinnymodbus · GitHub

On Atmel Studio it compiled properly…

So you put

in the platformio.ini but put an extra macro there to redefine to 8MHz? This line doesn’t appear in the original library at line 53.

I cannot reproduce this issue.

platformio.ini

[env:attiny25]
platform = atmelavr
board = attiny25
board_build.f_cpu = 1000000L
upload_protocol = usbasp
upload_flags = -Pusb

src\main.c

#include <softuart.h>

int main() {

    softuart_send((const uint8_t*)"Test");

    return 0;

}

and softuart.c, softuart.h from the links you posted, I get.

>pio run -v
Processing attiny25 (platform: atmelavr; board: attiny25; monitor_speed: 115200; board_build.f_cpu: 1000000L; upload_protocol: usbasp; upload_flags: -Pusb)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny25.html
PLATFORM: Atmel AVR 2.0.0 > Generic ATtiny25
HARDWARE: ATTINY25 1MHz, 128B RAM, 2KB Flash
PACKAGES:
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Framework incompatible library C:\Users\Maxi\.platformio\lib\MCCI LoRaWAN LMIC library_ID5774
Scanning dependencies...
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
No dependencies
Building in release mode
avr-gcc -o .pio\build\attiny25\src\main.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=attiny25 -DF_CPU=1000000L -DPLATFORMIO=40301 -DARDUINO_AVR_ATTINYX5 -Iinclude -Isrc src\main.c
avr-gcc -o .pio\build\attiny25\src\softuart.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=attiny25 -DF_CPU=1000000L -DPLATFORMIO=40301 -DARDUINO_AVR_ATTINYX5 -Iinclude -Isrc src\softuart.c
avr-gcc -o .pio\build\attiny25\firmware.elf -Os -mmcu=attiny25 -Wl,--gc-sections -flto -fuse-linker-plugin .pio\build\attiny25\src\main.o .pio\build\attiny25\src\softuart.o -L.pio\build\attiny25 -Wl,--start-group -lm -Wl,--end-group
avr-objcopy -O ihex -R .eeprom .pio\build\attiny25\firmware.elf .pio\build\attiny25\firmware.hex
MethodWrapper(["checkprogsize"], [".pio\build\attiny25\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.7% (used 6 bytes from 128 bytes)
Flash: [=         ]   7.1% (used 146 bytes from 2048 bytes)
.pio\build\attiny25\firmware.elf  :

section                    size      addr
.text                       140         0
.data                         6   8388704
.comment                     48         0
.note.gnu.avr.deviceinfo     60         0
.debug_info                1056         0
.debug_abbrev              1000         0
.debug_line                  26         0
.debug_str                  362         0
Total                      2698
============================= [SUCCESS] Took 1.26 seconds =============================

Can you upload your whole project so that it becomes reproducable?

Thanks for your answer.
I solved my problem, it turned out that the variable with the name “buf” is some kind of system element and has a different sence.
This resulted in a compilation error.
I renamed the variable “buf”=>“buff”, and now compilation is successful.
However, the syntax with highlighting “unknown register name ‘r0’” still showing and I think it led to the false path of my throwing.

This is still a valid VSCode Intellisense bug though it seems (AVR Assembler Errors (i.e. Arduino) · Issue #2377 · microsoft/vscode-cpptools · GitHub). The path to the compiler and the -mmcu argument is there, but is still somehow won’t pick it up.