Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
AVRのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
AVR
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
[[カテゴリ:開発]] [[en:AVR]] [[Wikipedia:AVR_microcontrollers|AVR]] is a family of microcontrollers (MCUs) developed by Microchip Technology (former AVR). AVRs are especially common in hobbyist and educational embedded applications, popularized by [[Arduino]] project. This page deals with 8-bit series of these MCUs. == Toolchain == Install {{Pkg|avr-gcc}} to get toolchain and GNU compiler. == Programmers == To flash compiled firmware to the AVR chip you will need programmer and software to rule it. Most popular programmers are [https://www.fischl.de/usbasp USBasp], [https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/ATAVRISP2 AVRISP mkII], [https://www.microchip.com/DevelopmentTools/ProductDetails/ATATMEL-ICE Atmel-ICE] and [https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/ATSTK500 STK500]. [https://www.olimex.com/Products/AVR/Programmers/AVR-PG2B There is] also exists the simplest DIY-programmer which works with LPT port. {{Pkg|avrdude}} supports them all great. === udev issues === If you're using AVRISP mkII or USBasp programmers please consider installing {{AUR|avrisp-udev}} and/or {{AUR|usbasp-udev}} respectively to be able to run avrdude without superuser rights. == Usage == To compile C program for AVR chip (let's consider ATmega8A running at 8 MHz as example) you can use {{ic|avr-gcc}} directly. You should only specify target MCU (full list of supported MCUs could be found in avr-gcc man page) and it's working frequency: $ avr-gcc -DF_CPU=8000000UL -mmcu=atmega8a -std=gnu99 main.c -o main.elf avrdude is smart enough to work with the resulting ELF file but you can convert it explicitly to Intel HEX: $ avr-objcopy -O ihex -j .text -j .data main.elf main.hex Then run avrdude and specify flash ROM as destination for formware burning (in this example AVRISP mkII is used and clock speed is lowered to the 125 kHz to be on safe side): $ avrdude -p atmega8 -c avrispmkII -B 125kHz -U flash:w:main.hex That's all. Among other things avrdude can work with EEPROM memory, fuse and lock bits. For example, to set up low and high fuses to the 0x9F and 0xD1 respectively use the following incantation: $ avrdude -p atmega8 -c avrispmkII -B 125kHz -U lfuse:w:0x9F:m -U hfuse:w:0xD1:m Just remember that ISP programming speed shouldn't exceed 1/8 of MCU's working frequency. A lot of new chips comes with 1 MHz speed settings so using 125 kHz as starting value should be fine enough. == Tips and tricks == === Optimization === Because AVRs come with tight flash ROM size and relatively weak CPUs you can consider some optimizations to improve space usage and overall performance of your device. It's common practice to enable GCC optimization level {{ic|-Os}} and turn on some extra features: {{ic|-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums}}. To exclude unnecessary library references perform garbage collection: {{ic|-ffunction-sections -fdata-sections -Wl,--gc-sections}}. === Sample Makefile === Managing huge project could be tedious and Makefile workflow is the most efficient way to deal with it. Here are sample Makefile based on [https://www.avrfreaks.net/sites/default/files/Makefile.txt AVRfreaks] version: CC = avr-gcc OBJCOPY = avr-objcopy SIZE = avr-size NM = avr-nm AVRDUDE = avrdude REMOVE = rm -f MCU = atmega8a F_CPU = 8000000 LFUSE = 0x9f HFUSE = 0xd1 TARGET = firmware SRC = main.c lcd.c twi.c OBJ = $(SRC:.c=.o) LST = $(SRC:.c=.lst) FORMAT = ihex OPTLEVEL = s CDEFS = CFLAGS = -DF_CPU=$(F_CPU)UL CFLAGS += $(CDEFS) CFLAGS += -O$(OPTLEVEL) CFLAGS += -mmcu=$(MCU) CFLAGS += -std=gnu99 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -Wall -Wstrict-prototypes CFLAGS += -Wa,-adhlns=$(<:.c=.lst) LDFLAGS = -Wl,--gc-sections LDFLAGS += -Wl,--print-gc-sections AVRDUDE_MCU = atmega8 AVRDUDE_PROGRAMMER = avrispmkII AVRDUDE_SPEED = -B 1MHz AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER) AVRDUDE_FLAGS += $(AVRDUDE_SPEED) MSG_LINKING = Linking: MSG_COMPILING = Compiling: MSG_FLASH = Preparing HEX file: all: gccversion $(TARGET).elf $(TARGET).hex size .SECONDARY: $(TARGET).elf .PRECIOUS: $(OBJ) %.hex: %.elf @echo @echo $(MSG_FLASH) $@ $(OBJCOPY) -O $(FORMAT) -j .text -j .data $< $@ %.elf: $(OBJ) @echo @echo $(MSG_LINKING) $@ $(CC) -mmcu=$(MCU) $(LDFLAGS) $^ --output $(@F) %.o : %.c @echo $(MSG_COMPILING) $< $(CC) $(CFLAGS) -c $< -o $(@F) gccversion: @$(CC) --version size: $(TARGET).elf @echo $(SIZE) -C --mcu=$(AVRDUDE_MCU) $(TARGET).elf analyze: $(TARGET).elf $(NM) -S --size-sort -t decimal $(TARGET).elf isp: $(TARGET).hex $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(TARGET).hex fuses: $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m release: fuses isp clean: $(REMOVE) $(TARGET).hex $(TARGET).elf $(OBJ) $(LST) *~ === Calculating control register values === To speed up development of your projects you can use {{AUR|avrcalc}} utility which helps to calculate different parameters for control registers regarding timers, frequencies etc. == See also == * [[Arduino]] * https://www.microchip.com/design-centers/8-bit/avr-mcus
このページで使用されているテンプレート:
テンプレート:AUR
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:Man
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
テンプレート:TranslationStatus
(
ソースを閲覧
)
AVR
に戻る。
検索
検索
AVRのソースを表示
話題を追加