Otiboot in platformio

hi.
need help.
Nano on Atmega168, optiboot
The question arises, how to explain to the compiler that it has another 1 kilobyte of flash?

So although you have Optiboot on the ATMega168, you have the same amount of flash as in the “No bootloader” case?

with optiboot I have 15872 bytes of available flash memory
but when compiling, platformio thinks it is 14336 bytes
after compiling i see this.
RAM: [== ] 18.4% (used 188 bytes from 1024 bytes)
Flash: [= ] 10.5% (used 1512 bytes from 14336 bytes)

all my attempts to communicate this to him in some way were unsuccessful. Could you explain in more detail how this can be done?

What’s your exact platformio.ini?

Version: 1.78.2 (user setup)
Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
Date: 2023-05-10T14:39:26.248Z
Electron: 22.5.2
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045
Sandboxed: Yes

platformio.ini

[env:KeyFob_168]
platform = atmelavr
board = nanoatmega168
board_build.mcu = atmega168pb ; not effect
board_build.f_cpu = 16000000L ; not effect
framework = arduino
upload_port = COM9
upload_speed = 115200
monitor_speed = 115200

Well the display is purely cosmetical. The compiler doesn’t need to be told the change in available flash because it only receiving -mmcu=atmega168 and no linker script option, to it will use its default linkerscript where it thinks it has all flash available.

You can fix the display by adding

board_upload.maximum_size = 15872

in the platformio.ini.

Note that with this configuration, you are using the official ArduinoCore-AVR. However, there’s also MiniCore that supports this chip (with a different pin mapping!). In this config, the flash size is correct out of the box.

You can e.g. configure that with

[env:KeyFob_168]
platform = atmelavr
; or ATMega168 or ATMega168P depending on the chip
board = ATmega168PB
framework = arduino
upload_port = COM9
upload_speed = 115200
monitor_speed = 115200
; tell it we have a UART bootloader
; https://docs.platformio.org/en/latest/platforms/atmelavr.html#minicore-megacore-mightycore-majorcore-and-microcore
board_hardware.uart = uart0

this really works
board_upload.maximum_size = 15872
I tried
board_build.maximum_size = 15872
but it didn’t work.

Note that with this configuration, you are using the official ArduinoCore-AVR. However, there’s also MiniCore that supports this chip (with a different pin mapping!). In this config, the flash size is correct out of the box.

Yes, I saw that in .platformio\platforms\atmelavr\boards\ATmega168PB.json
the size I need is 15872 and I thought that by writing the line
board_build.mcu=atmega168pb
would solve my problem

I ask you to correct me again.
1.
record in platformio.ini
board = ATmega168PB
allows me to use MiniCore with the corresponding pin designations, according to the MiniCore documentation ?
2.
The option that there is an option No bootloader
hints that a programmer can be connected to platformio?
I would be happy if the JTAG mkII AVR did this from the IDE.

Which is because the maximum_size attribute is in the upload section, not in the build section, refer to the JSON file.

Yes, this configuration will use the MiniCore. Internally, this is controlled by the core value in the board’s JSON file.

PlatformIO allows you to arbitrarily change the upload command and use all upload methods that avrdude or other uploaders are capable of. Hence you can configure PlatformIO to use an ISP programmer to burn the firmware. Several examples of this are listed in the Atmel AVR documentation.

Got it. JTAG mkII is not supported.
Thanks for the help.

AVRDude should be well-capable of a JTAG mkII. Just because it’s not listed in the examples of the documentation doesn’t mean it’s not supported. The only thing that matters is whether or not avrdude supports it.

See Upload code to ATMEGA64 using JtagICE MKII on custom board - #2 by maxgerhardt

[env:KeyFob_168]
platform = atmelavr
board = ATmega168 ;MiniCore
board_build.mcu=ATmega168
board_build.f_cpu = 16000000L
framework = arduino
monitor_speed = 115200
upload_protocol = custom
;upload_port = usb
upload_flags =
    -C
    ${platformio.packages_dir}/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -c
    jtag2isp
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

but it doesn’t work.

RAM:   [==        ]  18.4% (used 188 bytes from 1024 bytes)
Flash: [=         ]   8.9% (used 1414 bytes from 15872 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\KeyFob_168\firmware.hex
avrdude done.  Thank you.
*** [upload] Error 1

No I don’t think that change is good, can you delete that line?

And then execute the project task Advanced → Verbose Upload?

Removed. but the result is the same. I don’t see him blinking the LEDs like he can’t see it.
I also tried to set it to usb port

upload_port = usb
upload_flags =
    -C
    ${platformio.packages_dir}/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -P
    $UPLOAD_PORT
    -c
    jtag2isp
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

but that doesn’t help either.

Is flashing successfull in the logs?

No.
I don’t see what’s going on.
Where can I see this log?

RAM:   [==        ]  18.4% (used 188 bytes from 1024 bytes)
Flash: [=         ]   8.9% (used 1418 bytes from 15872 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\KeyFob_168\firmware.hex

avrdude done.  Thank you.

*** [upload] Error 1
============================================= [FAILED] Took 8.52 seconds =============================================