ATmega8 Configuration File no '-mmcu=' problem

Hello everyone, hope you are doing great! So, I built some basic projects (like blink) on this platform using ATTINY85 and USBTiny as programmer on a Raspberry Pi 4. All is well. But when I used the same code for configuring a project to ATmega8, I get this warning:

Processing program_via_USBtinyISP (platform: atmelavr)
-----------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PACKAGES: 
 - toolchain-atmelavr 1.70300.191015 (7.3.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
Compiling .pio/build/program_via_USBtinyISP/src/main.o
avr-gcc: error: missing device or architecture after '-mmcu='
*** [.pio/build/program_via_USBtinyISP/src/main.o] Error 1
====================================================== [FAILED] Took 1.68 seconds ======================================================

Environment             Status    Duration
----------------------  --------  ------------
ATmega8                 SUCCESS   00:00:04.074
program_via_USBtinyISP  FAILED    00:00:01.680
================================================= 1 failed, 1 succeeded in 00:00:05.753 =================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

Here is the configuration:

[env:ATmega8]
platform = atmelavr
board = ATmega8

; change microcontroller
;board_build.mcu = atmega8

; change MCU frequency
board_build.f_cpu = 8000000L

board_fuses.lfuse = 0xE4
board_fuses.hfuse = 0xD9

upload_protocol = usbtiny

[env:program_via_USBtinyISP]
platform = atmelavr

upload_protocol = custom
upload_flags =
    -C
    ; use "tool-avrdude-megaavr" for the atmelmegaavr platform
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -c
    usbtiny
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

I have extensively search for the problem in the code and on the forums (examples and how to) but simply cant find whats the problem?

Thank you for your time and effort! Cheers!

Your [env:program_via_USBtinyISP] does not have any board or fuses information in them. It does not inherit the previous environment, it is its own separate thing. So what you really have is one environment where all of the stuff seems to be set up regarding board and frequencies and fuses and everything and then just one platform with 3 upload directives and a platform directive (and no board = .. directive, which is why compilation fails).

Only the environment env is inherited by all other environments, if you were looking for that feature.

The simplest way to have a ATMega8 + USBTiny platformio.ini would be

[env:ATmega8]
platform = atmelavr
board = ATmega8

; change microcontroller
;board_build.mcu = atmega8

; change MCU frequency
board_build.f_cpu = 8000000L

board_fuses.lfuse = 0xE4
board_fuses.hfuse = 0xD9

upload_protocol = custom
upload_flags =
    -C
    ; use "tool-avrdude-megaavr" for the atmelmegaavr platform
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -c
    usbtiny
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

Thank you so much @maxgerhardt !
I had trouble configuring fuses but i got the hang of it. Here is the configuration:

[env:ATmega8]
platform = atmelavr
board = ATmega8

board_build.f_cpu = 8000000L
upload_protocol  = custom
upload_speed = 115200
   
upload_flags  =
    -C
    ; use "tool-avrdude-megaavr" for the atmelmegaavr platform
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -c
    usbtiny
   -Uhfuse:w:0xd9:m ;set fuses manually
   -Uefuse:w:0xff:m
   -Ulfuse:w:0xe4:m
    
upload_command = avrdude $UPLOAD_FLAGS -e -u -U flash:w:$SOURCE:i
1 Like

And checking up fuses from terminal of the R Pi:

pi@raspberrypi:~ $ avrdude -p m8 -c usbtiny

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9307 (probably m8)

avrdude: safemode: Fuses OK (E:FF, H:D9, L:E4)

avrdude done. Thank you.

1 Like