Code uploads but does not execute on attiny1616 using jtag2updi on PlatformIO

Well, here’s my first post on the community, so hopefully I’m not being a muppet :wink:

I’ve looked at one post which seems to reflect something similar to my problem, but the issue highlighted is not present in my case.

I have a simple blink app which compiles, uploads and executes just fine using jtag2updi in the Arduino IDE, but fails to run on the same attiny1616 using the same programmer using PlatformIO.

Doing a verbose compile and load on both PlatformIO and the Arduino IDE shows that the code is being upload to address 0x0000 ('avr-g++ … --section-start=.text=0x0 ’ in PlatformIO vs. ‘avr-gcc … --section-start=.text=0x0’ in Arduino IDE), but there’s no activity from the tiny at all using PlatformIO.

I’d really appreciate some pointers on how I can investigate / resolve this, as I have a big program to port from an ATTiny85, programmed using PlatformIO, to the ATTiny1616, but what I thought would have been an easy switch has been anything but :frowning:

Are you trying the simplest possible blinky code?

Also, PlatformIO uses version 2.6.7 of the MegaTinyCore, although the latest is 2.6.10. So not all sketches may run equivalently.

Thanks for the response Max :slight_smile:

Here’s my code:

#include <Arduino.h>
#define PN PIN_A3

void setup() {
  pinMode(PN, OUTPUT);
  digitalWrite(PN, HIGH);
  //Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(PN, HIGH);
  //Serial.println("On");
  delay(1000);
  //Serial.println("Off");
  digitalWrite(PN, LOW);
  delay(1000);
}

So, pretty simple I think :wink:

The commented out Serial lines should output the text on PB2, the default serial transmit pin, but they don’t work either, wheras I can see the A3 pin wobbling up and down and the serial data being sent to PB2 when the code is compiled and uploaded from the Arduino IDE :-S

Given the simplicity of the code, I assume that the different MegaTinyCore version wouldn’t affect something as fundamental as this?

The jtag2updi package I am using was downloaded from ElTangas/jtag2updi and compliled in the Arduon IDE and uploaded to my Arduino Uno, and it works fine from both PlatformIO and the Arduino IDE.

The platformio.ini for the project on PlatformIO looks like this:

[env:ATtiny1616]
platform = atmelmegaavr
board = ATtiny1616
framework = arduino
board_build.f_cpu = 8000000L
upload_protocol = custom
upload_port = COM4
upload_speed = 19200
upload_flags = 
	-C
	C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf
	-p
	$BOARD_MCU
	-P
	$UPLOAD_PORT
	-b
	$UPLOAD_SPEED
	-c
	jtag2updi
	-u
	-e
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

Just to try to match things, I have also changed the board_build.f_cpu to 20000000, as it is in the Arduino IDE, but that doesn’t make any difference either. There are other settings in the Arduino IDE for the ATtiny1616, but I have no idea how to replicate these :-S

The avrdude.conf file is the one which is provided with jtag2updi, although it was generating some errors about possibly incorrect address lines for members of the ATtiny family, which I think I fixed properly :-S However a compile still yields warnings about other issues, although I have ignored these for time being as they don’t seem to relate to the 1616.

The issue in avrdude.conf seemed to be down to the definition for the ATtiny43U, which seemed to be inherited by other Atiny devices, yielding the following errors:

avrdude warning: ATmega329's flash writepage misses a necessary address bit a13 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:5828]
avrdude warning: ATmega649's flash writepage misses a necessary address bit a14 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:6054]
avrdude warning: AT90PWM2's eeprom writepage misses a necessary address bit a8 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:9244]
avrdude warning: ATtiny44's eeprom writepage misses a necessary address bit a7 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11102]
avrdude warning: ATtiny84's eeprom writepage misses a necessary address bit a8 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11286]
avrdude warning: a4 would normally be expected to be a5 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: a3 would normally be expected to be a4 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: a2 would normally be expected to be a3 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: a1 would normally be expected to be a2 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: a0 would normally be expected to be a1 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: too few opcode bits in instruction [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11571]
avrdude warning: ATtiny43u's eeprom read misses a necessary address bit a5 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11590]
avrdude warning: ATmega32U4's eeprom writepage misses a necessary address bit a2 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11776]
avrdude warning: AT90USB1286's eeprom writepage misses a necessary address bit a11 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:12171]
avrdude warning: ATtiny1634's flash writepage misses a necessary address bit a5 [C:\Users\xxxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:14927]

So I checked the file over and compared various entries, then fixed it by changing line 11571 from (11570 included for context):

                read            = "1  0  1  0   0  0  0  0    0 0 0 x  x x x x",
                                   "0  0 a4  a3 a2 a1 a0   o o o o  o o o o";

to:

                read            = "1  0  1  0   0  0  0  0    0 0 0 x  x x x x",
                                   "0  0 a5 a4  a3 a2 a1 a0   o o o o  o o o o";

Which got rid of all those errors about the ATtinys, so now what I get in terms of error messages is:

avrdude error: "safemode" feature no longer supported
avrdude warning: ATmega329's flash writepage misses a necessary address bit a13 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:5828]
avrdude warning: ATmega649's flash writepage misses a necessary address bit a14 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:6054]
avrdude warning: AT90PWM2's eeprom writepage misses a necessary address bit a8 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:9244]
avrdude warning: ATtiny44's eeprom writepage misses a necessary address bit a7 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11102]
avrdude warning: ATtiny84's eeprom writepage misses a necessary address bit a8 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11286]
avrdude warning: ATmega32U4's eeprom writepage misses a necessary address bit a2 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:11776]
avrdude warning: AT90USB1286's eeprom writepage misses a necessary address bit a11 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:12171]
avrdude warning: ATtiny1634's flash writepage misses a necessary address bit a5 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:14927]
avrdude warning: mcuid -1 for ATtiny402w is out of range [0..2039], use a free number >= 372 [C:\Users\xxxxx\OneDrive\PlatformIO\Projects\ATTiny1616 Test1\src\jtag2updi\avrdude.conf:15542]

When I compile I get the following output:

Processing ATtiny1616 (platform: atmelmegaavr; board: ATtiny1616; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATtiny1616.html
PLATFORM: Atmel megaAVR (1.9.0) > ATtiny1616
HARDWARE: ATTINY1616 16MHz, 2KB RAM, 16KB Flash
PACKAGES:
 - framework-arduino-megaavr-megatinycore @ 2.6.7
 - tool-avrdude @ 1.70100.0 (7.1.0)
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\ATtiny1616\src\main.cpp.o
Linking .pio\build\ATtiny1616\firmware.elf
Checking size .pio\build\ATtiny1616\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  42.5% (used 870 bytes from 2048 bytes)
Flash: [===       ]  30.6% (used 5013 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\ATtiny1616\firmware.hex

Then the avrdude errors detailed above, then the upload:

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9421 (probably t1616)
avrdude: erasing chip
avrdude: reading input file .pio\build\ATtiny1616\firmware.hex for flash
         with 5013 bytes in 1 section within [0, 0x1394]
         using 79 pages and 43 pad bytes
avrdude: writing 5013 bytes flash ...

Writing | ################################################## | 100% 4.59s

avrdude: 5013 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATtiny1616\firmware.hex

Reading | ################################################## | 100% 4.53s

avrdude: 5013 bytes of flash verified

avrdude done.  Thank you.

I’ve used a couple of .ELF file viewers to try to work out what might be different between the two compile outputs, but quickly get in over my head :frowning:

I’d appreciate any pointers :slight_smile:

You might be mixing the avrdude.conf for one avrdude version (e.g. 7.x) with with the avrdude binary of another version (6.x). The default upload protocol of the ATtiny1616 is already jtag2updi (source). I don’t see why you would need to modify the upload_flags or redirect it to another config file.

What is the output when you just use this platformio.ini?

[env:ATtiny1616]
platform = atmelmegaavr
board = ATtiny1616
framework = arduino
board_build.f_cpu = 8000000L
upload_speed = 19200

Thanks Max, I didn’t realise that :slight_smile:

I added a new entry into platformio.ini using the text you have provided, then did a compile and upload using that variant, but it still doesn’t make the ATtiny1616 to burst into life :frowning:

Here’s the output from the compile:

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder ATTiny1616 Test1: C:\Users\xxxxx\.platformio\penv\Scripts\platformio.exe run --target upload --environment ATtiny1616 

Processing ATtiny1616 (platform: atmelmegaavr; board: ATtiny1616; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATtiny1616.html
PLATFORM: Atmel megaAVR (1.9.0) > ATtiny1616
HARDWARE: ATTINY1616 8MHz, 2KB RAM, 16KB Flash
PACKAGES:
 - framework-arduino-megaavr-megatinycore @ 2.6.7
 - tool-avrdude @ 1.70100.0 (7.1.0)
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\ATtiny1616\src\jtag2updi\JICE_io.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\JTAG2.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\UPDI_hi_lvl.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\UPDI_lo_lvl.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\crc16.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\dbg.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\jtag2updi.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\sys.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\updi_io.cpp.o
Compiling .pio\build\ATtiny1616\src\jtag2updi\updi_io_soft.cpp.o
Compiling .pio\build\ATtiny1616\src\main.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\ExtraWiring.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\UART.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\UART0.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\UART1.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\WInterrupts_PA.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\WInterrupts_PB.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\WInterrupts_PC.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\abi.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\Common.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\IPAddress.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\PluggableUSB.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\Print.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\RingBuffer.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\Stream.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\api\String.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\hooks.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\main.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\new.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_extra.cpp.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\ATtiny1616\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\ATtiny1616\libFrameworkArduino.a
Linking .pio\build\ATtiny1616\firmware.elf
Checking size .pio\build\ATtiny1616\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  42.5% (used 870 bytes from 2048 bytes)
Flash: [===       ]  30.6% (used 5009 bytes from 16384 bytes)
Building .pio\build\ATtiny1616\firmware.hex
Configuring upload protocol...
AVAILABLE: jtag2updi
CURRENT: upload_protocol = jtag2updi
Looking for upload port...
Auto-detected: COM4
Uploading .pio\build\ATtiny1616\firmware.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9421 (probably t1616)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file .pio\build\ATtiny1616\firmware.hex for flash
         with 5009 bytes in 1 section within [0, 0x1390]
         using 79 pages and 47 pad bytes
avrdude: writing 5009 bytes flash ...

Writing | ################################################## | 100% 4.59s

avrdude: 5009 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATtiny1616\firmware.hex

Reading | ################################################## | 100% 4.53s

avrdude: 5009 bytes of flash verified

avrdude done.  Thank you.

==================================================================== [SUCCESS] Took 12.54 seconds ====================================================================

Environment    Status    Duration
-------------  --------  ------------
ATtiny1616     SUCCESS   00:00:12.541
===================================================================== 1 succeeded in 00:00:12.541 =====================================================================
 *  Terminal will be reused by tasks, press any key to close it. 

Just to make sure, this Blinky only code, also does not blink when using PlatformIO? Or does only the Serial not work?

Nope, the A3 pin does not toggle and PB2 shows no activity when compiled and uploaded using PlatformIO, but both do what they should when using the Arduino IDE :slight_smile:

Can you post a screenshot of the “Arduino IDE → Tools” menu so that we can see all the configuration options? Might also be something clock setup related.

Sure thing Max!

They have a (hidden) documentation at

https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/PlatformIO.md

Can you try the following platformoi.ini to match that configuration more closely:

[env:ATtiny1616]
platform = atmelmegaavr
board = ATtiny1616
framework = arduino
board_build.f_cpu = 20000000L
board_hardware.oscillator = internal
board_hardware.bod = 1.8v
board_hardware.eesave = yes
board_hardware.updipin = updi
upload_speed = 19200

Thanks Max!

Well, I seem to have solved this now. Whilst looking at the Explorer in PlatformIO, I noticed that I’d copied the jtag2updi folder into the project’s src directory (as I was trying to compile it in PlatformIO first, but then gave up and just used the Arduino IDE to do it). Removing that folder didn’t seem to affect the compile or the upload, but the code now works on the ATtiny1616. Hoorah!

Looking at the output from my last compile, I can see that various things in that directory were getting compiled, so maybe they were getting linked into the executable in some way which stopped it starting maybe?

1 Like