Custom board json

Hello,

I want to create a custom JSON file for my board in order to not copy each time my custom environnement which the following :

platformio.ini
[platformio]
;default_envs = KZV3_
boards_dir =..\..\board

[common_env_data]
platform = atmelavr
framework = arduino
lib_extra_dirs = 
    ..\..\lib ;shared librarie

[env:custom] ; env :program_via_AVRISP_mkII Kaizenboard V3.1
platform = ${common_env_data.platform}
board = ATmega328P
board_hardware.oscillator = external ; added
board_build.f_cpu = 4000000L ;added 4 MHz
framework = ${common_env_data.framework}
monitor_port = ${env:ATmega328P.upload_port}
build_flags = -DKZ_V3 -DDEBUG -DBoard_1_8V
upload_speed = 9600 ;recommended for 4 MHz
upload_port = COM3 
upload_protocol= custom
upload_flags = 
   -C
   $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf 
   -p 
   $BOARD_MCU
   -P 
   $UPLOAD_PORT
   -c
   arduino ; test  stk500v2 
   -b
   $UPLOAD_SPEED
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
lib_extra_dirs = ${common_env_data.lib_extra_dirs} ;shared librarie

I created a json file in a board folder. I am able to use the board declare in the json.

My issue is the following, I don’t know if it is possible to remove all the board and upload declaration.
And if it is possible how ?

I make research and it seems that the easiest implementation would be by using a python script. Is there another way to use custom avrdude upload protocol whitout writing it in ini with all the flag.
Maybe I have missed something in the documentation ?

Thanks for your help

Clement

Isn’t that the standard upload configuration? That is already set at

so I don’t think you need that upload_x flags, except for upload_speed = 9600 at all.

You can put some of these options in the board JSON but not all. E.g.,
build_flags can be done via extra_flags, upload_protocol via protocol, upload_speed via spede, f_cpu via f_cpu, but not board_hardware.oscillator = external and the others.

1 Like

Thanks I made some tests by putting with speed in the json but it didn’t worked.
It may be because arduino protocol overwrite my 9600 baud for upload speed.

I will try some of the hint you gave me.
I agree about the fact that my custom protocol is almost standard but i didn’t understand everything.My project used to be on arduino with a programmer via AVRISP mkII.
So I used the env [env:program_via_AVRISP_mkII] from documentation : Atmel AVR — PlatformIO latest documentation

Except that stk500v2 wasn’t working so I have used arduino instead.

No, that should not be the case. Execute the project task “Advanced → Verbose Upload” to see the exact avrdude invocation. It should contain the -b 9600 flag if the upload speed is set up correctly, either via the platformio.ini or a custom board definition (which you must also refer to with the board = <name of json file> directive).

1 Like

Result without specifying arduino programmer :
image

Even if my custom.json say :

“upload”: {
“maximum_ram_size”: 2048,
“maximum_size”: 32768,
“protocol”: “arduino”,

Complete json

{
“build”: {
“core”: “MiniCore”,
“extra_flags”: “-DARDUINO_AVR_ATmega328P -DKZ_V3 -DBoard_1_8V”,
“f_cpu”: “4000000L”,
“mcu”: “atmega328p”,
“variant”: “standard”
},
“bootloader”: {
“led_pin”: “B5”
},
“debug”: {
“simavr_target”: “atmega328p”,
“avr-stub”: {
“speed”: 115200
}
},
“frameworks”: [
“arduino”
],
“name”: “ATmega328P/PA”,
“upload”: {
“maximum_ram_size”: 2048,
“maximum_size”: 32768,
“protocol”: “arduino”,
“require_upload_port”: true,
“speed”: 9600
},
“url”: “https://www.microchip.com/wwwproducts/en/ATmega328P”,
“vendor”: “Microchip”
}

Maybe I can specificy in the json under upload section :
programmer : arduino,

That is really weird because according to the code

it should add -c arduino to the flags since $UPLOAD_PROTOCOL is arduino.

What is the current platformio.ini?

Do you mean the full ini ?

`platformio.ini`

[platformio]

;default_envs = KZV3_

boards_dir =..\..\board

[common_env_data]
platform = atmelavr
framework = arduino
lib_extra_dirs = 
    ..\..\lib ;shared librarie

[env:uno]
board = uno
platform = ${common_env_data.platform}
lib_extra_dirs =${common_env_data.lib_extra_dirs} ;shared librarie
;test_ignore = test_misc

>[env:KZV3_1] ; env :program_via_AVRISP_mkII Kaizenboard V3.1
platform = ${common_env_data.platform}
framework =${common_env_data.framework}
board = KZV3_1
board_hardware.oscillator = external ;
lib_extra_dirs =${common_env_data.lib_extra_dirs} ;shared librarie
upload_speed = 9600 ;recommended for 4 MHz
upload_port = COM3 
upload_flags = 
   -C
   $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf 
   -p 
   $BOARD_MCU
   -P 
   $UPLOAD_PORT
   -c
   arduino
   -b
   $UPLOAD_SPEED
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

>[env:KZV3_Origin] ; env :program_via_AVRISP_mkII Kaizenboard V3.1
platform = ${common_env_data.platform}
board = ATmega328P
board_hardware.oscillator = external ; added
board_build.f_cpu = 4000000L ;added 4 MHz
framework = ${common_env_data.framework}
monitor_port = ${env:ATmega328P.upload_port}
build_flags = -DKZ_V3 -DDEBUG -DBoard_1_8V
upload_speed = 9600 ;recommended for 4 MHz
upload_port = COM3 
upload_protocol= custom
upload_flags = 
   -C
   $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf 
   -p 
   $BOARD_MCU
   -P 
   $UPLOAD_PORT
   -c
   arduino ; test  stk500v2 
   -b
   $UPLOAD_SPEED
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
lib_extra_dirs = ${common_env_data.lib_extra_dirs} ;shared librarie

KZV3_origin is the regular atmega file and KZV3_1 is the json one.

You should try without those.

1 Like

It seems to work fine without them even if they are written in the documentation : Atmel AVR — PlatformIO latest documentation
Thanks a lot !

I will look more deeply into them to understand what they were supposed to do.

I look more deeply on how upload and bootloader work with atmega board.
Apparently by writing that the board is a atmega, it will automaticaly go for tool avrdude

Example from my upload test :

  • avrdude -v -p atmega328p -C C:\packages\tool-avrdude\avrdude.conf -c arduino -b 9600 -D -P COM3 -U flash:w:.pio\build\KZV3\firmware.hex:i