platformio / platform-atmelmegaavr

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

Include errors with ATTINY3227 #44

Closed Optoneer closed 2 years ago

Optoneer commented 2 years ago

Hi,

I am facing an issue with setting up a project using an attiny3227. I am using an attiny1626 in another project, what works perfectly.

What I have done:

[env:ATtiny3227]
platform = atmelmegaavr
# board = ATtiny1626
board = ATtiny3227
framework = arduino

board_build.f_cpu = 20000000L
board_build.mcu = attiny3227
board_hardware.oscillator = internal ; internal or external
board_build.extra_flags = 
    -D $BOARD_MCU
    -D MILLIS_USE_TIMERA0

Could someone point me to the right direction? If you need further information, please do not hesitate to ask, I am happy to provide them as good as I can.

Best wishes, Marius

Optoneer commented 2 years ago

Today I see after opening the project, that it is unable to resolve the configuration for avr-gcc.exe and it would use a MinGW-gcc.exe. This does not pop up when opening the attiny1626 project.

What I continued to try - without success:

Any ideas?

Optoneer commented 2 years ago

Got it. Platformio does not include the necessary include files. If anyone faces this issue, too:

  1. Download DFP (Device Family Pack) from Atmel Homepage (Rename to *.zip and extract somewhere)
  2. Ensure that \\.platformio\packages\toolchain-atmelavr\avr\include\avr\io.h contains the #include for the correct header file.
    #elif defined (__AVR_ATtiny3227__)
    #  include <avr/iotn3227.h>
  3. header file
    • Copy \\include\avr\iotn3227.h to
    • \\.platformio\packages\toolchain-atmelavr\avr\include\avr\iotn3227.h
  4. archive file .a and startup file crt.o
    • Copy \\gcc\dev\attiny3227\avrxmega3\libattiny3227.a and crtattiny3227.o to
    • \\.platformio\packages\toolchain-atmelavr\avr\lib\
  5. specs file
    • Copy \\gcc\dev\attiny3227\device-specs\specs-attiny3227 to
    • \\.platformio\packages\toolchain-atmelavr\lib\gcc\avr\7.3.0\device-specs\

It starts to compile, but I get a compile error. I think, it is because it is not well tested and the vendor Microchip has not yet completely updated their include files, i.e. using the same names everywhere ...

My issue was with the CLK-Sel. I changed the device header file \\.platformio\packages\toolchain-atmelavr\avr\include\avr\iotn3227.h like this:

/* Clock Select */
typedef enum TCB_CLKSEL_enum
{
    TCB_CLKSEL_DIV1_gc = (0x00<<1),  /* CLK_PER */
    TCB_CLKSEL_DIV2_gc = (0x01<<1),  /* CLK_PER/2 */
    TCB_CLKSEL_TCA0_gc = (0x02<<1),  /* Use CLK_TCA from TCA0 */
    TCB_CLKSEL_EVENT_gc = (0x07<<1)  /* Count on event edge */
} TCB_CLKSEL_t;

changed to

/* Clock Select */
typedef enum TCB_CLKSEL_enum
{
    TCB_CLKSEL_CLKDIV1_gc = (0x00<<1),  /* CLK_PER */
    TCB_CLKSEL_CLKDIV2_gc = (0x01<<1),  /* CLK_PER/2 */
    TCB_CLKSEL_CLKTCA0_gc = (0x02<<1),  /* Use CLK_TCA from TCA0 */
    TCB_CLKSEL_EVENT_gc = (0x07<<1)  /* Count on event edge */
} TCB_CLKSEL_t;
Optoneer commented 2 years ago

Close