'avr-gcc'에 해당되는 글 1건

  1. 2016.11.09 Linux 에서 AVR 컴파일 및 프로그래밍
2016. 11. 9. 23:18

윈도우 에서 삽질하다 포기하고 리눅스로 넘어왔다.


첨부터 리눅스로 할껄...;;


필요한 프로그램 설치

apt install gcc-avr avr-libc avrdude 


다른 곳에서는 binutils 와 uisp 까지 설치 하라고 되있는 곳도 있던데...

일단 테스트 결과 네모 안에 있는 3개만 설치해도 빌드 및 프로그램이 가능함을 확인 하였다.

avr-gcc, avrdude 만 있음 되는 거 같다... 일단은 -_-


음영으로 표시된 부분이 명령창에서 입력하는 부분이다.



1. 소스 작성 (cpp)

2. Makefile 작성

3. 컴파일 -> hex 파일 생성

4. 프로그램 -> hex 파일 을 ATMega328p 에 전송 (USBASP 2.0 사용)

5. 퓨즈비트 세팅 -> 내장클릭 1Mhz 를 사용하지 않고 외부의 16 MHz 크리스탈을 사용하여 동작하도록 설정



잊어먹기 전에 정리.... -_-;;


안되서 맨날 시방시방 하다가 되니까... 이 기분을 어찌 표현해야 할지... ㅎㅎㅎ


펌웨어 버젼 어쩌고 경고 뜨는데, 현재로서는 모르겠다능 -_-;;

펍업 하다 USBASP 해먹으면... 진행을 못하니까... 열댓개 사서 시도를 해보던가 해야겠다.



ledblink.cpp

#define F_CPU 16000000UL

#include <avr/io.h>

#include <util/delay.h>

int main(void)

{

DDRB |= (1<<DDB5); //Set the 6th bit on PORTB (i.e. PB5) to 1 => output

while(1)

{

PORTB |= (1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 1 => on

_delay_ms(1000);        //Delay for 1000ms => 1 sec

PORTB &= ~(1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 0 => off

_delay_ms(1000);        //Delay for 1000ms => 1 sec

}



Makefile

ledblink.o: dummy

avr-gcc -mmcu=atmega328p -Os ledblink.cpp -o ledblink.o


ledblink: ledblink.o

avr-objcopy -j .text -j .data -O ihex ledblink.o ledblink.hex


dummy: 



compile

$ make ledblink

avr-gcc -mmcu=atmega328p -Os ledblink.cpp -o ledblink.o

avr-objcopy -j .text -j .data -O ihex ledblink.o ledblink.hex 



program

$ avrdude -c usbasp -p m328p -e -U flash:w:ledblink.hex


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: AVR device initialized and ready to accept instructions


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


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: erasing chip

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: reading input file "ledblink.hex"

avrdude: input file ledblink.hex auto detected as Intel Hex

avrdude: writing flash (176 bytes):


Writing | ################################################## | 100% 0.15s


avrdude: 176 bytes of flash written

avrdude: verifying flash memory against ledblink.hex:

avrdude: load data flash data from input file ledblink.hex:

avrdude: input file ledblink.hex auto detected as Intel Hex

avrdude: input file ledblink.hex contains 176 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 0.13s


avrdude: verifying ...

avrdude: 176 bytes of flash verified


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


avrdude done.  Thank you. 



fuse-bit setting

$ avrdude -c usbasp -p m328p -C /etc/avrdude.conf -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: AVR device initialized and ready to accept instructions


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


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: reading input file "0xFF"

avrdude: writing lfuse (1 bytes):


Writing | ################################################## | 100% 0.00s


avrdude: 1 bytes of lfuse written

avrdude: verifying lfuse memory against 0xFF:

avrdude: load data lfuse data from input file 0xFF:

avrdude: input file 0xFF contains 1 bytes

avrdude: reading on-chip lfuse data:


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


avrdude: verifying ...

avrdude: 1 bytes of lfuse verified

avrdude: reading input file "0xDE"

avrdude: writing hfuse (1 bytes):


Writing |                                                    | 0% 0.00s ***failed;  

Writing | ################################################## | 100% 0.03s


avrdude: 1 bytes of hfuse written

avrdude: verifying hfuse memory against 0xDE:

avrdude: load data hfuse data from input file 0xDE:

avrdude: input file 0xDE contains 1 bytes

avrdude: reading on-chip hfuse data:


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


avrdude: verifying ...

avrdude: verification error, first mismatch at byte 0x0000

         0xd9 != 0xde

avrdude: verification error; content mismatch


avrdude: safemode: hfuse changed! Was de, and is now d9

Would you like this fuse to be changed back? [y/n] y

avrdude: safemode: and is now rescued

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


avrdude done.  Thank you. 








Posted by 해비