Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need improved documentation for Platform IO users #319

Open
SpenceKonde opened this issue Aug 9, 2022 · 11 comments
Open

Need improved documentation for Platform IO users #319

SpenceKonde opened this issue Aug 9, 2022 · 11 comments
Labels
Documentation Improvements or additions to documentation Help Needed Help required from outside experts Impacts megaTinyCore This bug is also present in megaTinyCore - DxCore and megaTinyCore are derived from same codebase.

Comments

@SpenceKonde
Copy link
Owner

We are getting tons of questions about this that turn out to be because of
pio and the fact that I can't control what flags PIO passes to the compiler. Surely far more people are impacted.

I think that a single document could be shared between megaTinyCore and DxCore - but needs to be well organized and have a long shelf life, because I don't know enough about PIO to update it.

I think this project would be best handled by first working through it in a Google Doc or something like that instead of a PR with a finished document, so multiple people who have relevant knowledge can contribute.

@SpenceKonde SpenceKonde added Documentation Improvements or additions to documentation Help Needed Help required from outside experts Impacts megaTinyCore This bug is also present in megaTinyCore - DxCore and megaTinyCore are derived from same codebase. labels Aug 9, 2022
@MCUdude
Copy link
Contributor

MCUdude commented Aug 19, 2022

If you have time, the absolute best option would be if you kept the PlatformIO implementation up to date. When you add new flags to your boards.txt, this has to be implemented in the PlatformIO build system as well. It's not difficult, but it has to be done.

... and the fact that I can't control what flags PIO passes to the compiler. Surely far more people are impacted.

Yes, you can! Flags that should always be passed to the compiler are added to the board manifest JSON files (AVR128DA28.json).

Other, user selectable flags that would normally be selected by the settings in the tools menu are added to the projects platformio.ini file using build_flags to add flags, and build_unflags to clear flags that have been set by default. For some reason, each flag has to be on its own line and indented. Here's an example from a commercial project where I've set and cleared a bunch of flags when using MightyCore:

build_flags =
  -std=gnu++11
  -Wall
  -Wextra
  -DSERIAL_TX_BUFFER_SIZE=128
  -DSERIAL_RX_BUFFER_SIZE=128
  -DFIRMWARE_REVISION=\"R5\"
  -lprintf_flt
  -DDEBUG_ENABLE

build_unflags =
  -flto
  -fpermissive
  -std=gnu++17

@SpenceKonde
Copy link
Owner Author

SpenceKonde commented Aug 19, 2022 via email

@brunob45
Copy link
Contributor

Hi,

7 months ago, I made a script to generate the json boards files for every AVR-Dx variant, based on Atmel's ATpacks.
It was pulled into platformio/platform-atmelmegaavr#35.

If there's a new script to generate the board.txt file, I could add the part to generate the PIO json files as well.
All I would need is the default parameters of the "Tools menu" for each variant.

@mikrocoder
Copy link
Contributor

mikrocoder commented Aug 20, 2022

Hello,

I summarize what I have done for Windows users. This is more complicated compared to an Arduino Nano Every and the MegaCoreX from MCUdude.

  1. PlatformIO installed
  2. installed current version Python 3.10.6. Set the hook for the path entry.

Until I found matou78's entry, I added the system environment variables for Python. I do not know if this was really necessary.
If necessary restart the computer afterwards so that this is taken over.
Systemumgebungsvariablen für User

Then the current pymcuprog was missing. pyupdi is obsolete and is no longer maintained. pymcuprog is now supported by Microchip.

For this In a windows console (CMD) enter the following.

> pip install pymcuprog
> pip install serial

Then pip wanted to update itself. Here I had to type the complete path exactly as it appears automatically.

Then I created a project for an AVR128DB64. The board with it runs already longer with the Arduino IDE and the DxCore and is programmed by USB and bootloader.

The following entries thanks matou78 written in the platformio.ini.
platformio/platform-atmelmegaavr#41
Clocks by default first with internal 16MHz.

[platformio]
default_envs = Upload_USART

[env]
platform = atmelmegaavr
framework = arduino
board = AVR128DB64

[env:Upload_USART]
build_flags = -DUSING_OPTIBOOT
upload_protocol = arduino
upload_speed = 115200

And the following blink test worked after that. Serial and pin for itself adapt, should be clear. 😉

#include <Arduino.h>

constexpr uint8_t pinLed {PIN_PB4};
constexpr uint16_t onTime {100};
constexpr uint16_t periode {2000};

void setup (void)
{
  Serial2.swap(1);
  Serial2.begin(9600);
  Serial2.println(F("Hallo ich bin dein AVR128DB64.\n"));
  pinMode(pinLed, OUTPUT);
}

void loop (void)
{
  digitalWrite(pinLed, HIGH);
  delay(onTime);
  digitalWrite(pinLed, LOW);
  delay(periode-onTime);
}

Done. 😀
Thanks to MCUdude and matou78.

@brunob45
Copy link
Contributor

brunob45 commented Aug 20, 2022

Key takeaways:

@SpenceKonde
Copy link
Owner Author

SpenceKonde commented Nov 19, 2022

It should be possible to make an upload_protocol=custom that will use the prog.py that we supply. It uses the same wiring as pymcuprog does to upload from a serial adapter - except it's about 15-20 times faster, or much more than that using an FTDI adapter with the default 16ms latency timer (though with that configuration, it's still grindingly slow - about 8 times longer than it should be. With pymcuprog and that setting, it's like 8ms per byte, 125b/s, With the latency timer reduced to the minimum 1ms, it should be 1.something k/s IIRC with stock pymcuprog. SerialUPDI does like 20k/s)

@SpenceKonde SpenceKonde added this to the 1.5.x - 1.5.0 bugfixes milestone Dec 21, 2022
@Orthosilicate
Copy link

Is there a way I can pull the latest release (1.5.6) into PlatformIO? It appears they are still on 1.4.10, which doesn't support the DD series parts.

@SpenceKonde
Copy link
Owner Author

Pretty sure there is.

Of course do I know what it is? absolutely not! I don't know the first thing about applied use of platform IO. I have it somewhere. I have no clue how to juse it to compile anything, never tried.....

@SpenceKonde
Copy link
Owner Author

As for why 1.4.10, I vaguely recal encouraging them to use that one because I (correctly) forsaw that 1.5.x would be a shitshow for months. I mean, it wasn't until last week when I became aware that I had broken almost all PWM on 1.5.0, and as well as DAC output from analogWrite.

@brunob45
Copy link
Contributor

brunob45 commented Mar 17, 2023

Hi @Orthosilicate
I have forked the official PlatformIO package with the updated DxCore version.
You can find an example here: https://github.com/brunob45/dev-AVR-Dx

I'm using the custom platform https://github.com/brunob45/platform-atmelavrdx#dev/dxcore
and the custom framework https://github.com/brunob45/framework-arduino-megaavr-dxcore#platformio

I see that another user opened an issue with Platformio platformio/platform-atmelmegaavr#53.
Usually, they respond quickly and update the official platform.

If this is working for you too, please consider requesting PR platformio/platform-atmelmegaavr#48 be merged in the main branch

@Orthosilicate
Copy link

Thanks @brunob45 !

I was able to successfully build an image for the AVR64DD28 using your fork. (After uncommenting the platform packages)
platform_packages = framework-arduino-megaavr-dxcore @ https://github.com/brunob45/framework-arduino-megaavr-dxcore#platformio

@SpenceKonde Thank you so much for supporting these parts, I very much appreciate not having to use Microchip Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation Help Needed Help required from outside experts Impacts megaTinyCore This bug is also present in megaTinyCore - DxCore and megaTinyCore are derived from same codebase.
Projects
None yet
Development

No branches or pull requests

5 participants