Skip to content

Add ATtiny Support #1382

Open
Open
@fabyte

Description

@fabyte

Hi,
I want to contribute my changes to MySensors in order to support ATtiny MCUs (see the project page).

Three issues had to be addressed:

  1. Make RF24 driver be able to handle CE pin pulled up to VCC (already created PR RF24: Add 4-pin configuration support #1381 for this)
  2. Some register names had to be redefined and a function had to be defined to be able to compile MySensors for ATtiny.
  3. Fix hwCPUFrequency() in MyHwAVR.cpp

I want to discuss these issues:

  1. The missing defines are:
#define SIGRD   RSIG    // Signature Row from Store Program Memory Control and Status Register
#define EIFR    GIFR    // External/General Interrupt Flag Register
#define WDTCSR  WDTCR   // WDT Control Register
// #define TCCR1A TCCR1 // optional
// #define TIFR1 TIFR	// optional
extern void serialEventRun(void) __attribute__((weak));

Where should these definitions be places? Is there some kind of compatiblity.h header in the project for different MCUs?

  1. The hwCPUFrequency() seems to dynamically measure the CPU frequency and for this all timers are suspended. Since ATtiny supports not that much timers, the more simple approach for a fix would be like for other hardware platforms:
@@ -309,6 +309,11 @@ uint16_t hwCPUVoltage(void)
 uint16_t hwCPUFrequency(void)
 {
+#if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || \
+       defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
+       // reporting compile time frequency (in 1/10MHz)
+       return F_CPU / 100000UL;
+#else
        cli();
        // save WDT & timer settings
        const uint8_t WDTsave = WDTCSR;
@@ -343,6 +348,7 @@ uint16_t hwCPUFrequency(void)
        TCCR1C = TCCR1Csave;
        // return frequency in 1/10MHz (accuracy +- 10%)
        return result;
+#endif
 }

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions