30
Getting started with STM32Nucleo Boards Mirko Falchetto February 27 th , 2017

Getting started with STM32Nucleo Boardsroveri.faculty.polimi.it/wp-content/uploads/STM32_Nucleo_mbed_ex.pdf · programming probe (ST-Link v2) Morpho ... How to address the Functional

  • Upload
    vukhanh

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

Getting started with

STM32Nucleo BoardsMirko Falchetto

February 27th 2017

Agenda 2

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

IoT Opportunities 3

Smart IndustrySmart Home and City Smart Me

bull Smart Manufacturing bull Sport

bull Wellness

bull Health care

bull Energy saving

bull Security

bull Comfort

ST blocks for IoT 4

Sensing Connectivity Power

SecurityAnalog MCU

bull Environmental

bull Motion

bull Microphones

bull Sub-GHz

bull BT BLE

bull Wifihellip

bull Wireless charging

bull Bat Chargers

bull Smart OnOff

bull Signal conditioning

bull Interfaces

bull Bio-sensing

bull Low-power

bull Sensor fusion

bull Authentication

bull Contactless payment

ST Augmenting the IoT Development 5

Hardware Bricks

Sense

Connect

Translate

Power

Process

Actuate

Cloud Services

Application Examples

Middleware Libraries

Board Support Package

Hardware Abstraction Layer

Various Dev Environment

Software Bricks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Agenda 2

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

IoT Opportunities 3

Smart IndustrySmart Home and City Smart Me

bull Smart Manufacturing bull Sport

bull Wellness

bull Health care

bull Energy saving

bull Security

bull Comfort

ST blocks for IoT 4

Sensing Connectivity Power

SecurityAnalog MCU

bull Environmental

bull Motion

bull Microphones

bull Sub-GHz

bull BT BLE

bull Wifihellip

bull Wireless charging

bull Bat Chargers

bull Smart OnOff

bull Signal conditioning

bull Interfaces

bull Bio-sensing

bull Low-power

bull Sensor fusion

bull Authentication

bull Contactless payment

ST Augmenting the IoT Development 5

Hardware Bricks

Sense

Connect

Translate

Power

Process

Actuate

Cloud Services

Application Examples

Middleware Libraries

Board Support Package

Hardware Abstraction Layer

Various Dev Environment

Software Bricks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

IoT Opportunities 3

Smart IndustrySmart Home and City Smart Me

bull Smart Manufacturing bull Sport

bull Wellness

bull Health care

bull Energy saving

bull Security

bull Comfort

ST blocks for IoT 4

Sensing Connectivity Power

SecurityAnalog MCU

bull Environmental

bull Motion

bull Microphones

bull Sub-GHz

bull BT BLE

bull Wifihellip

bull Wireless charging

bull Bat Chargers

bull Smart OnOff

bull Signal conditioning

bull Interfaces

bull Bio-sensing

bull Low-power

bull Sensor fusion

bull Authentication

bull Contactless payment

ST Augmenting the IoT Development 5

Hardware Bricks

Sense

Connect

Translate

Power

Process

Actuate

Cloud Services

Application Examples

Middleware Libraries

Board Support Package

Hardware Abstraction Layer

Various Dev Environment

Software Bricks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

ST blocks for IoT 4

Sensing Connectivity Power

SecurityAnalog MCU

bull Environmental

bull Motion

bull Microphones

bull Sub-GHz

bull BT BLE

bull Wifihellip

bull Wireless charging

bull Bat Chargers

bull Smart OnOff

bull Signal conditioning

bull Interfaces

bull Bio-sensing

bull Low-power

bull Sensor fusion

bull Authentication

bull Contactless payment

ST Augmenting the IoT Development 5

Hardware Bricks

Sense

Connect

Translate

Power

Process

Actuate

Cloud Services

Application Examples

Middleware Libraries

Board Support Package

Hardware Abstraction Layer

Various Dev Environment

Software Bricks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

ST Augmenting the IoT Development 5

Hardware Bricks

Sense

Connect

Translate

Power

Process

Actuate

Cloud Services

Application Examples

Middleware Libraries

Board Support Package

Hardware Abstraction Layer

Various Dev Environment

Software Bricks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Agenda 6

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

bull Based on STrsquos 32-bit ARM

Cortex-M based STM32

microprocessors

bull A Boards with 1 MCU and

hardware to programdebug

bull Two connectors to connect to

companion chips boards

bull For all STM32 families

bull gt60K Boards sold

STM32 Nucleo Development Board 7

Arduino UNO extension

connectors easy access to add-

ons ()

Integrated Debugging and

programming probe (ST-Link v2)

Morpho extension headers

Direct access to all STM32 IOs

STM32 Microcontroller

Flexible board power supply

through USB or external source

() thanks to the electrical compatibility it can be used as a shield for Arduino UNO R3 or similar

complete product range

from ultra-low power to high-performance

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

9

Nucleo Expansion Boards leverage ST

Breadth and Depth Product Portfolio

Microcontroller

Secure MCU

MemoryRF Connectivity

Analog amp

Mixed Signal ICs

MEMS amp SensorsPower Discrete

amp Modules

Industrial

Analog ASSP

Power Conversion

Automotive

Imaging

Digital Consumer

amp ASICs

A unique portfolio with all the key

technologies and products

Increasing semiconductor content per

application

Move

Power Interact

Connect

Sense

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

STM32 Nucleo Expansion Boards

How to address the Functional Needs10

What do you want to do What you need Board

Process Ultra Low power STM32 L0

Ultra Low power STM32 L1

Mainstream STM32 F1

Mixed signal +DSP STM32 F3

High performance STM32 F2

High performance + DSP STM32 F4 ndash (F7 Planned)

Sense

motion pressure humidity light gas location

Motion Sensors Motion + Environmental

Environmental Sensors Motion + Environmental

Proximity Sensors FlightSense

OpAmp OpAmp

Connect

wireless or wired

Bluetooth Low Energy BlueNRG

Wi-Fi

Sub-GHz radio SPIRIT1

NFC M24SR

Translate Motor Driver xSPIN (easySPIN dSPIN)

MoveActivate Audio amplifier Audio-Out

Audio Microphone Audio-in

Power Energy management amp Battery Energy management

(EnFILM)

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Move

ActuatePower

TranslateConnect

Sense

Boards with additional functionality that can be plugged on top of the STM32 Nucleo development

board directly or stacked on another expansion board

11

DIL24 support for

new devices

Example X-NUCLEO-IKS01A2

LSM303AGR LSM6DSL

LPS22HB HTS221

Motion MEMS sensors

Environmental sensors

wwwstcomx-nucleo

STM32 Nucleo Expansion Boards

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

13

Order Code () Description Key products

Sense

Motion and

environment

sensors

X-NUCLEO-IKS01A1Motion MEMS amp environmental sensors

LIS3MDL LSM6DS0 HTS221

LPS25HB

X-NUCLEO-IKS01A2LSM303AGR LSM6DSL HTS221

LPS22HB

Proximity

sensors

X-NUCLEO-6180XA1Proximity gesture and ambient light sensor

expansion boardVL6180X

X-NUCLEO-53L0A1 Ranging and gesture sensor expansion board VL53L0X

Microphone X-NUCLEO-CCA02M1 Digital MEMS microphone expansion board MP34DT01-M STPS160A

ESDA7P60-1U1M USBLC6-2SC6

Connect

Bluetooth low

energy 41

X-NUCLEO-IDB04A1Bluetooth Low Energy module expansion board

SPBTLE-RF M95640-R

X-NUCLEO-IDB05A1 SPBTLE-RF M95640-R

Wi-Fi X-NUCLEO-IDW01M1 Wi-Fi expansion board SPWF01SA11 STLQ50C25R

Sub-GHz radioX-NUCLEO-IDS01A4 868 MHz RF expansion board SPSGRF-868 M95640-R

X-NUCLEO-IDS01A5 915 MHz RF expansion board SPSGRF-915 M95640-R

NFC

X-NUCLEO-NFC01A1Dynamic NFC Tag expansion board

M24SR

X-NUCLEO-NFC02A1 M24LR

X-NUCLEO-NFC03A1 NFC card reader expansion board CR95HF

Power

drive

Battery and

energy

management

X-NUCLEO-IPS02A1 24V Intelligent power switch expansion board VPS2535H

LED lighting X-NUCLEO-LED61A1 DC-DC LED driver expansion board

LED6001 STL3N10F7 STL8N10LF3

STPS2L60A BAS70KFILM ESDAULC5-

1BF4 SMM4F33A-TR

STM32 Nucleo Expansion Board Portfolio

() Refer to wwwstcom for STM32 Nucleo and X-CUBE related

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Key Product on board

LSM6DS0 MEMS 3D accelerometer (plusmn2plusmn4plusmn8 g) + 3D

gyroscope (plusmn245plusmn500plusmn2000 dps)

LIS3MDL MEMS 3D magnetometer (plusmn4 plusmn8 plusmn12 16

gauss)

LPS25H(B) MEMS pressure sensor 260-1260 hPa

absolute digital output barometer

HTS221 capacitive digital relative humidity and

temperature

DIL 24-pin socket available for additional MEMS adapters

and other sensors (UV index)

DIL 24-pin

MEMS and environmental sensors expansion boardHardware Overview (12) 15

Hardware Description

bull The X-NUCLEO-IKS01A1 is a MEMS motion and

environmental sensor evaluation board system

bull It is compatible with the Arduino UNO R3 connector

layout and is designed around STrsquos latest sensors

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

Arduino UNO R3 connector

ST Morpho connector

Connector for the STM32 Nucleo Board

HTS221

LPS25H

LSM6DS0

LIS3MDL

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

MEMS and environmental sensors expansion board

Hardware Overview (22) 16

Key Features

bull The X-NUCLEO-IKS01A1 is a MEMS inertial and

environmental sensor evaluation board system

bull All sensor sensors are connected on a single I2C bus

bull Sensor Isup2C address selection

bull Each sensor has separate power supply lines

allowing power consumption measurement

bull Sensor disconnection (disconnect the Isup2C bus as well

as the power supply)

bull Interrupt and DRDY signals from sensors

bull DIL24 socket (Compatible to STEVAL-MKIV

MEMS adapter boards)

Order Code X-NUCLEO-IKS01A1

Unit Price (US$) 155() Suggested Resale Price per unit (USD) for BUDGETARY USE ONLY

is used as a wildcard character for related part number

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Agenda 17

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

18STM32 ARM mbed

bull ST Support of ARM mbed

bull ARM mbed (wwwmbedcom) is a platform developed by ARM to support

easy and quick development of applications on Cortex M-series based

microcontrollers

bull Two main categories

bull Platforms ST Nucleo boards

bull Components ST Expansion boards (19)

bull Online compiler for easy-to-use

development and fast prototyping

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

mbed20 expansion boards19

X-NUCLEO-IKS01A1MOTION MEMS AND

ENVIRONMENTAL

SENSORS

X-NUCLEO-IDB04A1BLUETOOTH LOW ENERGY

X-NUCLEO-IDB05A1BLUETOOTH LOW ENERGY

X-NUCLEO-6180XA1PROXIMITY AND AMBIENT

LIGHT SENSOR

X-NUCLEO-IHM01A1STEPPER MOTOR DRIVER

X-NUCLEO-IHM02A1 TWO AXIS STEPPER MOTOR

DRIVER

X-NUCLEO-NFC01A1DYNAMIC NFC TAG

X-NUCLEO-LED61A1LED DRIVER X-NUCLEO-PLC01A1

PROGRAMMABLE LOGIC

CONTROLLER

X-NUCLEO-IHM03A1HIGH POWER STEPPER

MOTOR DRIVER

X-NUCLEO-IKA01A1MULTIFUNCTIONAL EXPANSION

BOARD BASED ON

OPERATIONAL AMPLIFIERS

X-NUCLEO-IHM05A1 BIPOLAR STEPPER MOTOR

DRIVER

X-NUCLEO-IHM04A1DUAL BRUSH DC MOTOR

DRIVER

Sensors and analog Wireless communication Motor drive

Others

IoT

X-NUCLEO-IDW01M1Wi-Fi EXPANSION BOARD

X-NUCLEO-IHM06A1 LOW VOLTAGE STEPPER

MOTOR DRIVER

X-NUCLEO-IPS02A1INTELLIGENT POWER SWITCH

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

httpsdevelopermbedorg 20

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

mbed for developers 21

bull Go to wwwmbedcom rarr rarr developermbedorg

bull Log InSignup

bull Hardware rarr Boards rarr STMicroelectronics rarr NUCLEO-F401RE

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

STMicroelectronics platforms 22

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

mbed page for STM32Nucleo F401 23

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Something to install ndash PC drivers 24

ST-LinkV2-1

driver

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

After PC driver installation

bull connect NUCLEO board to PC via

USB

bull drag-and-drop binary file on virtual

storage device to program the

board

25

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

Agenda 27

Introduction to the STM32 Nucleo Boards

A Primer Board Setup amp Demo Examples on MBED

1

2

3

Introduction to the MBED Development Environment

The IoT Opportunities0

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

ldquoGood Designrdquo

on Programming Embedded Devicesbull Dont optimize your code till you know you really need to

bull Donrsquot think you are smarter than the compiler

bull When you program without wasting any resources do you consider

your time a resource

bull Write your code so its reliable readable and maintainable first

bull Use a KISS Methodology and avoid code duplications at all costs

bull US Navy 1960 ldquoKeep it simple amp stupidrdquo -gt ldquoKeep it small amp simplerdquo

bull Define simple clear orthogonal APIrsquos and keep under the carpet the garbage

bull Donrsquot verbosely comment your code

bull If you comment every single line of code probably yoursquore code is not that clear and

not that good designed

bull Use C Language in a C++ way (OO Programming)

bull be ready to use (few) global variables but encapsulate them wherever possible

bull Abstract datatypes and use preprocessor macros to improve code readability

28

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

ldquoThings to considerrdquo

on Programming Embedded Devicesbull (On errors) Embedded systems usually will stop to work in

unexpected ways not just make it go slow

bull Stack ndash usually stack size is small Stack problems cause some of the most

insidious defects

bull Heap ndash usually smaller heap sizes avoid unwarranted memory allocation

Fragmentation quickly becomes an issue

bull When malloc or new [] returns NULL do you check for it and what do you do

Most MCU embedded systems do not use dynamic memory for these reasons

bull Hardware interrupts - handle these in a safe and timely manner

bull Use only safe re-entrant code on your interrupt routines (no STD C lib printf etc)

bull Assembly Language - almost always source of premature optimization

bull As an exercise write a small method in hand crafted assembly (from scratch)

bull Do the same in C Measure the performance

bull I bet the C will be faster And I know it will be more readable maintainable and

extendable

bull But In case be prepared to inspect assembly code generated by the compiler if

really needed

29

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

30

New rarr New Programhellip

Connect your NUCLEO-F401RE to your PC via USB

Save Ashellip

1st mbed Program Led Blinking

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

31

Change the frequency of blinking

bull Practice 1

bull Practice 2

Change the frequency of blinking using a timer (ie a ticker)

1st mbed Program Led Blinking

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

bull Plug the 2 boards

bull Go to mbedorg and selectbull Components Sensors Motion X-NUCLEO-IKS01A1

bull Import the program HelloWorld_IKS01A1 into your mbed online compiler

bull Do not check ldquoUpdate this program and libraries to the latest revisionrdquo

bull Compile the program and flash it on the NUCLEO board

35

1

2

X-NUCLEO-IKS01A1

+

NUCLEO-F401RE

Activity 2 NUCLEO + MEMS

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

36

3

4

bull Install a Serial Terminal on your PCbull Tera Term on Windows

bull httptera-termenlo4dcom

bull minicom on Linuxbull httpfossiesorglinuxmiscminicom-27targz

bull CoolTerm on OS bull httpswwwmacupdatecomappmac31352cooltermdownload

bull Plug the board run the terminal and open a connectionbull COMx port in Windows

bull ttyACMx in Linux

bull usbmodemxxxx in OS X

bull Setup

bull Reset the board to start displaying values on the screen

bull Serial portbull Baud rate 9600

bull Data 8 bit

bull Parity none

bull Stop 1 bit

bull Flow control none

bull Terminalbull Receive New Line AUTO

5

6

Activity 2 NUCLEO + MEMS

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks

42

Mirko Falchetto

Advanced System Technology

Embedded Analytics Research Platform

Sr SW System Engineer

ST Microelectronics Srl

20010 Cornaredo (MI) Italy

Via Tolomeo 1

Tel +39 02 93519 307

Fax +39 02 93519 376

mirkofalchettostcom

Questions

Thanks