Git Product home page Git Product logo

savor's Introduction

Supplemental AVR (savor)

This is a library that I am writing while programming my ATMega328p. I'm wanting to start out with SPI, SD Cards, and support for the FAT32 file system.

Usage

The easiest way to include this set of libraries in your project is to place this repo within your project as a submodule and build your project with CMAKE using:

add_subdirectory(lib/savor)
target_link_libraries(${EXEC_NAME} savor)

A full example CMakeLists.txt for a project using this library is:

cmake_minimum_required(VERSION 3.12)

project(SampleProject)

set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR atmega328p)
set(CMAKE_CROSSCOMPILING 1)

set(CMAKE_C_COMPILER avr-gcc)
set(SOURCES src/main.c)

set(CMAKE_C_FLAGS "-g -Wall -mcall-prologues -mmcu=${CMAKE_SYSTEM_PROCESSOR} -Os")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -Wl,-relax")

add_subdirectory(lib/savor)

add_executable(${PROJECT_NAME}.elf ${SOURCES})
target_link_libraries(${PROJECT_NAME}.elf savor)

set(CMAKE_C_OBJCOPY avr-objcopy CACHE PATH "" FORCE)


add_custom_target(hex ALL DEPENDS ${PROJECT_NAME}.hex)
add_custom_command(OUTPUT ${PROJECT_NAME}.hex COMMAND ${CMAKE_C_OBJCOPY} ARGS -R .eeprom -O ihex ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex DEPENDS ${PROJECT_NAME}.elf )

add_custom_target(flash DEPENDS ${PROJECT_NAME}.hex)
add_custom_command(TARGET flash USES_TERMINAL COMMAND "avrdude -c stk500v2 -P $(pavr2cmd --prog-port) -p ${CMAKE_SYSTEM_PROCESSOR} -U flash:w:${PROJECT_NAME}.hex:i")

This requires avrdude and pavr2cmd. pavr2cmd is used for the Pololu AVR Programmer device.

Serial

This is the primary serial UART library. It ties into stdio so UART can be used as stdout after initialization.

Usage

Initialization is done with serial_init(ubrr). The UBRR can be calculated with the serial_ubrr(freq,baud) macro. It uses the clock frequency and target baud rate to set the serial baud.

After initialization, UART can be used as stdout so the stdio printf() function prints to it by default.

SPI

Currently the SPI module only supports master mode.

Usage

Initialization in master is done with SPI_MasterInit(). Transmission is done with SPI_Transceive(char), receiving is done with SPI_Receive().

savor's People

Contributors

gwnichol avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.