x
Menu

Embedded Systems Programming

Other,

Updated On 02 Feb, 19

Overview

Getting Started - Counting - Flow of Control - Variables and Pointers - Blinking the LED - Preprocessor and volatile - Bit-wise operators in C - Arrays and Pointer Arithmetic - Functions and the Stack - Modules, Recursion, AAPCS - Stack Overflow and Other Pitfalls of Functions - stdint.h and mixing types - structures and CMSIS - startup code part - interrupts

Includes

Lecture 6: Preprocessor and volatile

4.1 ( 11 )


Lecture Details

Embedded Systems Programming Lesson-5 shows how to make the code more readable by using the C preprocessor. You also learn about the volatile keyword and how to use it to write programs that run correctly at any level of optimization.

The lesson starts with showing you how to define macros and explains how the C pre-processor substitutes the macros before the actual compilation.

Next, you define macros for all registers used in the "blinky" program and you test the code.

Next, you learn about the vendor-provided header file that conveniently defines all the registers for you.

You notice that the header file defines the registers as "volatile" and you learn what that means.

You also learn that "volatile" can be useful not just for the registers, but also for the "normal" variables like the delay-loop counter.

You increase the level of optimization to "high" and see for yourself that the compiler optimizes the delay loops "away".

You fix the problem by making the loop counter "volatile".

Finally, in the last step of the lesson, you learn how to actually include the "lm4f120h5qr.h" header file into your code and how to recognize the interesting registers in the header file.

In the next lesson you will learn how to use the bitwise OR and AND operators to blink the other colors of the composite LED and you will also learn about more advanced features of the GPIO registers. Stay tuned...

Miro Samek
state-machine.com

---
Resources

Article "Place volatile accurately" by Dan Saks
httpwww.embedded.comelectronics-blogsprogramming-pointers4025609Place-volatile-accurately

Article "Volatile as a promise" by Dan Saks
httpwww.embedded.comelectronics-blogsprogramming-pointers4025624Volatile-as-a-promise

YouTube playlist of the course
httpwww.youtube.complaylist?list=PLPW8O6W-1chwyTzI3BHwBLbGQoPFxPAPM

Course web-page
httpwww.state-machine.comquickstart

Ratings

0


0 Ratings
55%
30%
10%
3%
2%
Comments
comment person image

Sam

Excellent course helped me understand topic that i couldn't while attendinfg my college.

Reply
comment person image

Dembe

Great course. Thank you very much.

Reply
Send