I would like to program my Attiny202 in my PlatformIO IDE. But how can I do that best and which tools can I use for that?
I made already some unsuccessful experiments since I have not enought knowlage.
For the uploading I would like to use the UPDI protocoll and I fund several videos about using an arduion (e.g. nano) to use it as programmer. After receiving the nano I noticed that the projects seems to be deprecated.
I used these videos with their additonal sources:
There’s a python UPDI programmer mentioned and some configuration for using it. I have no idea what hardware you might have to obtain, the list on the page mentions Atmel-ICE, Power Debugger, PICkit4, Snap, PKOB nano / nEDBG / Curiosity Nano debugger.
There are pages worth of documentation and guidance on how to use the megaTinyCore (which besides many others, supports the ATtiny202) in PlatformIO at this page.
And you’ve already found the page on how to construct a UPDI programmer using a standard usb-to-serial adapter as a UPDI programmer. @NormanDunbar’s link above then tells you how to tell PlatformIO to use that upload method. If you already have your Uno configured as some programming device and you know the avrdude command for flashing it, then you of course can also use that.
So, an example platformio.ini could e.g. be
[env]
platform = atmelmegaavr
framework = arduino
; Chip in use
board = ATtiny202
; Clock frequency in [Hz]
board_build.f_cpu = 16000000L
; Oscillator type (internal or external)
board_hardware.oscillator = internal
; Serial monitor baud rate
monitor_speed = 9600
[env:attiny202_upload_pymcuprog]
upload_speed = 115200
upload_flags =
--tool
uart
--device
attiny202
--uart
$UPLOAD_PORT
--clk
$UPLOAD_SPEED
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE
Me neither this is my first time but since there are many controllers out of stock I thought I just try them since they where in stock and they were not to expensive.
I am not really sure about the upload flags, since I rode this"in the case of external programmers, it’s easy to brick a board simply by specifying incorrect upload flags."
I don´t know the hardware either but the Atmel-ICE is defintly too pricey for me. I mostly used ESP32-varinants so far.
So I need a standart USB-TTL adapter for that? Using the nano is not an option anymore?
I actually was on that site but it isn´t clear to me, do I need to install that or is it already in PlatformIO when it checks for the dependencys.
Do I need to run the command and which values do I need for the fuses:
pio run -t fuses -e set_fuses
Or is that just an example and it will just extract that information from the platform.ini file?
To to be honest I am not sure if it works since it didn´t work so far for me and I never used the acrdude command before.
Does just [env] mean that this is the default profile?
And when
$UPLOAD_PORT
is used does that mean that PIO fills this information and I do not have to provide that?
It still is as I’ve said above. If you had success with the programmer being selected as “jtag2updi” in the Arduino IDE, then you can use it in PlatformIO too. In fact, that’s the default upload method:
So you can erase all upload_x directives in the platformio.ini to get that.
The device already has some fuses set by default. In the first step, try not to modify them, only if you notice that it seems to be using the wrong clock source, divider, or some other thing.
As the documentation says, [env] is the place where you can put options that will be inherited by all other environments. Global settings, so to say. Individual [env:xyz] environments can then be smaller, just adding on top of the options defined in [env].
Yes, you can see $UPLOAD_PORT as the environment variable that PlatformIO will try to autodetect based on your available serial ports / COM devices. It’s a variable substitution. You can manually override this value by placing a upload_port directive in your environment.
When I try to upload it, I always get this error. I tried some different variants but it always prints something like this:
In file included from /home/djpx/.platformio/packages/toolchain-atmelavr/avr/include/avr/io.h:99:0,
from src/JICE_io.cpp:9:
src/JICE_io.cpp: In function 'uint8_t JICE_io::put(char)':
src/JICE_io.cpp:55:25: error: 'HOST_USART' was not declared in this scope
loop_until_bit_is_set(HOST_USART.STATUS, USART_DREIF_bp);
^
src/JICE_io.cpp:55:25: note: suggested alternative: 'IO_START'
In file included from src/JICE_io.cpp:10:0:
src/JICE_io.cpp: In function 'uint8_t JICE_io::get()':
src/JICE_io.cpp:67:38: error: 'HOST_USART' was not declared in this scope
loop_until_bit_set_or_host_timeout(HOST_USART.STATUS, USART_RXCIF_bp); /* Wait until data exists. */
^
src/JICE_io.h:18:12: note: in definition of macro 'loop_until_bit_set_or_host_timeout'
while(!((register&(1<<bitpos))||(SYS::checkTimeouts() & WAIT_FOR_HOST))); \
^~~~~~~~
src/JICE_io.cpp:67:38: note: suggested alternative: 'IO_START'
loop_until_bit_set_or_host_timeout(HOST_USART.STATUS, USART_RXCIF_bp); /* Wait until data exists. */
^
src/JICE_io.h:18:12: note: in definition of macro 'loop_until_bit_set_or_host_timeout'
while(!((register&(1<<bitpos))||(SYS::checkTimeouts() & WAIT_FOR_HOST))); \
^~~~~~~~
src/JICE_io.cpp:69:10: error: 'HOST_USART' was not declared in this scope
return HOST_USART.RXDATAL;
^~~~~~~~~~
Compiling .pio/build/attiny202_upload_pymcuprog/src/dbg.cpp.o
src/JICE_io.cpp:69:10: note: suggested alternative: 'IO_START'
return HOST_USART.RXDATAL;
^~~~~~~~~~
IO_START
In file included from src/JTAG2.h:12:0,
from src/JICE_io.h:13,
from src/JICE_io.cpp:10:
src/JICE_io.cpp: In function 'void JICE_io::init()':
src/sys.h:47:27: error: 'VPORTHOST_TX_PORT' was not declared in this scope
# define PORT(x) CONCAT(VPORT,x).OUT
^
src/sys.h:39:21: note: in definition of macro 'CONCAT'
#define CONCAT(A,B) A##B // concatenate
^
src/JICE_io.cpp:80:3: note: in expansion of macro 'PORT'
PORT(HOST_TX_PORT) |= 1 << HOST_TX_PIN;
^~~~
src/JICE_io.cpp:80:30: error: 'HOST_TX_PIN' was not declared in this scope
PORT(HOST_TX_PORT) |= 1 << HOST_TX_PIN;
^~~~~~~~~~~
src/JICE_io.cpp:83:3: error: 'HOST_USART' was not declared in this scope
HOST_USART.BAUD = baud_reg_val(19200);
^~~~~~~~~~
src/JICE_io.cpp:83:3: note: suggested alternative: 'IO_START'
HOST_USART.BAUD = baud_reg_val(19200);
^~~~~~~~~~
IO_START
In file included from src/JICE_io.cpp:10:0:
src/JICE_io.cpp: In function 'void JICE_io::flush()':
src/JICE_io.cpp:106:38: error: 'HOST_USART' was not declared in this scope
loop_until_bit_set_or_host_timeout(HOST_USART.STATUS, USART_TXCIF_bp);
^
src/JICE_io.h:18:12: note: in definition of macro 'loop_until_bit_set_or_host_timeout'
while(!((register&(1<<bitpos))||(SYS::checkTimeouts() & WAIT_FOR_HOST))); \
^~~~~~~~
src/JICE_io.cpp:106:38: note: suggested alternative: 'IO_START'
loop_until_bit_set_or_host_timeout(HOST_USART.STATUS, USART_TXCIF_bp);
^
src/JICE_io.h:18:12: note: in definition of macro 'loop_until_bit_set_or_host_timeout'
while(!((register&(1<<bitpos))||(SYS::checkTimeouts() & WAIT_FOR_HOST))); \
^~~~~~~~
src/JICE_io.cpp: In function 'void JICE_io::set_baud(JTAG2::baud_rate)':
src/JICE_io.cpp:114:3: error: 'HOST_USART' was not declared in this scope
HOST_USART.BAUD = baud_tbl[rate - 1];
^~~~~~~~~~
src/JICE_io.cpp:114:3: note: suggested alternative: 'IO_START'
HOST_USART.BAUD = baud_tbl[rate - 1];
^~~~~~~~~~
IO_START
Compiling .pio/build/attiny202_upload_pymcuprog/src/jtag2updi.ino.cpp.o
*** [.pio/build/attiny202_upload_pymcuprog/src/JICE_io.cpp.o] Error 1
Compiling .pio/build/attiny202_upload_pymcuprog/src/main.cpp.o
================== [FAILED] Took 1.05 seconds ==================
Environment Status Duration
-------------------------- -------- ------------
attiny202_upload_pymcuprog FAILED 00:00:01.049
============= 1 failed, 0 succeeded in 00:00:01.049 =============
Do I need more variables (Host variables?) so that I can use that?
I tried it with the arduino-IDE to be sure that the wireing and the nano works. I was able to flash it succesful but currently I still have trouble with PlatformIO (my preferred development environment)
It seems there was still something cashed now it works. I also noticed that you often need to do an extra clear when you use different controllers. Thank you for your help.
Now I just can use: