ATmega32 starts first declared function instead main

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

 

I have following code:

#define __AVR_ATmega32__
#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>

void secondary(void) {
    DDRA  = 0b00000011;
    PORTA = 0b11111100;

    while (1) {
        PORTA ^= (1 << PA0);
        _delay_ms(100);
    }
}

int main(void) {
    DDRA  = 0b00000011;
    PORTA = 0b11111100;

    while (1) {
        PORTA ^= (1 << PA1);
        _delay_ms(150);
        PORTA ^= (1 << PA1);
        _delay_ms(150);
        PORTA ^= (1 << PA1);
        _delay_ms(150);
        PORTA ^= (1 << PA1);
        _delay_ms(550);
    }

    return 0;
}

 

And then I compile BIN, generate HEX and flash it like this:

avr-gcc -Wall -g3 -Os -mmcu=avr5 -o $(APP).bin main.c
avr-objcopy -j .text -j .data -O ihex $(APP).bin $(APP).hex
avrdude -c linuxgpio -p atmega32 -U flash:w:$(APP).hex:i

 

The problem is ATmega32 runs secondary() function instead of main(). What am I doing wrong?

This topic has a solution.
Last Edited: Wed. Jan 1, 2020 - 08:36 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You are using the wrong start code. Use -mmcu=atmega32 and remove respective define from the source.
.
Better pick a correct source to copy/paste from...

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks! Wasn't entirely copy/paste...

I used this docs https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html and evidently get them wrong. Thank You again!