Menu

#140 MEGA2560/2561 target fails to compile without NUT_CPU_FREQ defined.

AVRGCC - Linux
open
nobody
9
2014-03-31
2014-03-31
No

Ethernut 5.2.2 - when using MCU_ATMEGA2561, and a Fixed MCU Clock (NUT_CPU_FREQ) is defined all works as expected.

However, when NUT_CPU_FREQ is not defined, compilation produces the following error:
../../nut/arch/avr/dev/ostimer.c:264: error: 'OCR2UB' undeclared (first use in this function)
../../nut/arch/avr/dev/ostimer.c:264: error: 'TCR2UB' undeclared (first use in this function)
../../nut/arch/avr/dev/ostimer.c: In function 'NutRegisterTimer':
../../nut/arch/avr/dev/ostimer.c:315: error: 'OCR2UB' undeclared (first use in this function)
../../nut/arch/avr/dev/ostimer.c:315: error: 'TCR2UB' undeclared (first use in this function)

Here is what I did to allow CPU clock calculation for mega2560 and 2561. This is all applied to the file 'nut/arch/avr/dev/ostimer.c':

(1) Fix missing/incorrect defines

add line 119: #define TCCR_AFLAGS 0

line 123: #define ASSR_BUSY (_BV(TCN2UB) | _BV(OCR2UB) | _BV(TCR2UB))
becomes: #define ASSR_BUSY (_BV(TCN2UB) | _BV(OCR2AUB) | _BV(TCR2AUB))

add line 126: #define TCCR_AFLAGS 0

line 130: #define ASSR_BUSY (_BV(TCN2UB) | _BV(OCR2UB) | _BV(TCR2UB))
becomes: #define ASSR_BUSY (_BV(TCN2UB) | _BV(OCR2AUB) | _BV(TCR2AUB))

(2) Fix cut-and-paste-a-bit-too-much

remove line 131: #define TCCR2B_AFLAGS (_BV(CS21))
remove line 132: #define ASSR_BIT AS2
remove line 133: #define ASSR_BUSY (_BV(TCN2UB) | _BV(OCR2UB) | _BV(TCR2UB))

(3) Introduce TIFRx define (and TIFRi, for Imagecraft ASM)

insert at line 153: #define TIFRx TIFR2
insert at line 154: #define TIFRi "0x37" //TIFR2
insert at line 162: #define TIFRx TIFR
insert at line 163: #define TIFRi "0x36" //TIFR

(4) Modify CountCpuLoops()

line 196: :"I"(_SFR_IO_ADDR(TIFR)) / Input %1 /
becomes: :"I"(_SFR_IO_ADDR(TIFRx)) / Input %1 /

line 211: asm("IN R19, 0x36");
becomes: asm("IN R19, " TIFRi);

line 214: asm("OUT 0x36, R19");
becomes: asm("OUT " TIFRi ", R19");

line 221: asm("IN R19, 0x36");
becomes: asm("IN R19, " TIFRi);

(5) Modify NutComputeCpuClock()

line 270: outb(TIFR, TIFR_TOVx);
becomes: outb(TIFRx, TIFR_TOVx);

(6) Modify NutRegisterTimer();

line 322: outb(TIFR, TIFR_OCFx);
becomes: outb(TIFRx, TIFR_OCFx);


Tested on Tickernut (mega2561 on 1.3g compatible homebrew hardware)

  • 18.432000 Mhz crystal measures as 18.432256 Mhz.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB