Practical Exercise. STM32F4 Discovery. Alessandro Palla

Similar documents
Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

32-bit ARM Cortex-M0, Cortex-M3 and Cortex-M4F microcontrollers

EE445L Fall 2011 Quiz 2A Page 1 of 6

Designing with STM32F3x

Motor Control using NXP s LPC2900

Project Final Report: Directional Remote Control

ELCT 912: Advanced Embedded Systems

Hardware Platforms and Sensors

EIE/ENE 334 Microprocessors

Roland Kammerer. 13. October 2010

GDM1101: CMOS Single-Chip Bluetooth Integrated Radio/Baseband IC

ADVANCED EMBEDDED MONITORING SYSTEM FOR ELECTROMAGNETIC RADIATION

GUJARAT TECHNOLOGICAL UNIVERSITY

ZKit-51-RD2, 8051 Development Kit

RX23T inverter ref. kit

Application Note. The Direct Digital Synthesis Generator

VC7300-Series Product Brief

VORAGO Timer (TIM) subsystem application note

Revision History. Rev. No Issued Date Page Description Summary. V Initial Release

AN4062 Application note

Getting started with the STSW-FCU001 reference design firmware for mini drones

Training Schedule. Robotic System Design using Arduino Platform

STM32L100C6 STM32L100R8 STM32L100RB

STM32L151xC STM32L152xC

INTERFACING WITH INTERRUPTS AND SYNCHRONIZATION TECHNIQUES

Realization and characterization of a smart meter for smart grid application

AN4507 Application note

EXAMINATION PAPER EMBEDDED SYSTEMS 6EJ005 UNIVERSITY OF DERBY. School of Computing and Technology DATE: SUMMER 2003 TIME ALLOWED: 2 HOURS

Microcontroller: Timers, ADC

STELLARIS ERRATA. Stellaris LM3S8962 RevA2 Errata

RB01 Development Platform Hardware

STM32L100x6/8/B-A. Ultra-low-power 32-bit MCU ARM -based Cortex -M3, 128KB Flash, 16KB SRAM, 2KB EEPROM, LCD, USB, ADC, DAC.

Hello, and welcome to this presentation of the STM32 Digital Filter for Sigma-Delta modulators interface. The features of this interface, which

MAXREFDES73#: WEARABLE, GALVANIC SKIN RESPONSE SYSTEM

STM32L151xE STM32L152xE

Exercise 3: Sound volume robot

STM32F401xB STM32F401xC

EE445L Fall 2012 Final Version B Page 1 of 7

Low Power Microphone Acquisition and Processing for Always-on Applications Based on Microcontrollers

RF4432 wireless transceiver module

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

AN3252 Application note

Utilizing the Trigger Routing Unit for System Level Synchronization

STM32F302x6 STM32F302x8

Lab 1.2 Joystick Interface

Firmware plugin for STSW-ESC001V1 board with ST Motor Control FOC SDK

NuMicro Family M051 DN/DE Series Product Brief

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

STM32F318C8 STM32F318K8

STM32F401xD STM32F401xE

EE445L Spring 2017 Final Page 1 of 7

DATASHEET. Amicrosystems AMI-AD1224 HIGH PRECISION CURRENT-TO-DIGITAL CONVERSION MODULE PRODUCT DESCRIPTION FEATURES

CSCI1600 Lab 4: Sound

EITF40 Digital and Analogue Projects - GNSS Tracker 2.4

DAB+ Voice Break-In Solution

Power. EE 109 Unit 17 -Pulse Width Modulation. Duty Cycle. Output Devices

STM32L151xx STM32L152xx

EE445L Fall 2015 Final Version B Page 1 of 7

Lab 23 Microcomputer-Based Motor Controller

STM32F411xC STM32F411xE

µchameleon 2 User s Manual

High-speed and High-precision Motion Controller

SNIOT702 Specification. Version number:v 1.0.1

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Universal LCD driver for low multiplex rates. AEC Q100 grade 2 compliant for automotive applications.

In this lab, you ll build and program a meter that measures voltage, current, power, and energy at DC and AC.

STM32F405xx STM32F407xx

STM32L162VC STM32L162RC

MICROCONTROLLER TUTORIAL II TIMERS

Electric Bike BLDC Hub Motor Control Using the Z8FMC1600 MCU

MEASUREMENT of physical conditions in buildings

STM32 PMSM FOC SDK v3.2. 蒋建国 MCU Application Great China

JUMA-TRX2 DDS / Control Board description OH2NLT

AN5086 Application note

3.3V regulator. JA H-bridge. Doc: page 1 of 7

Scope AVDD VDDC NRST. reset clock test. CPU core 16 bit. multiply HALIOS. control. watchdog. digital/ analog IRQ. control. timer

AES Cambridge Seminar Series 27 October Audio Signal Processing and Rapid Prototyping with the ARM mbed. Dr Rob Toulson

Select the single most appropriate response for each question.

PRODUCT OVERVIEW OVERVIEW OTP

Wireless hands-free using nrf24e1

STM32L063C8 STM32L063R8

KV4x Family Product Brief Supports 150 MHz devices with 64 KB to 256 KB Flash

EE 308 Apr. 24, 2002 Review for Final Exam

Hello and welcome to this Renesas Interactive Course that provides an overview of the timers found on RL78 MCUs.

Debugging a Boundary-Scan I 2 C Script Test with the BusPro - I and I2C Exerciser Software: A Case Study

AN1730. Digital Amplification Control of an Analog Signal Using the MC68HC705J1A. Introduction

JTAG pins do not have internal pull-ups enabled at power-on reset. JTAG INTEST instruction does not work

STM32L010F4 STM32L010K4

Single Phase Two-Channel Interleaved PFC Operating in CrM Using the MC56F82xxx Family of Digital Signal Controllers

Implementation of Brushless DC motor speed control on STM32F407 Cortex M4

MTY (81)

UHF RFID Micro Reader Reference Design Hardware Description

Servo click. PID: MIKROE 3133 Weight: 32 g

Vector Network Analyzers. Paul Coverdale VE3ICV

STM32L100RC. Ultra-low-power 32b MCU ARM -based Cortex -M3, 256KB Flash, 16KB SRAM, 4KB EEPROM, LCD, USB, ADC, DAC, memory I/F.

NJU26040 Application Note

Digital controllers for lighting and power conversion applications with up to 6 programmable PWM generators, 96 MHz PLL, DALI

LoRa1278 Wireless Transceiver Module

Preliminary GHz Transceiver-µController-Module. Applications PRODUCT SPECIFICATION FEATURES MICROCONTROLLER MHz

Lab 5 Timer Module PWM ReadMeFirst

Transcription:

Practical Exercise STM32F4 Discovery Alessandro Palla alessandro.palla@for.unipi.it

Outline STM32F4 Discovery Application: USB Mouse with accelerometer Hardware Configuration o o o o o Requirements Peripherals Selections Timer GPIO SPI USB Board Pinout Clock Selection Peripheral Configuration

Outline Software Design o PWM LEDs control o Interrupt management o Accelerometer Theoretical Background LIS3DSH SPI communication o USB Put All together Conclusion

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone Audio DAC with class D amplifier

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone Audio DAC with class D amplifier USB FS (Full Speed) with micro-usb connector

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone Audio DAC with class D amplifier USB FS (Full Speed) with micro-usb connector 4 user led (green, blue red and orange)

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone Audio DAC with class D amplifier USB FS (Full Speed) with micro-usb connector 4 user led (green, blue red and orange) One user button and one reset

STM32Discovery F4 STM32F407x Cortex-M4F core, 1MB flash, 192KB RAM, frequency up to 168 MHz 3-axis accelerometer Omnidirectional MEMS Microphone Audio DAC with class D amplifier USB FS (Full Speed) with micro-usb connector 4 user led (green, blue red and orange) One user button and one reset Programmation via USB with ST Link (chip above)

System Architecture Single Button USB Mouse Controlled by tilts on y and x axes Latency = 10 ms o It means that CPU has to polls accelerometer each millisecond Visual feedback using pulsing led. o Pulse frequency = 10 Hz PC USB CPU LEDs SPI Push Button 3 Axis Accelero meter

How it Works Tilt is measured by projection of g (gravity acceleration vector) on x and y axes (A x, A y ) If A x, A y << A z ρ A x A x A z g ϕ A y A z A y g For low deviation acceleration of x and y axes are proportional to tilts

System flow If A x or A y is greater than a threshold, firmware update mouse cursor position Leds blink depending on tilts direction Wait 10ms No Initialization Read A x, A y A x > Th A y > Th Yes Update mouse position Start led feedback

STM32Cube MX Developing starting point GPIO configuration Peripherals selection Clock management Peripherals and middleware configuration Power Calculator Big number of library (USB Host and Device, TCP/IP Stack, SSL, FAT FileSystem, FreeRTOS operative system)

First Step: Debug and Clock RCC (Real-Time Clock Control), HSE (High speed clock) connected to 8 MHz Crystal STLink connected via SWD (Serial Wire Debug), a simplified JTAG

Clock Configuration

Clock Configuration Input Crystal Frequency: 8 MHz Crystal is more accurate than HSI (High Speed Internal oscillator), so is suggested to use it in order to improve performances. PLL (Phased Locked Loop) is an electronic system that can increase frequency of signals. In this case f out = f in N M P System Clock and HCLK (AHB Bus clock) are set to 168 MHz Each APB bus has a different clock speed: 42 MHz APB1, 84 MHz APB2 Indeed timer has greater frequency: 84 MHz APB1, 168 MHz APB2

Pulse Width Modulation Adjusting duty cycle of signal we can control it s average If digital signal s frequency is greater than system bandwidth, we can approximate output with signal mean Can be used also to generate a fixed duty cycle waveform

Pulse Width Modulation f PWM = f Timer COUNTER_MAX δ Duty Cycle = = 10 Hz OCR COUNTER MAX = 50% (square wave) All Timer4 channels are connected to LEDs Timer4 is connected to APB1 (84 MHz)

Serial Peripheral Interface Full Duplex synchronous serial data link MOSI: Master Out Slave IN MISO Master IN Slave Out

USB Asymmetric communication: one Host and multiple Devices (up to 127) USB can supply embedded devices: o Voltage supply: 5V o Current: up to 1A o Power up to 5W, enough for most embedded devices First version of standard (1996): USB 1.0, speed 1.5 Mbit/s USB 1.1 introduces USB FS (Full Speed), speed 12 Mbit/s USB 2.0 => USB HS (High Speed), theoretical speed of 480 Mbit/s STM32F4 o Can be Host, Device or OTG (on-the-go, can switch between Host and Device) o It supports both USB FS and HS,

STM32F4 Discovery USB Mini USB connector for power supply, debugging and programming CPU Micro USB connector for communication In our application: o USB Device, PC is the Host o We don t need high speed => USB FS

Discovery USB Schematic Power Switch for USB Host ESD protection and EMI Filtering for USB

USB HID Human Interface Device, a class of USB specification designed to interacts directly with humans A lot of devices can use this technology: o Mice o Keyboards o Game Controller o Custom Device (driver developing on host side) Also other standards have HID class, like Bluetooth (Bluetooth HID, for wireless mice and keyboards) Latency is more important than throughput in those devices. Devices communicate with Host send non-periodic reports (later )

Time Base Generation Timer6 has to generate an 10 ms period time base, and his clock frequency is 84 MHz. Problem n1: How can we generate 100Hz signal from 84MHz one? Timer can be configured to generate an interrupt on counter overflow. If it counts from 0 to CNT-1, time between 2 interrupts is t = CNT f clk CNT = 840000

Timer Block Diagram

Time Base Generation Problem n2: Timer6 is a 16 bit timer, and 840000 > 65535 (2 16 1) Solution: Clock Prescaler! t = CNT PSC f clk Prescaler is also a useful to decrease power consumption (remember dynamic power consumption: Pd = C f V 2 dd ) It also decrease resolution of counter: o Resolution without prescaler: Δt = 1 f clk o Resolution with prescaler: Δt = PSC f clk In STM32F4 register PSC reg = PSC 1

Software design flow Software Design o PWM LEDs control o Interrupt management o SPI LIS3DSH Register Map o USB HID Put All together Conclusion

Led Blinking Cube Software has already initialize selected peripherals, so user don t need to do it Two simple function to start/stop PWM: o HAL_TIM_PWM_Start o HAL_TIM_PWM_Stop Parameters: o TIM_HandleTypeDef* htim: a pointer to a Timer Structure, you can find it s declaration in tim.c o uint32_t Channel: a macro (defined in STM32F4xx_hal_tim.h) to select channel. TIM_Channel_x, where x goes from 1 to 4

Interrupt management HAL_TIM_Base_Start_IT(&htim6); starts Timer6 in interrupt mode. How we can personalize ISR (Interrupt Service Routine) in order to perform required task? Timer6 Counter Overflow Interrupt IRQ Handler Clear pending IRQ Call Timer ISR Timer ISR Check interrupt type Call Specific ISR defined as weak weak void ISR(){ }

ARM weak keyword A weak function can be redefined in another source code If linker find two function with the same name, it uses the one without weak keyword. It is useful to separate application from drivers main.c driver.c //user callback at application //level void callback(){ //do stuffs void ISR(){ //previous stuff callback(); } } //unused function weak void callback(){ Timer callback function is HAL_TIM_PeriodElapsedCallback }

Accelerometer background Measure: displacement of mobile mass change a capacitance of the two electrode V u = x V d 0 o V = Drive voltage o o x = Displacement d 0 = Rest distance between electrode Elastic element

Accelerometer in real world Simple 1-axis accelerometer in this example Capacitors

Accelerometer in real world Simple 1-axis accelerometer in this example Capacitors Spring

Accelerometer in real world Simple 1-axis accelerometer in this example Capacitors Spring Mobile Mass

Just a little bit more... Relation between displacement and acceleration F tot = ma = m x F tot = F β x kx = m x (F = ma) o F n = Force applied by acceleration o β = Viscous friction coefficient o k = Elastic coefficient Second order differential equation in x(t) Laplace! x s = F m s 2 + β m s+ k m If s << ω 0 x = F Hooke Law K Second order Low Pass filter o ω 0 = k m, Q = km β

Noise Strength components: F = ma + F n o a is the MEMS acceleration o F n is the force caused by Brownian mote of air, this is a noise source System Sensitivity: F n 4K B Tβ G 0 = 1 ω 0 2 We can report this noise to a noise acceleration dividing noise s displacement by sensitivity: 4K BT mq ω 0 a n = F n G K 0 1 = Great bandwidth increase input noise

Dynamic Range Dynamic Range: DR = 20 log( a FS a n ) Example: LIS3DSH 16 bit DR = 20 log 2 16 = 96.3 db If FS bit is set to 000, a FS = ±2 g = 4 g Input noise: a n = 4 g 216 0.061 mg

Our Application Requirements: ω 0 = 100 Hz, a FS = ±2 g Resolution 8 bit (USB HID) Derived Specifications: Anti-aliasing filter: f LP 50 Hz Truncation of 16 bit registers to 8 bit. We have to read only Most Significant Byte How to send and receive data from accelerometer?

SPI Communication Steps: Put CS low Send register address. MSB is 1 for read or 0 for write operation Receive/Send a byte Put High CS

HID Report HID USB Report Structure Defines structure of USB report and data fields Crazy to understand Standard descriptor (usually supported by Operative Systems) are provided by USB consortium. Bit 8 Bit 2 Bit 1 Bit 0 Byte 0 Unused Center Right Left Byte 1 Byte 2 Byte 3 X Axis Y Axis Unused

Send Report Very simple using ST USB Device Middleware if((hid_buffer[0]!= 0) (HID_Buffer[1]!= 0) (HID_Buffer[2]!= 0)){ USBD_HID_SendReport(&hUsbDeviceFS, HID_Buffer, 4); }