ARM Embedded Programming Lecture 4 Accessing Memory Mapped Registers.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Assembly Language.
3-1 Peripherals & I/O lines All the on-chip peripherals are configured and controlled through Special Function Registers (SFR) Many of the SFR’s are bit.
Introduction to Micro-controllers Anurag Dwivedi.
ECE 447 Fall 2009 Lecture 2: TI MSP430 Software Development C and MSP430 Assembly.
INSTRUCTION SET ARCHITECTURES
7-5 Microoperation An elementary operations performed on data stored in registers or in memory. Transfer Arithmetic Logic: perform bit manipulation on.
Outline MSP430 LaunchPad MSP430 Microcontroller
There are two types of addressing schemes:
Processor System Architecture
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 3 – New instruction recap Tutorial.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Structure of a C program
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
State Machines Timing Computer Bus Computer Performance Instruction Set Architectures RISC / CISC Machines.
Butterfly I/O Ports CS-212 Dick Steflik. I/O for our labs To get data into and out of our Butterfly its a little trickier than using printf and scanf.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
Blackfin BF533 EZ-KIT Control The O in I/O
ARM Core Architecture. Common ARM Cortex Core In the case of ARM-based microcontrollers a company named ARM Holdings designs the core and licenses it.
Development. Development Environment Editor Assembler or compiler Embedded emulator/debugger IAR Embedded Workbench Kickstart Code Composer Essentials.
1 EKT 225 MICROCONTROLLER I CHAPTER 3 I/O PORT PROGRAMMING.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Programmer's view on Computer Architecture by Istvan Haller.
C Tokens Identifiers Keywords Constants Operators Special symbols.
The 8051 Microcontroller and Embedded Systems
ECS642U Embedded Systems Digital I/O William Marsh.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
V 1.01 Arrays and Pointers in C A pointer variable is a variable that contains the address of another variable. An array is a collection of like elements,
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory and Memory-Mapped I/O September 16, 2010.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Files A collection of related data treated as a unit. Two types Text
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
PRJ2: ESP2-UC workshop 1 Introductie 1.
History of C and basics of Programming
Displacement (Indexed) Stack
Format of Assembly language
Data types Data types Basic types
UNIT – Microcontroller.
ECE 3430 – Intro to Microcomputer Systems
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
Pointers and Pointer-Based Strings
C Short Overview Lembit Jürimägi.
William Stallings Computer Organization and Architecture 8th Edition
The Arduino Microcontroller: Atmel AVR Atmega 328
CENG2400 Revision Q1a A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module. Two on/off switches are connected to bit-3.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
ADDRESSING MODES AND INSTRUCTION SET
Baremetal C Programming for Embedded Systems
Govt. Polytechnic,Dhangar
Pointers and Pointer-Based Strings
Programming Language C Language.
C Language B. DHIVYA 17PCA140 II MCA.
Function of Operating Systems
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

ARM Embedded Programming Lecture 4 Accessing Memory Mapped Registers

Microcontroller Programming Paradigm 1.Decide what peripheral you want to use 2.Look in datasheet for the registers to enable and configure 3.Set bits in the registers to make peripheral behave the way you want 4. GOTO 1

Configuring PeripheralRegisters Writing and Reading Memory Mapped registers: in assembly it is easy e.g. LDR R1, =0x ; R1 <= memory address MOV R0, [ R1] ; value now loaded into R0 but in standard C ???

Task: How to Set the bit #23 in Peripheral Register at address 0x ? Would like to write something like const unsigned int MASK = 0x ; // 0b my_reg = my_reg | MASK; // Bitwise OR operation will set the required bit How to modify Memory Mapped Registers ?

Manipulating Memory Mapped Registers via Pointers 1.Define a pointer to the register address unsigned int * reg_addr = (*unsigned int) 0x ; 2. Set the MASK constant (1u << 23) // left shifting the constant 0x01 by 23 bits 3. OR the MASK with the current register value *reg_addr = (* reg_addr) | (1u << 23) ; // change stored value using // the indirection operator *

Using Macro #define to make code readable Use a text replacement macro #define. #define BIT23 (1u<<23) // replaces any occurrence of string BIT23 by string (1u<<23) // Hide the de-reference operator * and save yourself some typing: #define my_reg (*reg_addr); // expand the text “my_reg” to the text “(*reg_addr)”; my_reg = my_reg | BIT23; // set bit #23 can be also expressed in shorter form: my_reg | = BIT23; When using a mask in C we perform a read and modify operation

typedef keyword To make the code less error prone use the typedef keyword. It introduces a user defined type that is checked by the compiler: typedef unsigned int* reg_address_t ; /* User defined type pointer */ reg_address_t reg_addr = (reg_addr_t) 0x ; /* points at the memory address */ /* Text substitution macros save typing and make code readable */ #define my_reg (*reg_addr); /* this looks like a “variable” holding register value */ #define BIT_23 (1u <<23); /* constant representing the MASK */ /* The manipulation of register data is now easy to express */ my_reg ++; my_reg |= BIT_23;...

Storing values in MEMORY. The volatile qualifier indicates that the variable could be changed by external circumstances, such as user’s input switch. It instructs the compiler to store and update variable values in memory rather than from temporary storage (e.g. a CPU register). int volatile x = 0x67 ; // defines variable x that is stored in SRAM x = x + 0x03; // the result 0x6A will always be stored and updated in SRAM The inclusion of the volatile qualifier guards against the compiler performing code optimisation and storing the variable in an internal CPU register !!

Accessing Group of Memory Mapped Registers It is common for related Peripheral Registers have adjacent addresses. We can use the STRUCTURE data type to describe this group.

Example of a Port Pin Toggle typedef struct { unsigned int volatile MODER; // GPIO Mode Register unsigned int volatile OTYPER; // GPIO Output Type Register unsigned int volatile OSPEEDR; // GPIO Output Speed Register unsigned int volatile PUPDR; // GPIO Pull-up/Pull-down Register unsigned int volatile IDR; // GPIO Input Data Register unsigned int volatile ODR; // GPIO Output Data Register } GPIO_type; // Define a typical GPIO register group #define GPIOD_BASE (unsigned int) 0x // Value of Base Address of PORT D #define GPIOD (( GPIO_type*) GPIOD_BASE) // Pointer to Base Address of PORT D // Using the pointer GPIOD to the structure GPIO_type we can access its elements (registers) GPIOD->MODER = (1u << 26); // Set bit #26 (pin 13) to be general purpose output while (1) { my_delay (40 ms); // User written function returns after a delay of 40 ms GPIOD->ODR ^ = (1u << 13)); // Toggle output bit #13 using bit-wise XOR };