platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
136 stars 104 forks source link

ATtiny85 runs at half speed due to bad clock source setting #264

Closed Granjow closed 2 years ago

Granjow commented 2 years ago

Commit 012de336af56472e65e2db2e6c2d95d9a137803d, which was released with version 3.4.0, breaks ATtiny support when using frequencies other than 16 MHz. When setting board_build.f_cpu = 8000000L, the code is still compiled for 16 MHz due to the clock source and therefore the code only runs half as fast.

I don't know where the correct place to fix #255 is, but the attiny85.json definitely isn't because it is not even possible to override the clock source setting with board_build.clocksource = 0. A local workaround would probably be to set board_build.clocksource = 6 e.g. for the ATtiny85 in the platformio.ini.

rholder commented 2 years ago

@Granjow Thanks for the detailed description here as it helped me get a project build fixed much faster than I expected. I've opened up a PR with your suggested change.

valeros commented 2 years ago

Hi @Granjow @rholder ! Thanks for reporting, should be fixed in the dev branch. Please retest with the upstream version of the platform:

[env:attiny85]
platform = https://github.com/platformio/platform-atmelavr.git
framework = arduino
board = attiny85

I don't know where the correct place to fix #255 is, but the attiny85.json definitely isn't because it is not even possible to override the clock source setting with board_build.clocksource = 0.

It's was possible to override simply by specifying your own define -DCLOCK_SOURCE=0. Anyway, as you requested, it's now also possible to configure these settings via the board configuration:

[env:attiny85]
platform = atmelavr
framework = arduino
board = attiny85
board_build.f_cpu = 16000000L
board_build.clock_source = 6
Granjow commented 2 years ago

@rholder Glad to hear!

@valeros Thanks a lot for the fix! Can I use pio platform install to test the upstream version?

valeros commented 2 years ago

@Granjow Yes, simply run pio platform install https://github.com/platformio/platform-atmelavr.git, but to avoid any conflicts I'd recommend to delete the stable version beforehand.

Granjow commented 2 years ago

@valeros That worked. Can confirm that with this patch the problem is solved and the ATtiny85 now runs as expected. Thanks again!

ikatkov commented 2 years ago

For people who came here from a websearch if your attyiny85 runs at half speed through Platformio and works fine through Arduino IDE

I'd assume that the next release will fix it, but until then these are your only options

ur99999999 commented 2 years ago

temporary fix: add next line to platformio.ini [env:...] build_flags = -DCLOCK_SOURCE=0