Closed sstaub closed 3 years ago
I would love to see this!
@valeros what do you need me to do in order make this happen? the current MegaCoreX release is ready to be used with PlatformIO. I can provide the necessary manifest files if you want.
However, there are a few things that need to be addressed.
If we're going to do this, I suggest we start by addressing these issues. When everything seems to work as it should, I could start working on a script that would calculate fuses based on values from platformio.ini. I can also make a script that will load the correct bootloader too, similar to the script platform-atmelavr
has.
When this is finished, adding support for the megaavr ATtinys through megaTinyCore requested in https://github.com/platformio/platform-atmelavr/issues/83 would be simple.
These are the Avrdude programmers that need to be added:
@MCUdude @ivankravets Is there any update? I really want to use platformio for a atmega4808 but because of no support i am trying other ide's that talk with arduino directly...
It is annoying, I'm waiting for nearly a year for the support, also DxCore is missing, bootloader support..... I'm using the Arduino Pro IDE for that purpose, not the best but better than nothing.
Sorry for the delay, we have just prioritized this issue and will add support soon.
/cc @valeros
Thanks! Would be so great to see support soon. :)
I'm ready to continue working on the MegaCoreX implementation whenever @ivankravets or @valeros is!
@MCUdude would be cool if you three could come to an arrangement.
Question aside: Is there actually an official roadmap?
Hi guys, sorry for the delay, let's try to sort this out. According to @MCUdude hints above I prepared:
GCC 7.3.0
with the patches from Atmel ATmega Series Device Support (1.5.362)
avrdude
with new programmers and targets in avrdude.conf
MegaCoreX
v1.0.5CI successfully built the examples, so we just need to agree on supported upload methods and flags.
Awesome! I'm busy this weekend, but I'll get back to you on Monday. I do have a plan 😊
Will it be possible to change the oscillator to external, set the bod, etc.? 👁️
The first step would be to get it up and running. The next step would be to create two scripts. One to calculate the fuses, and one to load the correct bootloader. So @Gurkengewuerz, that is the plan. Similar functionality as with Minicore and MightyCore.
CI successfully built the examples, so we just need to agree on supported upload methods and flags.
@valeros the upload flags used at the moment can be found in the MegaCoreX platform.txt file. When it comes to the upload method, it's possible to upload using a dedicated programmer, or through a bootloader - Optiboot. This means the entire upload procedure will be very similar to what's already done with Mini/Mega/Major/MightyCore.
We should also discuss a fuses/bootloader script as well. As a start, I will try to implement ATmega808/1608/3208/4808 and ATmega809/1609/3209/4809, but there are no reason why the scripts can't support the entire tiny0, tiny1, and AVR DA/DB series later.
Hi @MCUdude I've pushed an initial implementation of fuses and bootloader programming for Arduino boards. Unfortunately I don't have any atmega4809-based board at hand, so it would be great if you could test new changes. But there is one thing that's bothering me in the current implementation. In Arduino core they program application, bootloader and set fuses in a single avrdude
command. Can we safely split that single command into three independent phases?
@valeros I'll test!
But there is one thing that bothering me, in the current implementation. In Arduino core they program application, bootloader and set fuses in a single avrdude command. Can we safely split that single command into three independent phases?
Flashing, bootloadering and fuses can safely be split into three separate tasks. The only thing you have to be aware of is that the bootloader is located at the beginning of the flash memory, and not the end like on classic AVRs. This means that programs compiled to run on chips that are using a bootloader need a 512 byte (0x200) offset (configured the BOOTEND fuse). When no bootloader is in use, the program starts at address 0x0000.
https://github.com/MCUdude/MegaCoreX/blob/master/megaavr/boards.txt#L176
Here's a blink hex file where a bootloader is already installed. Note the 0x200 offset:
:100200000C9448010C945A010C945A010C945A0114
:100210000C945A010C945A010C945A010C945A01F2
:100220000C945A010C945A010C945A010C945A01E2
:100230000C945A010C945A010C945A010C945A01D2
:100240000C945A010C945A010C945A010C945A01C2
:100250000C945A010C945A010C945A010C945A01B2
:100260000C945A010C94D1010C945A010C945A012B
:100270000C945A010C945A010C945A010C945A0192
:100280000C945A010C945A010C945A010C945A0182
:1002900011241FBECFEFCDBFDFE3DEBF28E2A0E019
:1002A000B8E201C01D92A430B207E1F70E94F90143
:1002B0000C948A020C9400019091010A9F7E909305
:1002C000010A9091600493FF0AC0811104C088E084
:1002D00080936604089588E08093650408959FB72D
:1002E000F894811107C080917304877F8093730411
:1002F0009FBF0895809173048860F8CF8FB7F894FA
:100300002091002830910128409102285091032823
:10031000E091AA0AF091AB0A9091A60A90FF08C05A
:100320002F5F3F4F4F4F5F4FE091AA0AF091AB0A0A
:100330008FBFA8EEB3E00E94700224E0F695E79527
:100340002A95E1F76E0F7F1F811D911D0895CF92B1
:10035000DF92EF92FF920E947E016B017C0120E40C
:10036000C20E22E4D21E2FE0E21EF11C80E4C81669
:1003700082E4D8068FE0E806F10438F40E947E019A
:10038000C616D706E806F906C8F30E947E016C156A
:100390007D058E059F05C8F3FF90EF90DF90CF900D
:1003A00008951F920F920FB60F9211248F939F936F
:1003B000AF93BF938091002890910128A0910228CB
:1003C000B09103280196A11DB11D80930028909340
:1003D0000128A0930228B093032881E08093A60A05
:1003E000BF91AF919F918F910F900FBE0F901F9073
:1003F000189588ED90E084BF90936100809102068B
:1004000086608093020680910006816080930006DA
:10041000809102068F7C8065809302061092E2052F
:1004200083E08093E40581E08093030A9EEF90933C
:10043000270A9093260A80E880932D0A80932B0A3E
:100440008093290A80932C0A80932A0A8093280A91
:100450002BE02093000A1092E50537E03093810AE3
:1004600090938C0A80938D0A25E02093800A309324
:10047000910A90939C0A80939D0A2093900A30934E
:10048000A10A9093AC0A8093AD0A2093A00A10921F
:10049000A10A8FE79EE38093AC0A9093AD0A809106
:1004A000A50A81608093A50A1092A00A8091A00AF3
:1004B00081608093A00A789488E080936104C0E012
:1004C000D0E081E00E945C010E94A70180E00E94D0
:1004D0005C010E94A7012097A1F30E940000F1CFC8
:1004E0000E947B02A59F900DB49F900DA49F800D4C
:1004F000911D11240895A29FB001B39FC001A39F35
:10050000700D811D1124911DB29F700D811D11244C
:08051000911D0895F894FFCF3E
:0400000300000200F7
:00000001FF
I will start working on dynamic fuse calculation once this PR is all figured out and working as it should. BTW how are the MegaCoreX bootloaders loaded? I tried to run pio run -t bootloader
, but I got an error saying *** Do not know how to make File target booloader (/Users/hans/Documents/PlatformIO/Projects/MegaCoreX_test/booloader). Stop.
I've updated the bootloader script, please pull the latest changes.
Flashing, bootloadering and fuses can safely be split into three separate tasks.
Thanks! Just in case, does the order of tasks matter?
This means that programs compiled to run on chips that are using a bootloader need a 512 byte (0x200) offset (configured the BOOTEND fuse)
Users can control this using build.text_section_start = 0x200
option.
Flashing, bootloadering and fuses can safely be split into three separate tasks.
Thanks! Just in case, does the order of tasks matter?
Well, the bootloader is optional, but the user program will only run correctly if the right fuses are set, just like on regular AVRs.
This means that programs compiled to run on chips that are using a bootloader need a 512 byte (0x200) offset (configured the BOOTEND fuse)
Users can control this using build.text_section_start = 0x200 option.
OK. This should be handled automatically though. It's very easy to detect. Add the 0x200 offset if board_hardware.uart != no_bootloader
.
OK. This should be handled automatically though. It's very easy to detect. Add the 0x200 offset if board_hardware.uart != no_bootloader.
There are also two other boards with the official Arduino core, but I will check what I can do.
There are also two other boards with the official Arduino core, but I will check what I can do.
The bootloader was developed after the Arduino Uno Wifi Rev2 and Arduino Nano Every was released. These two boards have an on-board UPDI programmer. The Uno Wifi Rev2 uses the 0x200 offset (no idea why, there are no bootloader, so the BOOTEND fuse should be 0x00), and the Nano every has 0x0000 offset.
It seems like the Arduino developers did plan to add a 512-byte bootloader to the Uno Wifi, but never actually did it. However, since the BOOTEND fuse is set to 0x02, the first 512 bytes are reserved regardless.
If you guys need some hardware to test i have an Arduino Nano Every and in the next days ATmega4808/808 will be ordered from mouser. 👀
I can test with Arduino Nano Every, Uno WIFI 2 and Nano Curiosity board.
@Gurkengewuerz It'd be great if someone could install the upstream verion of the platform and try to program the Arduino Nano Every
and Uno WIFI 2
boards with a simple blink example.
How to differ between the official Arduino core and the MegaCoreX in platformio.ini ?
I have a development board I can use to test ATmega808/1608/3208/4808. With and without bootloader.
Somehow an Arduino Nao Every works.
[env:nano_every]
platform = https://github.com/platformio/platform-atmelmegaavr.git#develop
board = nano_every
framework = arduino
let me hear if it helps you. If you want me to test something else, just mention me.
@Gurkengewuerz you're not building Nano Every with MegaCoreX, you're using the official core which lacks several hardware features that MegaCoreX offer.
How to differ between the official Arduino core and the MegaCoreX in platformio.ini ?
I'm not sure it's implemented yet, but MegaCoreX have several pinouts to choose from:
48pin-standard
, 40pin-standard
nano-every
and uno-wifi
.
Try using this configuration:
[env:ATmega4809]
platform = atmelmegaavr
framework = arduino
board = ATmega4809
board_build.variant = nano-every
@MCUdude oh good to know! So the following config should be fine?
[env:nano_every]
platform = https://github.com/platformio/platform-atmelmegaavr.git#develop
framework = arduino
board = ATmega4809
board_build.variant = nano-every
PlatformIO also updated to toolchain-atmelavr @ 2.70300.201015
and tool-avrdude-megaavr @ 2.60300.201015
now
MegaCoreX
should also be set as the core:
Nevermind, thought we're using nano_every
directly.
Using the config above the flash was successful!
@Gurkengewuerz ah, yes, the platform field has to be the github URL.
@valeros I think there is something weird going on with the build process. When I build a blank sketch in Arduino IDE, it compiles down to 476 bytes. However, with PlatformIO it compiles to 4340 bytes. Also, why does MegaCoreX have to be explicitly specified? Neither of my other cores has to.
@MCUdude just a side note: Maybe you want to edit you larger comments in this issue with a spoiler tag. Scrolling on my phone is a pain in the ass 🤣
### Titel
</details>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum do
</details>
@valeros @MCUdude oh true. can cornfirm that the compiled blink sketch in Arduino IDE is much smaller using the MegaCoreX. Could it be because of the UARTX.cpp
, wiring_*.cpp
etc. compiled with it in the PlatformIO implementation (see my build log)?
@valeros @MCUdude oh true. can cornfirm that the compiled blink sketch in Arduino IDE is much smaller using the MegaCoreX. Could it be because of the UARTX.cpp, wiring_*.cpp etc. compiled with it in the PlatformIO implementation (see my build log)?
I'm not sure what causes this. RAM usage is also way too high. I can confirm that this is also an issue when compiling for the "official" Nano Every and Uno Wifi Rev2.
Tried with UNO WIFI 2, can compile but upload fails: I'm on macOS
Processing ATmega4809 (platform: https://github.com/platformio/platform-atmelmegaavr.git#develop; framework: arduino; board: ATmega4809)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATmega4809.html
PLATFORM: Atmel megaAVR (1.1.1+sha.ebadbd9) > ATmega4809
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 48KB Flash
PACKAGES:
- framework-arduino-megaavr-megacorex 1.0.5
- tool-avrdude-megaavr 2.60300.201015 (6.3.0)
- toolchain-atmelavr 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio/build/ATmega4809/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 11.9% (used 731 bytes from 6144 bytes)
Flash: [== ] 15.4% (used 7576 bytes from 49152 bytes)
Configuring upload protocol...
AVAILABLE: jtag2updi
CURRENT: upload_protocol = jtag2updi
Looking for upload port...
Auto-detected: /dev/cu.usbmodem14302
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem14302
Waiting for the new upload port...
Uploading .pio/build/ATmega4809/firmware.hex
avrdude: jtagmkII_recv_frame(): timeout
avrdude: jtagmkII_getsync(): sign-on command: status -1
following ini:
[env:ATmega4809]
#platform = atmelmegaavr
platform = https://github.com/platformio/platform-atmelmegaavr.git#develop
framework = arduino
board = ATmega4809
board_build.variant = uno-wifi
build_flags = -Wl,-u,vfprintf -lprintf_flt -lm
Code:
#include "Arduino.h"
#define LED LED_BUILTIN
// #define LED PIN_PF5 // Curiosity Nano ATmega 4809 MegaCoreX
// #define LED PIN_PC6 // Curiosity Nano AVR128DA48 DxCore
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
// Serial3.begin(9600); // Curiosity Nano ATmega 4809 MegaCoreX
// Serial1.begin(9600); // Curiosity Nano AVR128DA48 DxCore
}
void loop() {
Serial.print("time milliseconds ");
Serial.println(millis());
// Serial3.printf("millis %d\n", millis()); // Curiosity Nano ATmega 4809 MegaCoreX
// Serial1.printf("Millis %d\n", millis()); // Curiosity Nano AVR128DA48 DxCore
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
Arduino Nano Every works, but UNO WIFI 2 not. How to upload to Nano Curiosity board which uses nEDBG?
Thanks, the footprint issue should be fixed in the dev branch. Please update to the latest revision.
@sstaub Does the uploading via jtag2updi
work in Arduino IDE with UNO WIFI 2
and the MegaCoreX
core? Could you please attach here the entire log from Arduino IDE?
The Nano every does use jtag2updi
. The Uno Wifi Rev2 uses xplainedmini_updi
, and curiosity nano uses curiosity_updi
.
@sstaub Probably you need to change the upload protocol when programming the Uno WiFi
board even if a variant from MegaCoreX is used.
Changed the upload protocol but failed also: (macOS 10.15.7) with Arduino IDE upload works
Update: same problem with Curiosity Nano
jtag2updi
is the default protocol and it requires upload port. If you want to use xplainedmini_updi
you need to disable the wait_for_upload_port
option.
[env:ATmega4809]
platform = https://github.com/platformio/platform-atmelmegaavr.git#develop
framework = arduino
board = ATmega4809
board_build.variant = uno-wifi
board_upload.require_upload_port = False
OK, this works for the UNO WIFI 2. Only the Curiosity board is missing.
OK, this works also for Curiosity nano. Thank you very much, hope we can do the same for the DxCore.
I made three new board definitions:
I made three new board definitions: curiosity_nano_4809 uno_wifi_x nano_every_x this allows to use Arduino and Microchip boards without extra definitions for MegaCoreX If ok, can you add it please? I attached the definitions within the boards.zip All variants are tested.
The whole idea with the MegaCoreX implementation is that it's supposed to be generic. Nano Every and Uno Wifi Rev2 are just pinout variants that are supported. it would be much better if we could figure out a way to get rid of the board_upload.require_upload_port
flag. AFAIK the only available UPDI programmer out there that require a serial power is jtag2updi. @valeros can't we just have some logic in the megaavr main.py that checks what programmer is currently being used, and tweak board_upload.require_upload_port
automatically?
For a concrete board there are more things to handle than board_upload.require_upload_port
in the .json board definition. e.g. for the curiosity board also the debugger capability should handled in future.
Added two other boards
both can compile but no tests of real boards I updated some URLs boards.zip
@MCUdude I updated the build script, so jtag2udpi
is now configured dynamically. If you need more time for preparing your PR with dynamic fuses, we can simply publish a new release with basic functionality.
@MCUdude I updated the build script, so jtag2udpi is now configured dynamically. If you need more time for preparing your PR with dynamic fuses, we can simply publish a new release with basic functionality.
Thanks! It will take me some time to get everything just the way I like it, so please release it as it is now, and prepare a new release when the dynamic fuses/bootloader functionality is in. But it would be great if you could just wait a little more before doing the release so I have time to test all chips and pinout variants for all targets. I should be done testing everything tonight.
For the dynamic fuses/bootloader stuff; I can just open a new issue if I need assistance and input from you, which I think I'll need somewhere on the way.
@MCUdude No problem, thanks a lot for testing!
A support of the MegaCoreX will helpful because there are other boards with MegaAvr0 chips, (Curiosity Nano, ATmega4809 Xplained Pro ...) which are not supported by Arduino directly. https://github.com/MCUdude/MegaCoreX Thank you for support of the original Arduino boards.