我已经开始将我的一些atmega代码移动到静态库中,以便将来使用。使用该库存在一些问题。我已经编译并链接了它,它可以运行。问题在于USART函数需要一个数组作为输入,似乎只是向我的com端口发送噪声。在将代码放入静态库中之前,它运行良好。
Makefile库
## General Flags
PROJECT = june
MCU = atmega328p
TARGET = libJune.a
CC = avr-g++
F_CPU := 1200000LL
## Options common to compile, link and
assembly rules
COMMON = -fpack-struct -fshort-enums -
funsigned-char -funsigned-bitfields -
mmcu=$(MCU) -DF_CPU=$(F_CPU)
## Compile options common for all C
compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -Os -MD -MP -MT -MF
#CFLAGS += -MD -MP -MT $(*F).o -MF
dep/$(@F)
## Objects that must be built in order
to link
OBJECTS := adc.o pwm.o message.o
messagehandler.o
messagetranslationsenter.o usart.o
## Build
all: $(TARGET)
## Compile
adc.o: adc.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
pwm.o: pwm.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
message.o: message.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
messagehandler.o: messagehandler.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
messagetranslationsenter.o:
messagetranslationsenter.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
usart.o: usart.cpp
$(CC) $(INCLUDES) $(CFLAGS) -c $<
## Archive into a library file (.a)
$(TARGET): $(OBJECTS)
avr-ar -r $(TARGET) $(OBJECTS)
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) $(TARGET) #dep/*
Makefile程序
# the GNU make program
#
VERSION := 0.1
PROGRAM_NAME := heater$(VERSION)
# Chip and programmer
DEVICE_PROGRAMMER := usbtiny
CPU_AVRDUDE := m328p
MCU := atmega328p
F_CPU := 1200000LL
LIB_PATH := $(JUNE_ROOT)/avr
LIBS := -lJune -lm
INCLUDES := -I$(JUNE_ROOT)/avr
# FLAGS
CF := -c -Os -fpack-struct - fshort-enums -funsigned-char -funsigned- bitfields -mmcu=$(MCU) -DF_CPU=$(F_CPU)
$(INCLUDES)
LF := -Os -MD -MP -mmcu=$(MCU) -MT -static -L$(LIB_PATH) $(LIBS)
# TOOLS
CC := avr-g++
avrdude ?= avrdude
OBJECTS = main.o
all: $(PROGRAM_NAME)
main.o: main.cpp
$(CC) $(CF) -c $<
$(PROGRAM_NAME): $(OBJECTS)
$(MAKE) -C $(JUNE_ROOT)/avr
$(CC) -o $(PROGRAM_NAME) $(OBJECTS)
$(LF)
$(PROGRAM_NAME).hex: $(PROGRAM_NAME)
avr-objcopy -O ihex -R .eeprom
$(PROGRAM_NAME) $(PROGRAM_NAME).hex
.PHONY: flash
flash: programmedDevice
clean:
-rm -f *.o *.hex *.elf
programmedDevice_*.time
programmedDevice: $(PROGRAM_NAME).hex
$(avrdude) -c $(DEVICE_PROGRAMMER) -p
$(CPU_AVRDUDE) -v -U
flash:w:$(PROGRAM_NAME).hex
touch programmedDevice_$(CPU_GCC).time
$(PROGRAM_NAME)_$(CPU_GCC).hex:
$(Ofiles)
$(CC) $(LF) -o
$(PROGRAM_NAME)_$(CPU_GCC).elf
$(Ofiles)
$(avr_objcopy) -j .text -j .data -O
ihex $(PROGRAM_NAME)_$(CPU_GCC).elf
$(PROGRAM_NAME)_$(CPU_GCC).hex
clean:
-rm -f *.o *.hex *.elf
programmedDevice_*.time
$(MAKE) -C $(JUNE_ROOT)/avr clean
dumpchip_srec:
$(avrdude) -c $(DEVICE_PROGRAMMER)
-p $(CPU_AVRDUDE) -U
lfuse:r:lfuse_$(CPU_GCC).hex:i -U
hfuse:r:hfuse_$(CPU_GCC).hex:i -U
efuse:r:efuse_$(CPU_GCC).hex:i -U
eeprom:r:eeprom_$(CPU_GCC).hex:i -U
flash:r:flash_$(CPU_GCC).hex:i -U
lock:r:lock_$(CPU_GCC).hex:i -U
signature:r:sig_$(CPU_GCC).hex:i
dumpchip:
$(avrdude) -c $(DEVICE_PROGRAMMER) -p
$(CPU_AVRDUDE) -U
lfuse:r:lfuse_$(CPU_GCC).bin:r -U
hfuse:r:hfuse_$(CPU_GCC).bin:r -U
eeprom:r:eeprom_$(CPU_GCC).bin:r -U
flash:r:flash_$(CPU_GCC).bin:r -U
lock:r:lock_$(CPU_GCC).bin:r -U
signature:r:sig_$(CPU_GCC).bin:r -U
efuse:r:efuse_$(CPU_GCC).bin:r
check:
$(avrdude) -v -c
$(DEVICE_PROGRAMMER) -p $(CPU_AVRDUDE)
这是测试软件的一部分,它从静态库中调用usart函数,但是我也只能从它发送数据的com端口读取噪声。
while(true)
{
//
USART_putstring("Test");
_delay_ms(5000);
}
我认为我找不到找不到的编译器标志。如果我将usart文件添加到程序并进行编译,则一切运行正常。问题是将文件放在静态库中时。
编辑:
当我将定义F_CPU放在源文件中而不是Makefile中的-DF_CPU = $(F_CPU)时,它起作用