From e759db5558d9028496ec09a5f8eea1cb596e1c2f Mon Sep 17 00:00:00 2001 From: bartoolina Date: Sat, 5 Sep 2020 16:55:20 +0200 Subject: [PATCH] avr-gcc i ceedling dzialaja kolo siebie. +makefile --- .vscode/c_cpp_properties.json | 10 ++- Makefile | 125 ++++++++++++++++++++++++++++++ src/i2c/i2c.c | 6 ++ src/{ => i2c}/i2c.h | 0 src/{ => lights}/lights.c | 0 src/{ => lights}/lights.h | 0 src/main.c | 33 ++++++++ src/{ => tempSensor}/tempSensor.c | 2 +- src/{ => tempSensor}/tempSensor.h | 0 9 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 Makefile create mode 100644 src/i2c/i2c.c rename src/{ => i2c}/i2c.h (100%) rename src/{ => lights}/lights.c (100%) rename src/{ => lights}/lights.h (100%) create mode 100644 src/main.c rename src/{ => tempSensor}/tempSensor.c (88%) rename src/{ => tempSensor}/tempSensor.h (100%) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 402fbd5..83e0b8c 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,10 +4,14 @@ "name": "Linux", "includePath": [ "${workspaceFolder}/**", - "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/unity/src/", - "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/cmock/src" + "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/unity/src", + "/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/cmock/src", + "/usr/lib/avr/include" + ], + "defines": [ + "__AVR_ATmega644PA__", + "F_CPU=11059200" ], - "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c99", "cppStandard": "gnu++14", diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a52530 --- /dev/null +++ b/Makefile @@ -0,0 +1,125 @@ +SHELL := /bin/bash +# Created by bartool +# 15.03.2020 +# TODO +# Create pattern for upload +# Create pattern for init (create main.c, src dir, setting.json, c_cpp_properties.json) +PROCESSOR := ATmega644PA +F_CPU := 11059200UL + +DUDE_PROGRAMMER := ATB-FT232R +DUDE_PORT := ft0 + +SRC_DIR := src +BUILD_DIR := build/$(PROCESSOR) + +OPTIMIZE = Os +AVRDUDE_PATH := C:/avr/avrdude +CC := avr-gcc +OBJCOPY := avr-objcopy +OBJDUMP := avr-objdump +OBJSIZE := avr-size + +PROJECT_NAME := $(notdir $(CURDIR)) +ELF := $(BUILD_DIR)/$(PROJECT_NAME).elf +LSS := $(BUILD_DIR)/$(PROJECT_NAME).lss +MAP := $(BUILD_DIR)/$(PROJECT_NAME).map +FLASH_IMAGE := $(BUILD_DIR)/$(PROJECT_NAME).hex +EEPROM_IMAGE := $(BUILD_DIR)/$(PROJECT_NAME).eep + +C_FILES := $(wildcard $(SRC_DIR)/*/*.c) $(wildcard $(SRC_DIR)/*.c) +OBJ_FILES := $(patsubst src/%.c, $(BUILD_DIR)/%.o, $(C_FILES)) +DIRS := $(sort $(dir $(OBJ_FILES))) + +# lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1)))))))))))))))))))))))))) +MCU := $(shell echo $(PROCESSOR) | tr '[:upper:]' '[:lower:]') +# MCU = $(call lc,$(PROCESSOR)) + +# kratka sa oznaczene opcje wykorzystywane przez eclipse +CFLAGS = -mmcu=$(MCU)# +CFLAGS += -$(OPTIMIZE)# +CFLAGS += -g +CFLAGS += -std=gnu99# +CFLAGS += -funsigned-char# +CFLAGS += -funsigned-bitfields# +CFLAGS += -fpack-struct# +#CFLAGS += -ffreestanding +CFLAGS += -ffunction-sections# +CFLAGS += -fdata-sections# +CFLAGS += -fshort-enums# +CFLAGS += -fverbose-asm +CFLAGS += -Wall# +#CFLAGS += -Ic:/avr/avr_toolchain/avr/include +CFLAGS += -Wstrict-prototypes +CFLAGS += -DF_CPU=$(F_CPU)# + +ESC := \033[ +STOP := $(ESC)0m +RESET := $(ESC)$(STOP) +DEBUG := $(RESET)$(ESC)36;49;2m +FOCUS := $(RESET)$(ESC)35;49;10m +PROGRAM := $(RESET)$(ESC)33;49;1m + +all: $(ELF) $(LSS) $(FLASH_IMAGE) $(EEPROM_IMAGE) sizedummy + +build: $(ELF) + +$(DIRS): + @echo -e "$(DEBUG)>>> Making a dir: $(FOCUS)$@$(DEBUG) <<<$(STOP)" + @mkdir -p $@ + +$(ELF): $(OBJ_FILES) + @echo -e "$(DEBUG)>>> Building target: $(FOCUS)$@$(DEBUG) <<<$(STOP)" + @echo -e "$(DEBUG)>>> Invoking: AVR C Linker <<<$(STOP)" + $(CC) -Wl,-Map,$(MAP) -mmcu=$(MCU) -o $(ELF) $(OBJ_FILES) + +$(LSS): $(ELF) + @echo -e "$(DEBUG)>>> Invoking: AVR Create Extended Listing $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJDUMP) -h -S $(ELF) > $(LSS) + +$(FLASH_IMAGE): $(ELF) + @echo -e "$(DEBUG)>>> Create flash image (ihex format) $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJCOPY) -j .text -j .data -O ihex $(ELF) $(FLASH_IMAGE) + +$(EEPROM_IMAGE): $(ELF) + @echo -e "$(DEBUG)>>> Create eeprom image (ihex format) $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(OBJCOPY) -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 -O ihex $(ELF) $(EEPROM_IMAGE) + +sizedummy: $(ELF) + @echo -e "$(DEBUG)>>> Invoking: Print size <<<$(STOP)" + $(OBJSIZE) --format=avr --mcu=$(MCU) $(ELF) + +clean: + @echo -e "$(DEBUG)>>> Cleaning... <<<$(STOP)" + rm -rf $(ELF) $(LSS) $(MAP) $(FLASH_IMAGE) $(EEPROM_IMAGE) $(OBJ_FILES) + rm -rf $(DIRS) + +info: + @echo -e "$(DEBUG)MCU: $(MCU) F_CPU: $(F_CPU)$(STOP)" + @echo -e "$(DEBUG)Programer: $(DUDE_PROGRAMMER) Port: $(DUDE_PORT)$(STOP)" + @echo -e "$(DEBUG)Source dir: $(SRC_DIR) Build dir: $(BUILD_DIR)$(STOP)" + @echo -e "$(DEBUG)Project name: $(PROJECT_NAME)$(STOP)" + @echo -e "$(FOCUS)elf: $(ELF) lss: $(LSS) map: $(MAP)$(STOP)" + @echo -e "$(DEBUG)hex: $(FLASH_IMAGE) $(ESC)$(STOP)$(FOCUS)eep: $(EEPROM_IMAGE)$(STOP)" + @echo -e "$(DEBUG)All dirs: $(DIRS)$(STOP)" + @echo -e "$(DEBUG)All c files: $(C_FILES)$(STOP)" + @echo -e "$(DEBUG)All o files: $(OBJ_FILES)$(STOP)" + @echo -e "$(DEBUG)Cflags: $(CFLAGS)$(STOP)" + @echo $(LOWER_VAR) + @echo "done" + +# nie testowane! sprawdzic poprawnosc parametrow +flash: $(FLASH_IMAGE) + @echo -e " $(PROGRAM)>>> Uplod only flash <<<$(STOP)" + $(AVRDUDE_PATH)/avrdude -p $(MCU) -P $(DUDE_PORT) -c $(DUDE_PROGRAMMER) -U flash:w:$(FLASH_IMAGE):i + +flash_eeprom: + @echo -e " $(PROGRAM)>>> Upload flash and eeprom <<<$(STOP)" + avrdude -p $(MCU) -P $(DUDE_PORT) -c $(DUDE_PROGRAMMER) -U flash:w:$(FLASH_IMAGE):i -D -U eeprom:w:$(EEPROM_IMAGE):i + +.SECONDEXPANSION: +$(OBJ_FILES): $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $$(wildcard $$(dir $(SRC_DIR)/%.c)*.h) + @if [ ! -d "$(dir $@)" ]; then echo -e "$(DEBUG) >>> Create dir: $(FOCUS)$(dir $@)$(DEBUG) <<<$(STOP)"; mkdir -p $(dir $@); fi + @echo -e "$(DEBUG)>>> Building file: $(FOCUS)$<$(DEBUG) --> $(FOCUS)$@$(DEBUG) <<<$(STOP)" + $(CC) $(CFLAGS) -c -o $@ $< + diff --git a/src/i2c/i2c.c b/src/i2c/i2c.c new file mode 100644 index 0000000..fa4533a --- /dev/null +++ b/src/i2c/i2c.c @@ -0,0 +1,6 @@ +#include "i2c.h" + +uint16_t i2c_readRegister(uint8_t registerAddress) +{ + return 0x00; +} \ No newline at end of file diff --git a/src/i2c.h b/src/i2c/i2c.h similarity index 100% rename from src/i2c.h rename to src/i2c/i2c.h diff --git a/src/lights.c b/src/lights/lights.c similarity index 100% rename from src/lights.c rename to src/lights/lights.c diff --git a/src/lights.h b/src/lights/lights.h similarity index 100% rename from src/lights.h rename to src/lights/lights.h diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..de24b56 --- /dev/null +++ b/src/main.c @@ -0,0 +1,33 @@ +#include "lights/lights.h" +#include + +#define _FREQU 680 + +void adc_timer_init(void); + +int main(void) +{ + lights_SetHeadlightSwitchOn(); + lights_SetHeadlightSwitchOff(); + + while (1) + { + PORTB |= (PB3 >> 1); + adc_timer_init(); + } +} + +void adc_timer_init(void) +{ + ADMUX |= (1 << REFS1) | (1 << ADLAR); + ADCSRA |= (1 << ADEN) | (1 << ADATE) | (1 << ADPS2) | (1 << ADPS0) | (1 << ADIE); + //11 059 200/32 = 345 600/13,5 = 25 600 + ADCSRB |= (1 << ADTS1) | (1 << ADTS0); + DIDR0 |= (1 << ADC0D); + + TCCR0A |= (1 << WGM01); + // OCR0A = F_CPU/8/19200; + OCR0A = F_CPU / 64 / _FREQU; + TCCR0B |= (1 << CS01) | (1 << CS00); + TIMSK0 |= (1 << OCIE0A); +} \ No newline at end of file diff --git a/src/tempSensor.c b/src/tempSensor/tempSensor.c similarity index 88% rename from src/tempSensor.c rename to src/tempSensor/tempSensor.c index 31522f9..5808cb4 100644 --- a/src/tempSensor.c +++ b/src/tempSensor/tempSensor.c @@ -1,5 +1,5 @@ #include "tempSensor.h" -#include "i2c.h" +#include "../i2c/i2c.h" #include float tempSensor_getTemperature(void) diff --git a/src/tempSensor.h b/src/tempSensor/tempSensor.h similarity index 100% rename from src/tempSensor.h rename to src/tempSensor/tempSensor.h