platformio / platform-atmelmegaavr

Atmel megaAVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelmegaavr
Apache License 2.0
29 stars 22 forks source link

Add tinyAVR-0/tinyAVR-1 targets to fuse calculation script #13

Closed MCUdude closed 4 years ago

MCUdude commented 4 years ago

Note that this script isn't properly tested yet, because #12 isn't merged yet, and I wasn't able to get it to work when manually adding these manifest files locally.

The only real difference between the fuses on megaAVR-0 and tinyAVR-0/1 is the SYSCFG0 fuse. megaAVR-0 has a dedicated UPDI pin that's always a UPDI pin, but the tinyAVR-0/1's have it multiplexed with the reset pin (that can also be a GPIO.

This means that when calculating fuses for megaAVR-0 you can reassign the reset pin with this line:

board_hardware.rstpin = reset
; or
board_hardware.rstpin = gpio

But for tinyAVR-0/1's it's going to be like this:

board_hardware.updipin = updi
; or
board_hardware.updipin = reset
; or
board_hardware.updipin = gpio

https://github.com/platformio/platform-atmelavr/issues/83 related.

MCUdude commented 4 years ago

@valeros thanks for adding initial support for megaTinyCore. I pulled the latest Github version and discovered a few issues I've fixed now. This script now works as expected.

valeros commented 4 years ago

Thanks a lot!

MCUdude commented 4 years ago

@valeros I'm not sure where to discuss this, but is there anything else needed before we have "proper" megaTinyCore support?

I did have a look in the platform.txt file, and there are a few macros passed from boards.txt that has to be included in the PlatformIO build as well. There is the -DCLOCK_SOURCE={build.clocksource} field that determines if we're using an internal or external oscillator, and there are -DMILLIS_USE_TIMER{build.millistimer} to determine what timer to use for millis.

IMO the clock source part could and should be dealt with by using build_hardware.oscillator = internal/external, and the millis timer is already defined in every ATtiny manifest file in this repo. It's only a matter of unflagging and "reflagging" a new millis timer.

There are also some version dependent macros found here.

valeros commented 4 years ago

I see you already specified default values -DMILLIS_USE_TIMER* and -DUARTBAUD5V in the extra_flags field. Is it a bad approach? Users can simply override values by using the build_unflags option. As an alternative, we can write down all possible values in documentation and add default ones only if user didn't specify anything. Something similar to the configuration system in ASR605x. But again, this will introduce additional maintenance efforts since someone will need to keep track of the changes in each new release to keep the docs relevant.

MCUdude commented 4 years ago

I see you already specified default values -DMILLIS_USE_TIMER* and -DUARTBAUD5V in the extra_flags field. Is it a bad approach?

These are default and should be fine for most users. For those who need different values, it's easy to unflag. I think this is the best approach.

The only thing that needs to be dealt with is the oscillator option. It should default to internal (CLOCKSOURCE=0), and it should be possible to override this using build_hardware.oscillator = external (CLOCKSOURCE=2) without having to deal with CLOCKSOURCE at all, just like with MegaCoreX

valeros commented 4 years ago

Thanks, added oscillator settings for megatinycore.

MCUdude commented 3 years ago

@valeros what is left to do before a new release is ready (apart from fixing #15)? I only have a few tinyAVR-0/1 boards, so I'm not able to test all targets. Maybe you could reach out to the various issues that request tinyAVR-0/1 support and ask if people could help out and test the latest development version?

valeros commented 3 years ago

If everything seems OK to you, then we can publish a new release once the issue 15 is resolved.

MCUdude commented 3 years ago

OK, I'd like to test some basic things first on a few boards I have. I'll report back here in a few days!

MCUdude commented 3 years ago

I can confirm that I'm able to calculate and write fuses and upload to ATtiny817 and ATtiny3217, which means that the foundation is OK, and probably works for the rest of the targets too.

Note that bootloader support is not present at the moment. It's a bit more tricky than on the megaAVR-0's, since the UPDI pin is multiplexed with the reset line. But my impression is that most users don't use a bootloader for the tinyAVR-0/1 series anyway.

What's missing now is only some documentation on the PlatformIO docs site, similar docs that we have for Mighty/Mega/Mini/Major/MicroCore.