Giter Site home page Giter Site logo

avr_328p_freertos's Introduction

Building a AVR based FreeRTOS application (blinky)

This project walks you through the process building a FreeRTOS based AVR application to toggle a LED on the ATMega328p microcontroller. The FreeRTOS kernel is developed by leading chip manufacturers to provide a Real Time Operating System for microtrollers and microprocessors. Refer to your microcontroller's datasheet to determine optiomal memory footprint and stack size.

Prerequisites:

Installing avr-gcc

Installing avr-gcc on MacOS w/Brew

brew tap osx-cross/avr
brew install avr-gcc

verify installation

avr-gcc --version

Installing Avrdude on MacOS w/Brew

brew install avrdude
or
brew install avrdude --with-usb

verify installation

avrdude -v

The code

The vLEDFlashTask code below is the body of the thread that FreeRTOS will execute from the call stack. The for loop simply toggles the LED port on and off once per second.

void vLEDFlashTask(void *pvParms)
{
	vLEDInit();
	portTickType xLastWakeTime;
	const portTickType xFrequency = 1000;
	xLastWakeTime = xTaskGetTickCount();

	for(;;) {
		vLEDToggle();
		vTaskDelayUntil(&xLastWakeTime, xFrequency);
	}
}

Initialize LED

The code below initializes the led port and prepares for use.

void vLEDInit(void)
{
	DDRB |= _BV(PB5);
}

Toggle LED

Much like the blinky code we wrote in avr_328p_blinky, the following method is called from the FreeRTOS vLEDFlashTask thread to toggle the LED on and off.

void vLEDToggle(void)
{
	PORTB ^= _BV(PB5);
}

Compiling the code

To compile the source code we need to create a Makefile to autmoate the process. Makefiles allow us to place all build/clean/flash commands into one easy to use file. Each microcontroller has a unique set of parameters prior to compiling and deploying. These commands are listed a the top of the Makefile and are easily changed.

Below is a snippet of Makefile parametes that would be changed to target your project.

# parameters (make changes accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega328p
# mcu clock frequency
CLK = 8000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = usbtiny

Now that your Makefile is complete issue the make from the command start the build process.

make

Loading the code

Now that we compiled the code we can deploy to our microcontroller.

make flash

Summary

As you can see adding FreeRTOS support is pretty straight forward. FreeRTOS will allow you to program your microcontroller more like a computer using threads and task isolation. The tradeoff is more disciplined memory management of your threads. These skills only add to your ability to design more efficient code.

References:

https://github.com/osx-cross/homebrew-avr

http://www.linuxandubuntu.com/home/setting-up-avr-gcc-toolchain-and-avrdude-to-program-an-avr-development-board-in-ubuntu

avr_328p_freertos's People

Contributors

spice-weasel avatar johncobb 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.