LINUX.ORG.RU

Как сделать работу в avr-gcc более удобной

 , ,


0

1

Покажите какие плюшки и как подключить чтобы было видно как работает код а то после

avr-gcc -mmcu=atmega8 -nostartfiles -Wl,--undefined=_mmcu blink.s -o blink.elf
ничего не видно, а после
vr-objdump -h blink.elf
ничего не понятно. Где синтаксис взять, а то тыкаться устал
.equ DDRB = 0x37  ;ОШИБКА

;;; Blinks LED on PB0 (pin 14) using a simple delay loop.
; blink.s — AVR GAS syntax for avr-gcc

; Symbol definitions (note the comma in .equ)
.equ DDRB,  0x37          ; I/O address of DDRB for ATmega8
.equ PORTB, 0x38          ; I/O address of PORTB
.equ PB0,   0             ; bit number 0

.org 0x0000
rjmp reset                 ; reset vector

reset:
    ldi  r16, (1 << PB0)   ; PB0 is a plain constant
    out  DDRB, r16         ; set PB0 as output

loop:
    ldi r16, (1<<PB0)      ; PB0 high
    out PORTB, r16
    rcall DELAY

    ldi r16, (0<<PB0)      ; PB0 low
    out PORTB, r16
    rcall DELAY
    rjmp loop

DELAY:
    ldi r17, 200
D1: dec r17
    brne D1
    ldi r18, 255
D2: dec r18
    brne D2
	ret

	/* Define the .mmcu section for simavr */
.section .mmcu,"a",@progbits

/* VCD Trace Header: tells simavr to create 'trace.vcd' */
.byte 0x01          /* tag for AVR_MMCU_TAG_VCD_TRACE */
.byte 24            /* size of this chunk */
.asciz "trace.vcd"  /* filename */

/* Trace entry: Monitor PORTB (Address 0x38 for ATmega8) */
.byte 0x02          /* tag for a trace symbol */
.byte 8             /* size */
.byte 0x38          /* address of PORTB in ATmega8 */
.byte 0x01          /* mask (bit 0) */
.asciz "LED_PIN"    /* name of the trace in GTKWave */

.byte 0x00          /* End of section */
	

Вот, что ИИ советует

To make pure-assembler projects behave like they did in AVR Studio, you mainly need to:

Assemble and link via avr-gcc (using the right -mmcu) rather than calling avr-as/avr-ld directly.

Use avr-objcopy and avr-size in the same way as for C, just changing how you pass the source.

Assembling like AVR Studio

Typical command for one .S (or .asm) file:

bash
avr-gcc -mmcu=atmega328p -x assembler-with-cpp -Wa,-gstabs \
  -c main.S -o main.o

Notes:

    -mmcu=... selects the same device as in AVR Studio’s project settings.

    -x assembler-with-cpp lets you use #define, #include, etc., through the C preprocessor (Studio often did that behind the scenes).

    -Wa,options passes options to the assembler; -gstabs or -g lets you debug in GDB/simulavr similarly to Studio’s debug info.
If you don’t want the C preprocessor, just use:
bash
avr-gcc -mmcu=atmega328p -x assembler -c main.S -o main.o
(or rename to .s and drop -x entirely). Linking and startup like Studio

If you want a “full” application with reset vector, interrupt vectors, and the C runtime (like a C project in Studio), you typically:

Provide your own entry label (often _start or similar) in assembly.

Link with the standard libraries and startup from avr-libc via avr-gcc:

bash
avr-gcc -mmcu=atmega328p -Wl,-Map=project.map \
  main.o other.o -o project.elf
If you want only your own hand‑written vectors and no C runtime, you can still use avr-gcc as a driver but add linker flags (linker script, no crt, etc.); for example:
bash
avr-gcc -mmcu=atmega328p -nostartfiles -nostdlib \
  -Wl,-Map=project.map,-Tyour_linker_script.ld \
  main.o -o project.elf
That corresponds more to a “bare” AVR Studio asm project where you manage vector table and initialization yourself. Generating HEX and size info

Same idea as in a C project; just apply to your .elf:

bash
avr-objcopy -O ihex -R .eeprom project.elf project.hex

avr-objcopy -O ihex -j .eeprom --set-section-flags .eeprom=alloc,load \
  --change-section-lma .eeprom=0 \
  project.elf project_eeprom.hex

avr-size -C --mcu=atmega328p project.elf
This will give you HEX and size output very similar to Studio’s. Minimal “AVR Studio‑style” asm Makefile

For an all‑assembly project:

MCU = atmega328p
CC  = avr-gcc
OBJCOPY = avr-objcopy
SIZE = avr-size

ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=project.map

all: project.hex

project.elf: main.o
	$(CC) $(LDFLAGS) $^ -o $@

%.o: %.S
	$(CC) $(ASFLAGS) -c $< -o $@

project.hex: project.elf
	$(OBJCOPY) -O ihex -R .eeprom $< $@
	$(SIZE) -C --mcu=$(MCU) $<


Последнее исправление: saufesma (всего исправлений: 2)

Правильно тебе говорят, про 455 циклов. Сколько у тебя тактовая частота? Вот и прикинь, сколько раз нужно разделить эту частоту, чтобы получить на выходе 1 Гц при скважности, равной двум.

yars068 ★★★★★
()
Ответ на: комментарий от yars068

Мне надо вспомнить как писать на ассемблере для atmel ATmega8 я давно это делал, а тут просто мысль пришла надо реализовать, а я забыл все. И windows c avr studio нема под рукой/

saufesma
() автор топика