Real Time & Embedded Systems. STM32 GPIO and Timers

Similar documents
General Purpose Timers. Chapter 15

Digital Input and Output

Using the Special Function Registers of the Digital I/O interface of STM32

Using the Special Function Registers of the Digital I/O interface of STM32

ELEC 3040/3050 Lab Manual Lab 2 Revised 8/20/14. LAB 2: Developing and Debugging C Programs in MDK-ARM for the STM32L100RC Microcontroller

The following is copied from STM32L15xxx reference manual (RM0038). Timer Register Map

12.1 TIM1 introduction

Input/Output Programming

Developing and Debugging C Programs in MDK-ARM for the STM32L100RC Microcontroller

STM32F100RB processor GPIO notes rev 2

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

ECE 271 Microcomputer Architecture and Applications University of Maine

STM32 MICROCONTROLLER

EE 354 Fall 2018 Timers and timer interrupts

Introduction to Embedded Systems

ARM Cortex-M4 Architecture and Instruction Set 1: Architecture Overview

ELEC 3040/3050 Lab 6. Time-based interrupts (Digital stopwatch design)

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

Embedded assembly is more useful. Embedded assembly places an assembly function inside a C program and can be used with the ARM Cortex M0 processor.

ELC4438: Embedded System Design ARM Cortex-M Architecture II

Hello, and welcome to this presentation of the STM32 general-purpose IO interface. It covers the general-purpose input and output interface and how

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Final Exam Study Guide

ARM Microcontroller Course

Hello, and welcome to this presentation of the STM32 Touch Sensing Controller (TSC) which enables the designer to simply add touch sensing

Lab #4: GPIOs in Assembly Language Week of 18 February 2019

Unlocking the Potential of Your Microcontroller

ARM Cortex M3 & General Purpose Input/Output (GPIO)

Introduction to the MC9S12 Hardware Subsystems

ARM architecture road map. NuMicro Overview of Cortex M. Cortex M Processor Family (2/3) All binary upwards compatible

STG - STM32 + FreeRTOS + LwIP/EmWin

May 15, 2015 EE 354 Fall 2015 Lecture 6 Timers and timer interrupts

HC12 Built-In Hardware

EE4390 Microprocessors. Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System

TPMC x ADC, 16x/0x DAC and 8x Digital I/O. Version 1.0. User Manual. Issue May 2018

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

EE 308 Spring Lecture 28 March 30, 2012 Review for Exam 2. Introduction to the MC9S12 Expanded Mode

The ARM Cortex-M0 Processor Architecture Part-1

Education of Embedded Systems Programming in C and Assembly Based on ARM s Cortex-M Microprocessors

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

M2351 Security Architecture. TrustZone Technology for Armv8-M Architecture

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

(Embedded) Systems Programming Overview

ELEC 3040/3050 Lab 5. Matrix Keypad Interface Using Parallel I/O

AN3268 Application note

Clock Synchronous Control Module for Serial Flash Memory Access Firmware Integration Technology

QSB Command List. Document Version /15/2017

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

TPMC Channel Motion Control. User Manual. The Embedded I/O Company. Version 1.0. Issue 1.3 March 2003 D

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Embedded C. ECE Rick

Product Technical Brief S3C2412 Rev 2.2, Apr. 2006

AN065. AN065 Getting Started with the KXTJ3. Introduction

AMULET2e PRELIMINARY. 32-bit Integrated Asynchronous Microprocessor. Features. Introduction

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

Goals. Grading Rubrics (Total = 20 points) Pre-lab assignment

MICROPROCESSOR BASED SYSTEM DESIGN

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

Product Technical Brief S3C2413 Rev 2.2, Apr. 2006

Architecture of Computers and Parallel Systems Part 6: Microcomputers

COMP2121: Microprocessors and Interfacing

Chapter 2. Overview of Architecture and Microcontroller-Resources

Hello, and welcome to this presentation of the STM32L4 System Configuration Controller.

Hello, and welcome to this presentation of the STM32 Real- Time Clock. It covers the main features of this peripheral, which is used to provide a

Topic 3. ARM Cortex M3(i) Memory Management and Access. Department of Electronics Academic Year 14/15. (ver )

Developing Reusable Device Drivers for MCU's

STM32 Ecosystem workshop. T.O.M.A.S Team

USB-4303 Specifications

L2 - C language for Embedded MCUs

ARDUINO MEGA INTRODUCTION

LatticeMico32 GPIO. Version. Features

Course Introduction. 2009, Renesas Technology America, Inc., All Rights Reserved

AN5181. Building a thermometer using the STM8 Nucleo-64 boards. Application note. Introduction

UBC104 Embedded Systems. Review: Introduction to Microcontrollers

Systems Programming. Lecture 11 Timers

AN2585 Application note

Systems Programming. Lecture 4 Z16 Architecture and Programming

538 Lecture Notes Week 5

538 Lecture Notes Week 5

Arduino Uno R3 INTRODUCTION

TXZ Family Reference manual 32-bit Timer Event Counter (T32A-B)

A33 Nand Flash Controller Specification

Program SoC using C Language

EE 354 Fall 2015 Lecture 1 Architecture and Introduction

Table 1: Cross Reference of Applicable Products. INTERNAL PIC NUMBER Arm Cortex M0+ UT32M0R GPIO Module QS30

Interconnects, Memory, GPIO

Hello, and welcome to this presentation of the STM32F7 System Configuration Controller.

PC87435 Enhanced IPMI Baseboard Management Controller

EIE/ENE 334 Microprocessors

AN4666 Application note

Read section 8 of this document for detailed instructions on how to use this interface spec with LibUSB For OSX

Modern C++ for Embedded Systems

80C51 Block Diagram. CSE Overview 1

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

MCU: Interrupts and Timers. Ganesh Pitchiah

TPMC Channel SSI, Incremental Encoder, Counter. Version 1.0. User Manual. Issue January 2017

NuMicro Mini51 DE Series Product Brief

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

11 General-Purpose Timers

Education of Embedded Systems Programming in C and Assembly Based on ARM s Cortex-M Microprocessors

Transcription:

Real Time & Embedded Systems STM GPIO and Timers

GPIO

Memory Map of Cortex-M. GB xffffffff xe System NVIC, System Timer, SCB, vendor-specific memory GB External Device Such as SD card xa GB External RAM GB Off-chip memory for data. GB. GB x x Peripheral SRAM AHB & APB, such as timers, GPIO On-chip RAM, for heap, stack, & cod. GB x x Code On-chip Flash, for code & data One Byte (8 bits)

Memory Map of STML. GB xffffffff System xe GB External Device GB. GB. GB. GB xa x x x x External RAM Peripheral SRAM Code x x8 x8c x88 x8 x8 x GPIO D ( KB) GPIO C ( KB) GPIO B ( KB) GPIO A ( KB) One Byte (8 bits)

GPIO Memory Map x8 x8 x8 GPIO A ( KB) x8c x88 x8 x8 x8c x88 x8 x8 x8c x88 x8 x8 ASCR BRR AFR[] AFR[] LCKR BSRR ODR IDR PUPDR OSPEEDR OTYPER MODER 8 bytes Each register has bytes

GPIO Memory Map x8 Set pin A. to high x8 x8 GPIO A ( KB) x8c x88 x8 x8 x8c x88 x8 x8 x8c x88 x8 x8 ASCR BRR AFR[] AFR[] LCKR BSRR ODR IDR PUPDR OSPEEDR OTYPER MODER 8 bytes Set bit of ODR to high

Output Data Register (ODR) x87 x8 ODR word (i.e. bits) x87 x8 x8 x8 bytes Little Endian 9 8 7 9 8 7 9 8 7 7

Output Data Register (ODR) x87 x8 ODR word (i.e. bits) x87 x8 x8 x8 bytes Little Endian 9 8 7 9 8 7 9 8 7 *((uint_t *) x8) = UL<<; Dereferencing a pointer Bitwise OR 8

Dereferencing a Memory Address x8c x88 x8 x8 x8c x88 x8 x8 x8c x88 x8 x8 ASCR BRR AFR[] AFR[] LCKR BSRR ODR IDR PUPDR OSPEEDR OTYPER MODER typedef struct { volatile uint_t MODER; // Mode register volatile uint_t OTYPER; // Output type register volatile uint_t OSPEEDR; // Output speed register volatile uint_t PUPDR; // Pull-up/pull-down register volatile uint_t IDR; // Input data register volatile uint_t ODR; // Output data register volatile uint_t BSRR; // Bit set/reset register volatile uint_t LCKR; // Configuration lock register volatile uint_t AFR[]; // Alternate function registers volatile uint_t BRR; // Bit Reset register volatile uint_t ASCR; // Analog switch control register } GPIO_TypeDef; // Casting memory address to a pointer #define GPIOA ((GPIO_TypeDef *) x8) GPIOA->ODR = UL<<; 9

General Purpose Input/Output (GPIO) 8 GPIO Ports: A, B, C, D, E, F, G, H Up to pins in each port

Basic Structure of an I/O Port Bit Input and Output Schmitt trigger volts=.8v

GPIO Input: Pull Up and Pull Down A digital input can have three states: High, Low, and High-Impedance (also called floating, tri-stated, HiZ) Pull-Up If external input is HiZ, the input is read as a valid HIGH. Pull-Down If external input is HiZ, the input is read as a valid LOW.

Buttons / switches

I/O Debouncing Example signal when a button is pressed Voltage across push button... -. -......... Time (microseconds)

Noisy analog signals V in Threshold Analog signals Noisy Rise and fall slowly (small slew rate) A button press can generate a noisy transition for up to msec if not debounced in hardware

produce noisy digital signals V in Threshold Simple Comparator

Schmitt Trigger V out V in V out V TH V TL Immunity Band V TH V in V out V TL V in V DD Schmitt Trigger V out V TL V TH V in V DD Simple Comparator Trigger Low Trigger High 7

Basic Structure of an I/O Port Bit: Input bit= volts=.8v Schmitt trigger Input Data Register (IDR) GPIO Pull-up/Pull-down Register (PUPDR) = No pull-up, pull-down = Pull-up = Pull-down = Reserved 8

TIMERS 9

Timer Free-run counter (independent of processor) Functions Input capture Output compare Pulse-width modulation (PWM) generation One-pulse mode output STM has many application notes (on all aspects of the STM) App note AN77 General Purpose Timer Cookbook

Timer: Clock Reload Value ARR Reload f CL_PSC clock PSC Prescaler f CL_CNT Timer Counter ISR Interrupt ff CCCC_CCCCCC = ff CCCC_PPPPPP PPPPPP +

Timer: Output Reload Value ARR Reload f CL_PSC clock PSC Prescaler f CL_CNT Timer Counter ISR Interrupt = Timer Output (OCREF) Compare & Capture Register (CCR)

Timer: Input Capture Reload Value ARR Reload f CL_PSC clock PSC Prescaler f CL_CNT Timer Counter ISR Interrupt Trigger event (e.g. rising edge of external signal) Compare & Capture Register (CCR)

Multi-Channel Outputs

PWM Mode (Pulse Width Modulation) Period Period = T off + T on Mode Duty Cycle = TT oooo TT oooooo +TT oooo Mode Counter < Reference Counter Reference PWM mode (Low True) PWM mode (High True) Active Low Inactive Inactive Active High

Edge-aligned Mode (Up-counting) ARR =, RCR = clock counter Counter overflow Counter overflow Counter overflow Counter overflow Update event (UEV) Period = ( + ARR) * Clock Period = 7 * Clock Period ARR = Auto-Reload Register UEV = Update Event RCR = Repetition Count Register

Edge-aligned Mode (downcounting) ARR =, RCR = Clock Counter Counter underflow Counter underflow Counter underflow Counter underflow Update event (UEV) Period = ( + ARR) * Clock Period = 7 * Clock Period 7

Center-aligned Mode ARR =, RCR = Clock Counter Counter overflow Counter underflow Counter overflow Counter underflow Update event (UEV) Period = ( * ARR) * Clock Period = * Clock Period 8

PWM Mode (Low-True) Timer Output = High if counter < CCR Low if counter CCR Upcounting mode, ARR =, CCR =, RCR = Clock Counter CCR = OCREF CCR Duty Cycle = ARR + = 7 Period = ( + ARR) * Clock Period = 7 * Clock Period 9

PWM Mode (High-True) Timer Output = Low if counter < CCR High if counter CCR Upcounting mode, ARR =, CCR =, RCR = Clock Counter CCR = OCREF Duty Cycle = - = 7 CCR ARR + Period = ( + ARR) * Clock Period = 7 * Clock Period

PWM Mode (High-True) Timer Output = Low if counter < CCR High if counter CCR Upcounting mode, ARR =, CCR =, RCR = Clock Counter CCR = OCREF Duty Cycle = - = 7 CCR ARR + Period = ( + ARR) * Clock Period = 7 * Clock Period

PWM Mode (High-True) Timer Output = Low if counter < CCR High if counter CCR Center-aligned mode, ARR =, CCR =, RCR = Clock Counter CCR = OCREF Duty Cycle = - CCR ARR = Period = * ARR * Clock Period = * Clock Period

PWM Mode (High-True) Timer Output = Low if counter < CCR High if counter CCR Center-aligned mode, ARR =, CCR =, RCR = Clock Counter CCR = OCREF Duty Cycle = - CCR ARR = Period = * ARR * Clock Period = * Clock Period

Auto-Reload Register (ARR) Auto-Reload Preload Enable (ARPE) bit in TIMx_CR ARPE = (Synchronous Update) Write to ARR Read from ARR Preload Register Auto-reload Register (ARR) If UDIS bit in TIMx_CR is, UEV event is disabled. Triggered by Update Event (UEV) ARPE = (Asynchronous Update) Write to ARR Read from ARR Auto-reload Register (ARR)

Repetition Counter Register (RCR)

Repetition Counter Register (RCR)

Repetition Counter Register (RCR) 7

Repetition Counter Register (PCR) 8

Repetition Counter Register (PCR) 9

PWM Output Polarity Mode Counter < CCR Counter CCR PWM mode (Low True) PWM mode (High True) Active (Low) Inactive Inactive Active (High) Output Polarity: Software can program the CCxP bit in the TIMx_CCER register Active Inactive Active High High Voltage Low Voltage Active Low Low Voltage High Voltage

Up-Counting: Left Edge-aligned Upcounting mode, ARR =, CCR =, RCR = Clock Counter CCR = CCR = CCR = OCREF CCR = OCREF All rising edges occur at the same time! Left-aligned PWM Period

PWM Mode : Right Edge-aligned Upcounting mode, ARR =, CCR =, RCR = Clock Counter CCR = CCR = OCREF CCR = OCREF CCR = All falling edges occur at the same time! Right-aligned PWM Period

PWM Mode : Center Aligned Timer Output = Low if counter < CCR High if counter CCR Center-aligned mode, ARR =, CCR =, RCR = Clock Counter CCR = CCR = OCREF CCR = OCREF CCR = PWM signals are center aligned! Center-aligned PWM Period

The devil is in the detail Timer output control Enable Timer Output MOE: Main output enable OSSI: Off-state selection for Idle mode OSSR: Off-state selection for Run mode CCxE: Enable of capture/compare output for channel x CCxNE: Enable of capture/compare complementary output for channel x

Input Capture Monitor both rising and falling edge

Input Capture Monitor only rising edges or only falling edge

Input Capture 7

Input Capture Diagram 8

WHY IS THE MEASUREMENT OF TIME INTERESTING??? 9

Bats use echolocation to map their surroundings?

Ultrasonic Distance Sensor DDDDDDDDDDDDDDDD = RRRRRRRRRR TTTTTTTT TTTTTTTT SSSSSSSSSS oooo SSSSSSSSSS = RRRRRRRRRR TTTTTTTT TTTTTTTT µss mm/ss = RRRRRRRRRR TTTTTTTT TTTTTTTT µss 8

Ultrasonic Distance Sensor The delay from triggered chirp to echo response is the round-trip time t RT. Trigger a call t RT DDDDDDDDDDDDDDDD (cccc) = RRRRRRRRRR tttttttt tttttttt (μμμμ) 8-7 8 9 7 8 9 Echo response If t RT > is ms, no obstacle is detected.

Ultrasonic Distance Sensor