diff --git a/BaseMake.mk b/BaseMake.mk index 3633f1a..fe0c910 100644 --- a/BaseMake.mk +++ b/BaseMake.mk @@ -79,7 +79,7 @@ FORMAT = ihex # Even though the DOS/Win* filesystem matches both .s and .S the same, # it will preserve the spelling of the filenames, and gcc itself does # care about how the name is spelled on its command-line. -ASRC = +ASRC = # Optional compiler flags. # -g: generate debugging information (for GDB, or for COFF conversion) @@ -312,7 +312,7 @@ clean_list : [ -s $@ ] || rm -f $@ # Remove the '-' if you want to see the dependency files generated. --include $(SRC:.c=.d) +include $(SRC:.c=.d) -include $(PSRC:.cpp=.d) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..66bf646 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,81 @@ + +# +#include_directories(arduino/hardware/arduino/variants/standard) +#include_directories(arduino/hardware/arduino/avr/libraries/SPI/src) +#include_directories(arduino/hardware/arduino/avr/cores/arduino) +#include_directories(arduino/hardware/arduino/avr/variants/standard) +#include_directories(arduino/libraries/RF24) +#include_directories(arduino/libraries/SoftPWM) +#include_directories(arduino/hardware/tools/avr/avr/include) +#include_directories(./) +##include_directories(arduino/hardware/tools/avr/avr/include/avr/iom328p.h) +# + + +# Project name +project(battletank) + +# CMake version +cmake_minimum_required(VERSION 2.6) + +# Options +# Adjust to your board +set(MCU "atmega328p" ) +set(CPU_SPEED "16000000" ) +set(PORT "/dev/ttyUSB0") +set(PORT_SPEED "57600") +set(PIN_VARIANT "standard") +set(ARDUINO_PATH "arduino") +set(PROGRAMMER "arduino") +set(COMPILE_FLAGS "") + +# Set own source files +# Simply list all your C / C++ source (not header!) files here +set(SRC_FILES main.cpp) + +# Include directories +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${ARDUINO_PATH}/hardware/arduino/avr/libraries/SPI/src + ${ARDUINO_PATH}/hardware/arduino/avr/cores/arduino + ${ARDUINO_PATH}/hardware/arduino/avr/variants/standard + ${ARDUINO_PATH}/libraries/SoftPWM + ${ARDUINO_PATH}/libraries/RF24 + ${ARDUINO_PATH}/hardware/tools/avr/avr/include +) + +# Find Arduino source files. +file(GLOB_RECURSE ARDUINO_CORE_SRC + ${ARDUINO_PATH}/hardware/arduino/avr/cores/arduino/*.c + ${ARDUINO_PATH}/hardware/arduino/avr/cores/arduino/*.cpp + ${ARDUINO_PATH}/libraries/SoftPWM/*.cpp + ${ARDUINO_PATH}/libraries/RF24/*.cpp + ${ARDUINO_PATH}/hardware/arduino/avr/libraries/SPI/src/*.cpp +) + +# Compiler suite specification +set(CMAKE_C_COMPILER avr-gcc) +set(CMAKE_CXX_COMPILER avr-g++) +set(CMAKE_OBJCOPY avr-objcopy) +set(CMAKE_OBJDUMP avr-objdump) +set(CMAKE_RANLIB avr-ranlib) +set(CMAKE_LINKER avr-ld) + +# Compiler flags +add_definitions(-DBAUD=9600UL -DARDUINO -DROLE=1) +add_definitions(-mmcu=${MCU} -DF_CPU=${CPU_SPEED}) +add_definitions(-c -g -Os -Wall) +add_definitions(-fpack-struct -fno-exceptions -ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fshort-enums) + +# Linker flags +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") +set(CMAKE_EXE_LINKER_FLAGS "-Os -Wl,--gc-sections -mmcu=${MCU}") + +add_executable(${PROJECT_NAME} ${ARDUINO_CORE_SRC} ${SRC_FILES}) + +add_custom_target(flash + COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${PROJECT_NAME} ${PROJECT_NAME}.hex + COMMAND avrdude -F -p${MCU} -carduino -P${PORT} -b${PORT_SPEED} -D -Uflash:w:main.hex:i + DEPENDS ${PROJECT_NAME} + ) diff --git a/lib.h b/lib.h index 66c5b8d..4727406 100644 --- a/lib.h +++ b/lib.h @@ -1,3 +1,4 @@ + void uart_init() { // Upper and lower bytes of the calculated prescaler value for baud. UBRR0H = UBRRH_VALUE; diff --git a/main.cpp b/main.cpp index 4931021..414563c 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,6 @@ #define CS_PIN 2 #define RED 4 #define GREEN 5 -#define F_CPU 8000000UL class Radio {