From 7e93cabdfe65fd01c5dc0c75ca74707be0547276 Mon Sep 17 00:00:00 2001 From: David Lenfesty Date: Mon, 23 Sep 2019 20:34:06 -0600 Subject: [PATCH] Did a blinky --- .gitignore | 4 +- lab_1/CMakeLists.txt | 156 +++++++++++++++++++++++++++++++++++++++++++ lab_1/main.c | 10 ++- main.c | 16 ----- 4 files changed, 165 insertions(+), 21 deletions(-) create mode 100644 lab_1/CMakeLists.txt delete mode 100644 main.c diff --git a/.gitignore b/.gitignore index 7b9b0ad..b57af0b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ cmake-build-debug/ cmake-build-debug/* .idea .idea/* -build/** -_build/** +*/build/** +*/_build/** diff --git a/lab_1/CMakeLists.txt b/lab_1/CMakeLists.txt new file mode 100644 index 0000000..98b1191 --- /dev/null +++ b/lab_1/CMakeLists.txt @@ -0,0 +1,156 @@ +################################################################################## +# "THE ANY BEVERAGE-WARE LICENSE" (Revision 42 - based on beer-ware +# license): +# wrote this file. As long as you retain this notice +# you can do whatever you want with this stuff. If we meet some day, and +# you think this stuff is worth it, you can buy me a be(ve)er(age) in +# return. (I don't like beer much.) +# +# Matthias Kleemann +################################################################################## + +################################################################################## +# Sample CMakeLists.txt for a simple AVR project based on the toolchain +################################################################################## + +cmake_minimum_required(VERSION 2.8) + +### TOOLCHAIN SETUP AREA ################################################# +# Set any variables used in the toolchain prior project() call. In that +# case they are already set and used. +########################################################################## + +################################################################################## +# tools to be used for programming the AVR +################################################################################## +set(AVR_UPLOADTOOL avrdude) +set(AVR_PROGRAMMER avrispmkII) +set(AVR_UPLOADTOOL_PORT usb) +# AVR and fuses needs to be set +set(AVR_MCU attiny13a) +set(AVR_H_FUSE 0xFF) +set(AVR_L_FUSE 0x6A) + +### END TOOLCHAIN SETUP AREA ############################################# + +########################################################################## +# name your project +########################################################################## +project(lab1) + +################################################################################## +# status messages +################################################################################## +message(STATUS "Current uploadtool is: ${AVR_UPLOADTOOL}") +message(STATUS "Current programmer is: ${AVR_PROGRAMMER}") +message(STATUS "Current upload port is: ${AVR_UPLOADTOOL_PORT}") +message(STATUS "Current uploadtool options are: ${AVR_UPLOADTOOL_OPTIONS}") +message(STATUS "Current MCU is set to: ${AVR_MCU}") +message(STATUS "Current H_FUSE is set to: ${AVR_H_FUSE}") +message(STATUS "Current L_FUSE is set to: ${AVR_L_FUSE}") + +################################################################################## +# set build type, if not already set at cmake command line +################################################################################## +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif(NOT CMAKE_BUILD_TYPE) + +################################################################################## +# needs to be defined for AVR toolchain +################################################################################## +set(MCU_SPEED "9600000UL") + +################################################################################## +# some cmake cross-compile necessities +################################################################################## +if(DEFINED ENV{AVR_FIND_ROOT_PATH}) + set(CMAKE_FIND_ROOT_PATH $ENV{AVR_FIND_ROOT_PATH}) +else(DEFINED ENV{AVR_FIND_ROOT_PATH}) + if(EXISTS "/opt/local/avr") + set(CMAKE_FIND_ROOT_PATH "/opt/local/avr") + elseif(EXISTS "/usr/avr") + set(CMAKE_FIND_ROOT_PATH "/usr/avr") + elseif(EXISTS "/usr/lib/avr") + set(CMAKE_FIND_ROOT_PATH "/usr/lib/avr") + elseif(EXISTS "/usr/local/CrossPack-AVR") + set(CMAKE_FIND_ROOT_PATH "/usr/local/CrossPack-AVR") + else(EXISTS "/opt/local/avr") + message(FATAL_ERROR "Please set AVR_FIND_ROOT_PATH in your environment.") + endif(EXISTS "/opt/local/avr") +endif(DEFINED ENV{AVR_FIND_ROOT_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +# not added automatically, since CMAKE_SYSTEM_NAME is "generic" +set(CMAKE_SYSTEM_INCLUDE_PATH "${CMAKE_FIND_ROOT_PATH}/include") +set(CMAKE_SYSTEM_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/lib") + +################################################################################## +# status messages for generating +################################################################################## +message(STATUS "Set CMAKE_FIND_ROOT_PATH to ${CMAKE_FIND_ROOT_PATH}") +message(STATUS "Set CMAKE_SYSTEM_INCLUDE_PATH to ${CMAKE_SYSTEM_INCLUDE_PATH}") +message(STATUS "Set CMAKE_SYSTEM_LIBRARY_PATH to ${CMAKE_SYSTEM_LIBRARY_PATH}") + +################################################################################## +# set compiler options for build types +################################################################################## +if(CMAKE_BUILD_TYPE MATCHES Release) + set(CMAKE_C_FLAGS_RELEASE "-Os") + set(CMAKE_CXX_FLAGS_RELEASE "-Os") +endif(CMAKE_BUILD_TYPE MATCHES Release) + +if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -save-temps -g -gdwarf-3 -gstrict-dwarf") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -save-temps -g -gdwarf-3 -gstrict-dwarf") +endif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS_DEBUG "-O0 -save-temps -g -gdwarf-3 -gstrict-dwarf") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -save-temps -g -gdwarf-3 -gstrict-dwarf") +endif(CMAKE_BUILD_TYPE MATCHES Debug) + +################################################################################## +# compiler options for all build types +################################################################################## +add_definitions("-DF_CPU=${MCU_SPEED}") +add_definitions("-fpack-struct") +add_definitions("-fshort-enums") +add_definitions("-Wall") +add_definitions("-Werror") +# http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Alternate-Keywords.html#Alternate-Keywords +# [...]-pedantic and other options cause warnings for many GNU C extensions. You can prevent such warnings within +# one expression by writing __extension__ before the expression. __extension__ has no effect aside from this.[...] +add_definitions("-pedantic") +add_definitions("-pedantic-errors") +add_definitions("-funsigned-char") +add_definitions("-funsigned-bitfields") +add_definitions("-ffunction-sections") +add_definitions("-c") +add_definitions("-std=gnu99") + +################################################################################## +# add AVR executable +################################################################################## +add_avr_executable( + main + main.c +) + +################################################################################## +# add AVR library +################################################################################## +# add_avr_library( +# +# +# ) + +################################################################################## +# link library to executable +# NOTE: It needs to be the elf target. +################################################################################## +# target_link_libraries(-${AVR_MCU}.elf -${AVR_MCU}) +# OR easier +#target_link_libraries( ) + diff --git a/lab_1/main.c b/lab_1/main.c index fb3e1e6..09587dc 100644 --- a/lab_1/main.c +++ b/lab_1/main.c @@ -1,16 +1,20 @@ #include +#include + + // Set up GPIO here void pin_setup() { - + DDRB |= (1 << DDB3); } int main() { - pin_setup() + pin_setup(); while (1) { - + PORTB ^= (1 << PORTB3); + _delay_ms(500); } } diff --git a/main.c b/main.c deleted file mode 100644 index 7c6ff5a..0000000 --- a/main.c +++ /dev/null @@ -1,16 +0,0 @@ -#include - -// Set up GPIO here -void pin_setup() { - -} - - -int main() { - pin_setup(); - - while (1) { - - } - -}