添加功能时为什么我的Atmega328p程序会冻结?

问题描述 投票:0回答:1

我正在尝试在Atmega328p上创建一个简单的程序。当我只包含main函数时,它工作正常,但添加另一个函数(即使不调用它)会导致微控制器冻结(灯光根本不闪烁)。

我把它缩小到简单地添加一个空函数。以下冻结 - 只需注释掉它正常工作的功能(灯闪烁)。

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

int main(void){
    DDRB |= (1 << 5);
    PORTB |= (1 << 5);
    while(1){
        PORTB ^= (1 << 5);
        _delay_ms(500);
    }

return 0;
}

void Somerandomcrap(char data){

}

$ avr-gcc -mmcu=atmega328p -Os -Wall -DF_CPU=16000000 -I inc/   -c -o src/main.o src/main.c
$ avr-gcc -o main.elf src/main.o
$ avr-objcopy -O ihex main.elf main.hex
$ avrdude -c usbtiny -p atmega328p -U flash:w:main.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (80 bytes):

Writing | ################################################## | 100% 0.16s

avrdude: 80 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex auto detected as Intel Hex
avrdude: input file main.hex contains 80 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.09s

avrdude: verifying ...
avrdude: 80 bytes of flash verified

avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

avrdude done.  Thank you.

freeze avr-gcc
1个回答
0
投票

想出来 - 这是因为我只在编译器阶段传递MCU类型,而不是在链接器阶段传递。

© www.soinside.com 2019 - 2024. All rights reserved.