Hi,
I'm doing a project using the new ATtiny404. I'm using a PICkit4 (long-time PIC user here) and MPLABX v5.10 with the AVR-GCC toolchain v5.4.0 for my development - I'm on a mac, so Atmel Studio is a no-go. I'm new to AVRs, and have spent a LOT of time on the forums/datasheets the past few days, but I'm still pretty shaky on some of the concepts, especially to do with gcc, linkers etc. - apologies in advance.
I'm using Timer A (TCA0) periodic overflow interrupt to change the output on PORTA. The byte to be written to the PORT will be stored in 2 char variables, d1 and d2. On each interrupt, one of these bytes is to be written to PORTA (alternating between the 2, for which a third variable is used, which keeps track of which of these bytes is currently in use, called dActive).
The timer interrupt is working correctly as expected.
The problem - since d1, d2 and dActive need to be accessed by the ISR as well as from other functions, I'm trying to declare them globally as volatile uint8_ts. The variables get declared without a problem, however, any statement accessing them (either in main() or in the ISR) causes linker errors.
#include <stdio.h> #include <stdlib.h> #define F_CPU 3333333 #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> #include "portio.h" #define delay_ms(x) _delay_ms(x) #define digitSel B,1 #define digitVal PORTA_OUT volatile uint8_t dActive=0; volatile uint8_t d1=0x19, d2=0xe6; /* * */ FUSES = { .OSCCFG = FREQSEL_20MHZ_gc, .SYSCFG0 = CRCSRC_NOCRC_gc | RSTPINCFG_UPDI_gc, .SYSCFG1 = SUT_64MS_gc, .APPEND = 0x00, // Application data section disabled .BOOTEND = 0x00 // Boot section disabled }; void init() { TCA0.SINGLE.INTCTRL |= (1 << TCA_SINGLE_OVF_bp); /* Overflow Interrupt: enabled */ TCA0.SINGLE.PER = 0xff; /* Period: 0xff */ TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV64_gc /* System Clock / 64 */ | 1 << TCA_SINGLE_ENABLE_bp; sei(); } ISR(TCA0_OVF_vect) { if(dActive==1) //lines starting here are the ones causing the issue. digitVal=d2; else digitVal=d1; if(++dActive==2) dActive=0; //issue causing block ends here. output_toggle(digitSel); TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm; } int main() { init(); PORTA.DIR=0xFE; Set_Output(digitSel); digitVal=0xe6; while(1) { _delay_ms(1000); } return (EXIT_SUCCESS); }
The errors are:
"/Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/avr-gcc" -mmcu=attiny404 -I "/Applications/microchip/mplabx/v5.10/packs/Atmel/ATtiny_DFP/1.3.238/include" -B "/Applications/microchip/mplabx/v5.10/packs/Atmel/ATtiny_DFP/1.3.238/gcc/dev/attiny404" -x c -c -D__ATtiny404__ -funsigned-char -funsigned-bitfields -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -MD -MP -MF "build/default/production/main.o.d" -MT "build/default/production/main.o.d" -MT build/default/production/main.o -o build/default/production/main.o main.c -DXPRJ_default=default "/Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/avr-gcc" -mmcu=attiny404 -B "/Applications/microchip/mplabx/v5.10/packs/Atmel/ATtiny_DFP/1.3.238/gcc/dev/attiny404" -D__ATtiny404__ -Wl,-Map="dist/default/production/app1.X.production.map" -o dist/default/production/app1.X.production.elf build/default/production/main.o -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -Wl,--gc-sections -Wl,--start-group -Wl,-lm -Wl,--end-group /Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803f02 of dist/default/production/app1.X.production.elf section `.data' is not within region `data' /Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803f03 of dist/default/production/app1.X.production.elf section `.bss' is not within region `data' /Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803f02 of dist/default/production/app1.X.production.elf section `.data' is not within region `data' /Users/samay/Downloads/avr8-gnu-toolchain-darwin_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: address 0x803f03 of dist/default/production/app1.X.production.elf section `.bss' is not within region `data' collect2: error: ld returned 1 exit status make[2]: *** [dist/default/production/app1.X.production.hex] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2
The Makefile is the one generated by MPLAB, and the program compiles fine if the lines marked in the ISR function are removed.
What is it that i'm doing wrong here? Any help would be much appreciated.
Thanks!