Skip to content
0:00 / 0:00

#pointerarithmetic#arrays#gpio

#7 Arrays and Pointer Arithmetic

Quantum Leaps, LLC

74K subscribers • 20 videos on Hallway

YouTube

Intermediate. Assumes working knowledge.

119K views13 years ago2 recommendations

Systems programmingProgramming languagesCEmbedded systemsMemory management

An introduction to arrays and pointer arithmetic in C, demonstrating how to use them to access GPIO registers on ARM Cortex-M.

Embedded Systems Programming Lesson-7 introduces you to arrays and basic pointer arithmetic in C. You will learn how to apply these concepts to take advantage of the more advanced features of the Stellaris GPIO DATA registers, which answers some questions asked in the comments to this video course posted on YouTube. The lesson starts with explaining why the traditional read-modify-write sequence that you used in the previous lessons can be problematic when you add interrupts in the future. Next, you see how this problem can be solved in hardware by using the address bits as a mask for updating the GPIO DATA bits. You get an understanding that this solution requires many GPIO DATA registers, and you find out why the DATA register with the offset 0x3FC is so special. Next, you try to use a brute-force solution from lesson-3 to synthesize the GPIO DATA register addresses manually and you verify that it works, although is not very elegant. Next, you learn about arrays in C and their equivalence with pointers. Next, you see how to index into an array and you learn about the equivalence between array indexing and pointer arithmetic. Next, you verify the equivalence of the three approaches: address arithmetic, pointer arithmetic, and array indexing when it comes to the generated machine code. You learn about the difference between address arithmetic and pointer arithmetic. Finally, you learn about the two peripheral buses: APB and AHB in the LM4F microcontroller and you see how to switch the code to use the faster AHB. The next lesson will be devoted to functions in C. Stay tuned... ------ Resources: Companion web page for this video course: state-machine.com/quickstart GitHub repository for projects for this video course: github.com/QuantumLeaps/modern-embedded-programming-course YouTube playlist of the course: youtube.com/playlist?list=PLPW8O6W-1chwyTzI3BHwBLbGQoPFxPAPM

Why it's here

2 people recommend this

What people say. Recommended for its clear explanation of address offsets and register masking in embedded programming.

u/jeyoungin r/embedded • Recommends

On “Need help understanding address offsets.”

I know this is now an old thread, but I recently came across a YouTube video that explains the address offset very well. I thought you might find it helpful. (You can skip to about 4:00 to get to the address offset part.)

u/TheFlamingLemonin r/embedded • Recommends

On “Tiva C Launchpad GPIO accessing bus.”

I’m not sure. It’s certainly possible to use either one. Since you’re using that board there’s a good chance you’re already going through this tutorial series, but if not you can learn more about this from lesson 7 of the quantum leaps modern embedded systems programming course here