Leanpub Header

Skip to main content

Mastering STM32 - Second Edition

A step-by-step guide to the most complete ARM Cortex-M platform, using the official STM32Cube development environment

With more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.

Minimum price

$29.99

$35.99

You pay

$35.99

Author earns

$28.79
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
2,064
Readers
910
Pages
About

About

About the Book

This is the second edition of the most complete book about the STM32 family of 32‑bit Flash microcontrollers from ST Microelectronics based on the ARM® Cortex®‑M architecture. The book will guide you in a clear and practical way to this hardware platform and the official ST CubeHAL and STM32CubeIDE, showing its functionalities with a lot of examples and tutorials. The book assumes that you are totally new to this family of MCUs, and it will start showing how to setup the tool-chain to build your STM32 based applications.

The book is addressed both to professionals and to fans of this platform, like hobbyists and students. The book examples are based on nine Nucleo-64 boards from ST.

This second edition is composed by twenty-eight chapters, divided in about 900 pages. They cover:

  • Introduction to Cortex-M and STM32 microcontrollers.
  • How to setup the STM32CubeIDE tool-chain in Windows, Linux and Mac OSX.
  • How to use STM32CubeMX to generate application skeleton.
  • Introduction to the debugging of STM32 applications.
  • GPIO management.
  • NVIC controller.
  • UART peripheral.
  • DMA controller.
  • STM32 clock tree and its configuration.
  • Basic, general purpose and advanced STM32 timers.
  • ADC peripheral.
  • DAC controller.
  • I2C bus and protocol.
  • SPI bus.
  • CRC peripheral.
  • IWDG and WWDG timers.
  • RTC clock.
  • Power management.
  • The memory layout of an STM32 application and linker scripts.
  • Flash memory management and the role of the ART Accelerator.
  • The booting process in STM32 microcontrollers and how to write a custom bootloader.
  • FreeRTOS 10.x and the tickless low-power mode.
  • Advanced debugging techniques and how to use SEGGER tools to debug STM32 MCUs.
  • FatFs Middleware.
  • How to develop IoT applications with the W5500 Ethernet processor.
  • USB 2.0 protocol and the STM32 USB Device Framework.
  • How to design a custom board using an STM32 MCU.

The complete Table of Contents can be downloaded from here.

You can reach the author through the book website: http://www.carminenoviello.com/en/mastering-stm32/

The LeanPub platform works so that, once you buy the book, you receive all updates for free.

Author

About the Author

Carmine Noviello

Carmine is a hardware designer and firmware developer living in south of Italy, close to the wonderful Naples. He spends the most of his time as team leader and BU Director in Bit4id, an Italian company leader in authentication, digital signature and cryptography. As soon manages to find some free time, he likes to treat programming topics on his personal blog. 

As you can see, he does not like to talk about himself :-)

Website: http://www.carminenoviello.com

Contents

Table of Contents

Preface

  1. Who Is This Book For?
  2. What About Arduino?
  3. How to Integrate This Book?
  4. How Is the Book Organized?
  5. Differences With the First Edition
  6. About the Author
  7. Errata and Suggestions
  8. Book Support
  9. How to Help the Author
  10. Copyright Disclaimer
  11. Credits

Acknowledgments to the First Edition

  1. IIntroduction

1.Introduction to STM32 MCU Portfolio

  1. 1.1Introduction to ARM Based Processors
  2. 1.1.1Cortex and Cortex-M Based Processors
  3. 1.1.1.1Core Registers
  4. 1.1.1.2Memory Map
  5. 1.1.1.3Bit-Banding
  6. 1.1.1.4Thumb-2 and Memory Alignment
  7. 1.1.1.5Pipeline
  8. 1.1.1.6Interrupts and Exceptions Handling
  9. 1.1.1.7SysTimer
  10. 1.1.1.8Power Modes
  11. 1.1.1.9TrustZone™
  12. 1.1.1.10CMSIS
  13. 1.1.1.11Effective Implementation of Cortex-M Features in the STM32 Portfolio
  14. 1.2Introduction to STM32 Microcontrollers
  15. 1.2.1Advantages of the STM32 Portfolio….
  16. 1.2.2….And Its Drawbacks
  17. 1.3A Quick Look at the STM32 Subfamilies
  18. 1.3.1F0
  19. 1.3.2F1
  20. 1.3.3F2
  21. 1.3.4F3
  22. 1.3.5F4
  23. 1.3.6F7
  24. 1.3.7H7
  25. 1.3.8L0
  26. 1.3.9L1
  27. 1.3.10L4
  28. 1.3.11L4+
  29. 1.3.12L5
  30. 1.3.13U5
  31. 1.3.14G0
  32. 1.3.15G4
  33. 1.3.16STM32WB
  34. 1.3.17STM32WL
  35. 1.3.18How to Select the Right MCU for You?
  36. 1.4The Nucleo Development Board
  37. Why Use the Nucleo as Example Board for This Book?

2.Get In Touch With SM32CubeIDE

  1. 2.1Why Choose STM32CubeIDE as Tool-Chain for STM32
  2. 2.1.1Two Words About Eclipse…
  3. 2.1.2… and GCC
  4. What Is a Cross-Compiler?
  5. 2.2Downloading and Installing the STM32CubeIDE
  6. 2.2.1Windows - Installing the Tool-Chain
  7. 2.2.2Linux - Installing the Tool-Chain
  8. 2.2.3Mac - Installing the Tool-Chain
  9. Read Carefully!
  10. 2.3STM32CubeIDE overview

3.Hello, Nucleo!

  1. 3.1Create a Project
  2. 3.2Adding Something Useful to the Generated Code
  3. 3.3Connecting the Nucleo to the PC
  4. Read Carefully
  5. 3.3.1ST-LINK Firmware Upgrade
  6. Warning
  7. Error in upgrading the ST-LINK firmware
  8. 3.4Flashing the Nucleo using STM32CubeProgrammer
  9. Read Carefully
  10. Eclipse intermezzo

4.STM32CubeMX Tool

  1. 4.1Introduction to CubeMX Tool
  2. 4.1.1Target Selection Wizard
  3. 4.1.1.1MCU/MPU Selector
  4. 4.1.1.2Board Selector
  5. 4.1.1.3Example Selector
  6. 4.1.1.4Cross Selector
  7. 4.1.2MCU and Middleware Configuration
  8. 4.1.2.1Pinout View & Configuration
  9. 4.1.2.2Clock Configuration View
  10. Overclocking
  11. 4.1.3Project Manager
  12. What is the Cube Low-Layer API?
  13. 4.1.4Tools View
  14. 4.2Understanding Project Structure
  15. Peripheral Initialization and Deinitialization
  16. 4.3Downloading Book Source Code Examples
  17. 4.4Management of STM32Cube Packages

5.Introduction to Debugging

  1. 5.1What is Behind a Debug Session
  2. 5.2Debugging With STM32CubeIDE
  3. 5.2.1Views in the Debug Perspective
  4. 5.2.2Debug Configurations
  5. 5.3I/O Retargeting
  6. printf() and float datatypes.
  7. IIDiving into the HAL

6.GPIO Management

  1. 6.1STM32 Peripherals Mapping and HAL Handlers
  2. 6.2GPIOs Configuration
  3. 6.2.1GPIO Mode
  4. 6.2.2GPIO Alternate Function
  5. 6.3Driving a GPIO
  6. 6.4De-initialize a GPIO
  7. Eclipse Intermezzo

7.Interrupts Management

  1. 7.1NVIC Controller
  2. 7.1.1Vector Table in STM32
  3. 7.2Enabling Interrupts
  4. 7.2.1External Lines and NVIC
  5. 7.2.2Enabling Interrupts with CubeMX
  6. What Belongs to What
  7. 7.3Interrupt Lifecycle
  8. 7.4Interrupt Priority Levels
  9. 7.4.1Cortex-M0/0+
  10. 7.4.2Cortex-M3/4/7/33
  11. 7.4.3Setting Interrupt Priority in CubeMX
  12. 7.5Interrupt Re-Entrancy
  13. 7.6Mask All Interrupts at Once or an a Priority Basis
  14. Eclipse Intermezzo

8.Universal Asynchronous Serial Communications

  1. 8.1Introduction to UARTs and USARTs
  2. 8.2UART Initialization
  3. Is It Mandatory to Define This Function?
  4. 8.2.1UART Configuration Using CubeMX
  5. 8.3UART Communication in Polling Mode
  6. Read Carefully
  7. 8.3.1Installing a Terminal Emulator in Eclipse
  8. 8.4UART Communication in Interrupt Mode
  9. 8.4.1UART Related Interrupts
  10. 8.5Error Management
  11. 8.6List of Available Callbacks in the HAL_UART Module
  12. Differences Between HAL_PPP and HAL_PPPEx Modules

9.DMA Management

  1. 9.1Introduction to DMA
  2. 9.1.1The Importance of DMA and the Role of Internal Buses
  3. 9.1.2The DMA Controller
  4. 9.1.2.1The DMA Implementation in F0/F1/F3/L0/L1/L4 MCUs
  5. 9.1.2.2The DMA Implementation in F2/F4/F7 MCUs
  6. 9.1.2.3The DMA Implementation in G0/G4/L4+/L5/H7 MCUs
  7. 9.2HAL_DMA Module
  8. 9.2.1DMA_HandleTypeDef in F0/F1/F3/L0/L1/L4 HALs
  9. 9.2.2Detailed Fields of DMA_InitTypeDef
  10. 9.2.3DMA Configuration in G0/G4/L4+/L5/H7 HALs
  11. 9.2.4DMA_HandleTypeDef in F2/F4/F7 HALs
  12. 9.2.5How to Perform DMA Transfers in Polling Mode
  13. 9.2.6How to Perform DMA Transfers in Interrupt Mode
  14. 9.2.7Using the HAL_UART Module with DMA Mode Transfers
  15. 9.2.8Programming the DMAMUX with the CubeHAL
  16. 9.2.9Miscellaneous Functions From HAL_DMA and HAL_DMA_Ex Modules
  17. 9.3Using CubeMX to Configure DMA Requests
  18. 9.4Correct Memory Allocation of DMA Buffers
  19. 9.5A Case Study: The DMA Memory-to-Memory Transfer Performance Analysis

10.Clock Tree

  1. 10.1Clock Distribution
  2. 10.1.1Overview of the STM32 Clock Tree
  3. Why So Many Intermediate PLL/Prescaler Stages?
  4. 10.1.1.1The Multispeed Internal RC Oscillator in STM32L/U Families
  5. 10.1.2Configuring Clock Tree Using CubeMX
  6. 10.1.3Clock Source Options in Nucleo Boards
  7. 10.1.3.1Clock Source in Nucleo-64 rev. MB1136 (older ones with ST-LINK V2.1)
  8. 10.1.3.1.1OSC Clock Supply
  9. Read Carefully
  10. 10.1.3.1.2OSC 32kHz Clock Supply
  11. Read Carefully
  12. 10.1.3.2Clock Source in Nucleo-64 rev. MB1367 (newer ones with ST-LINK v3)
  13. 10.1.3.2.1OSC Clock Supply
  14. 10.1.3.2.2OSC 32kHz Clock Supply
  15. 10.2Overview of the HAL_RCC Module
  16. 10.2.1Compute the Clock Frequency at Run-Time
  17. Read Carefully
  18. 10.2.2Enabling the Master Clock Output
  19. Read Carefully
  20. 10.2.3Enabling the Clock Security System
  21. 10.3HSI Calibration

11.Timers

  1. 11.1Introduction to Timers
  2. 11.1.1Timer Categories in an STM32 MCU
  3. 11.1.2Effective Availability of Timers in the STM32 Portfolio
  4. 11.2Basic Timers
  5. 11.2.1Using Timers in Interrupt Mode
  6. The Performance of the HAL_TIM_IRQHandler() Routine
  7. How to Choose the Values for Prescaler and Period Fields?
  8. 11.2.1.1Time Base Generation in Advanced Timers
  9. 11.2.2Using Timers in Polling Mode
  10. 11.2.3Using Timers in DMA Mode
  11. Read Carefully
  12. 11.2.4Stopping a Timer
  13. 11.2.5Using CubeMX to Configure a Basic Timer
  14. 11.3General Purpose Timers
  15. 11.3.1Time Base Generator with External Clock Sources
  16. 11.3.1.1External Clock Mode 2
  17. Read Carefully
  18. 11.3.1.2External Clock Mode 1
  19. 11.3.1.3Using CubeMX to Configure the Source Clock of a General Purpose Timer
  20. 11.3.2Master/Slave Synchronization Modes
  21. 11.3.2.1Enable Trigger-Related Interrupts
  22. 11.3.2.2Using CubeMX to Configure the Master/Slave Synchronization
  23. 11.3.3Generate Timer-Related Events by Software
  24. 11.3.4Counting Modes
  25. 11.3.5Input Capture Mode
  26. 11.3.5.1Using CubeMX to Configure the Input Capture Mode
  27. 11.3.6Output Compare Mode
  28. 11.3.6.1Using CubeMX to Configure the Output Compare Mode
  29. 11.3.7Pulse-Width Generation
  30. 11.3.7.1Generating a Sinusoidal Wave Using PWM
  31. 11.3.7.2Using CubeMX to Configure the PWM Mode
  32. 11.3.8One Pulse Mode
  33. 11.3.8.1Using CubeMX to Configure the OPM Mode
  34. 11.3.9Encoder Mode
  35. 11.3.9.1Using CubeMX to Configure the Encoder Mode
  36. 11.3.10Other Features Available in General Purpose and Advanced Timers
  37. 11.3.10.1Hall Sensor Mode
  38. 11.3.10.2Combined Three-Phase PWM Mode and Other Motor-Control Related Features
  39. 11.3.10.3Break Input and Locking of Timer Registers
  40. 11.3.10.4Preloading of Auto-Reload Register
  41. 11.3.11Debugging and Timers
  42. 11.4SysTick Timer
  43. Read Carefully
  44. 11.4.1Use Another Timer as System Timebase Source
  45. 11.5A Case Study: How to Precisely Measure Microseconds with STM32 MCUs

12.Analog-To-Digital Conversion

  1. 12.1Introduction to SAR ADC
  2. 12.2HAL_ADC Module
  3. 12.2.1Conversion Modes
  4. 12.2.1.1Single-Channel, Single Conversion Mode
  5. 12.2.1.2Scan Single Conversion Mode
  6. 12.2.1.3Single-Channel, Continuous Conversion Mode
  7. 12.2.1.4Scan Continuous Conversion Mode
  8. 12.2.1.5Injected Conversion Mode
  9. 12.2.1.6Dual Modes
  10. 12.2.2Channel Selection
  11. The CubeHAL and its non-linear evolution
  12. 12.2.3ADC Resolution and Conversion Speed
  13. 12.2.4A/D Conversions in Polling Mode
  14. Read Carefully
  15. 12.2.5A/D Conversions in Interrupt Mode
  16. 12.2.6A/D Conversions in DMA Mode
  17. 12.2.6.1Convert Multiple Times the Same Channel in DMA Mode
  18. 12.2.6.2Multiple and not Continuous Conversions in DMA Mode
  19. 12.2.6.3Continuous Conversions in DMA Mode
  20. 12.2.7Errors Management
  21. 12.2.8Timer-Driven Conversions
  22. 12.2.9Conversions Driven by External Events
  23. 12.2.10ADC Calibration
  24. 12.3Using CubeMX to Configure ADC Peripheral

13.Digital-To-Analog Conversion

  1. 13.1Introduction to the DAC Peripheral
  2. 13.2HAL_DAC Module
  3. 13.2.1Driving the DAC Manually
  4. 13.2.2Driving the DAC in DMA Mode Using a Timer
  5. Read Carefully
  6. 13.2.3Triangular Wave Generation
  7. 13.2.4Noise Wave Generation

14.I²C

  1. 14.1Introduction to the I²C specification
  2. Read Carefully
  3. 14.1.1The I²C Protocol
  4. 14.1.1.1START and STOP Condition
  5. 14.1.1.2Byte Format
  6. 14.1.1.3Address Frame
  7. 14.1.1.4Acknowledge (ACK) and Not Acknowledge (NACK)
  8. 14.1.1.5Data Frames
  9. 14.1.1.6Combined Transactions
  10. 14.1.1.7Clock Stretching
  11. 14.1.2Availability of I²C Peripherals in STM32 MCUs
  12. 14.2HAL_I2C Module
  13. 14.2.1Using the I²C Peripheral in Master Mode
  14. Read Carefully
  15. 14.2.1.1I/O MEM Operations
  16. 14.2.1.2Combined Transactions
  17. 14.2.1.3A Note About the Clock Configuration in STM32F0/L0/L4 families
  18. 14.2.2Using the I²C Peripheral in Slave Mode
  19. 14.3Using CubeMX to Configure the I²C Peripheral
  20. Read Carefully

15.SPI

  1. 15.1Introduction to the SPI Specification
  2. 15.1.1Clock Polarity and Phase
  3. 15.1.2Slave Select Signal Management
  4. 15.1.3SPI TI Mode
  5. 15.1.4Availability of SPI Peripherals in STM32 MCUs
  6. 15.2HAL_SPI Module
  7. 15.2.1Exchanging Messages Using SPI Peripheral
  8. 15.2.2Maximum Transmission Frequency Reachable using the CubeHAL
  9. 15.3Using CubeMX to Configure SPI Peripheral

16.Cyclic Redundancy Check

  1. 16.1Introduction to CRC Computing
  2. 16.1.1CRC Calculation in STM32F1/F2/F4/L1 MCUs
  3. 16.1.2CRC Peripheral in STM32F0/F3/F7/L0/L4/L5/G0/G4 MCUs
  4. 16.2HAL_CRC Module

17.IWDG and WWDG Timers

  1. 17.1The Independent Watchdog Timer
  2. 17.1.1Using the CubeHAL to Program IWDG Timer
  3. 17.2The System Window Watchdog Timer
  4. 17.2.1Using the CubeHAL to Program WWDG Timer
  5. 17.3Detecting a System Reset Caused by a Watchdog Timer
  6. 17.4Freezing Watchdog Timers During a Debug Session
  7. 17.5Selecting the Right Watchdog Timer for Your Application

18.Real-Time Clock

  1. 18.1Introduction to the RTC Peripheral
  2. 18.2HAL_RTC Module
  3. 18.2.1Setting and Retrieving the Current Date/Time
  4. 18.2.1.1Correct Way to Read Date/Time Values
  5. 18.2.2Configuring Alarms
  6. 18.2.3Periodic Wakeup Unit
  7. 18.2.4Timestamp Generation and Tamper Detection
  8. 18.2.5RTC Calibration
  9. 18.2.5.1RTC Coarse Calibration
  10. 18.2.5.2RTC Smooth Calibration
  11. 18.2.5.3Reference Clock Detection
  12. 18.3Using the Backup SRAM
  13. IIIAdvanced topics

19.Power Management

  1. 19.1Power Management in Cortex-M Based MCUs
  2. 19.2How Cortex-M MCUs Handle Run and Sleep Modes
  3. 19.2.1Entering/exiting sleep modes
  4. 19.2.1.1Sleep-On-Exit
  5. 19.2.2Sleep Modes in Cortex-M Based MCUs
  6. 19.3Power Management in STM32F Microcontrollers
  7. 19.3.1Power Sources
  8. 19.3.2Power Modes
  9. 19.3.2.1Run Mode
  10. 19.3.2.1.1Dynamic Voltage Scaling in STM32F4/F7 MCUs
  11. 19.3.2.1.2Over/Under-Drive Mode in STM32F4/F7 MCUs
  12. 19.3.2.2Sleep Mode
  13. 19.3.2.3Stop Mode
  14. 19.3.2.4Standby Mode
  15. Read Carefully
  16. 19.3.2.5Low-Power Modes Example
  17. 19.3.3An Important Warning for STM32F1 Microcontrollers
  18. 19.4Power Management in STM32L/G Microcontrollers
  19. 19.4.1Power Sources
  20. 19.4.2Power Modes
  21. 19.4.2.1Run Modes
  22. 19.4.2.2Sleep Modes
  23. Read Carefully
  24. 19.4.2.2.1Batch Acquisition Mode
  25. 19.4.2.3Stop Modes
  26. 19.4.2.4Standby Modes
  27. 19.4.2.5Shutdown Mode
  28. 19.4.3Power Modes Transitions
  29. 19.4.4Low-Power Peripherals
  30. 19.4.4.1LPUART
  31. 19.4.4.2LPTIM
  32. 19.4.4.3LPGPIO
  33. 19.4.4.4LPDMA
  34. 19.5Power Supply Supervisors
  35. 19.6Debugging in Low-Power Modes
  36. 19.7Using the CubeMX Power Consumption Calculator
  37. 19.8A Case Study: Using Watchdog Timers With Low-Power Modes

20.Memory layout

  1. 20.1The STM32 Memory Layout Model
  2. 20.1.1Flash Memory Typical Organization
  3. 20.1.2SRAM Memory Typical Organization
  4. 20.1.3Understanding Compilation and Linking Processes
  5. 20.2The Really Minimal STM32 Application
  6. 20.2.1ELF Binary File Inspection
  7. STM32CubeIDE Build Analyzer
  8. 20.2.2.data and .bss Sections Initialization
  9. 20.2.2.1A Word About the COMMON Section
  10. 20.2.3.rodata Section
  11. Pointers to Const Data
  12. 20.2.4Stack and Heap Regions
  13. A Note About Linker Script Symbols
  14. 20.2.5Checking the Size of Heap and Stack at Compile-Time
  15. 20.2.6Differences With the Tool-Chain Script Files
  16. 20.3How to Use the CCM Memory
  17. Why Use CCM to Store Code Instead of Data?
  18. 20.3.1Relocating the vector table in CCM Memory
  19. 20.4How to Use the MPU in Cortex-M0+/3/4/7 Based STM32 MCUs
  20. 20.4.1Programming the MPU With the CubeHAL

21.Flash Memory Management

  1. 21.1Introduction to STM32 Flash Memory
  2. 21.2The HAL_FLASH Module
  3. 21.2.1Flash Memory Unlocking
  4. 21.2.2Flash Memory Erasing
  5. Read Carefully
  6. 21.2.3Flash Memory Programming
  7. 21.2.4Flash Read Access During Programming and Erasing
  8. 21.3Option Bytes
  9. 21.3.1Flash Memory Read Protection
  10. Read Carefully
  11. 21.4Optional OTP and True-EEPROM Memories
  12. 21.5Flash Read Latency and the ART™ Accelerator
  13. 21.5.1The Role of the TCM Memories in STM32F7/H7 MCUs
  14. 21.5.1.1How to Access Flash Memory Through the TCM Interface
  15. 21.5.1.2Using CubeMX to Configure Flash Memory Interface

22.Booting Process

  1. 22.1The Cortex-M Unified Memory Layout and the Booting Process
  2. 22.1.1Software Physical Remap
  3. 22.1.2Vector Table Relocation
  4. 22.1.3Running the Firmware From SRAM Using the STM32CubeIDE
  5. 22.2Integrated STM32 Bootloader
  6. 22.2.1Starting the STM32 Bootloader from the On-Board Firmware
  7. 22.2.2The Booting Sequence in the STM32CubeIDE Tool-chain
  8. 22.3Developing a Custom Bootloader
  9. Read Carefully
  10. Some Considerations on the Custom Bootloader
  11. 22.3.1Vector Table Relocation in STM32F0 Microcontrollers
  12. 22.3.2How to Use the flasher.py Tool

23.Running FreeRTOS

  1. 23.1Understanding the Concepts Underlying an RTOS
  2. 23.2Configuring FreeRTOS and the CMSIS-RTOS v2 Wrapper
  3. 23.2.1The FreeRTOS Source Tree
  4. 23.2.1.1How to Configure FreeRTOS Using CubeMX
  5. 23.3Thread Management
  6. Read Carefully
  7. Read Carefully
  8. 23.3.1Thread States
  9. 23.3.2Thread Priorities and Scheduling Policies
  10. 23.3.3Voluntary Release of the Control
  11. 23.3.4The idle Thread
  12. A Word About Concurrent Programming
  13. 23.4Memory Allocation and Management
  14. 23.4.1Dynamic Memory Allocation Model
  15. 23.4.1.1heap_1.c
  16. 23.4.1.2heap_2.c
  17. 23.4.1.3heap_3.c
  18. 23.4.1.4heap_4.c
  19. 23.4.1.5heap_5.c
  20. 23.4.1.6FreeRTOS Heap Definition
  21. 23.4.2Static Memory Allocation Model
  22. Read Carefully
  23. 23.4.2.1idle Thread Allocation with Static Memory Allocation Model
  24. 23.4.3FreeRTOS and the C stdlib
  25. 23.4.3.1How to Configure newlib to Handle Concurrency with FreeRTOS
  26. 23.4.3.2How to Use malloc() and malloc()-dependant newlib Functions With FreeRTOS
  27. Read Careflly
  28. 23.4.3.3STM32CubeMX Approach to Thread-Safety
  29. 23.4.4Memory Pools
  30. 23.4.5Stack Overflow Detection
  31. 23.5Synchronization Primitives
  32. 23.5.1Message Queues
  33. 23.5.2Semaphores
  34. 23.5.3Event and Thread Flags
  35. 23.6Resources Management and Mutual Exclusion
  36. 23.6.1Mutexes
  37. 23.6.1.1The Priority Inversion Problem
  38. 23.6.1.2Recursive Mutexes
  39. 23.6.2Critical Sections
  40. 23.6.3Interrupt Management With an RTOS
  41. 23.6.3.1FreeRTOS API and Interrupt Priorities
  42. 23.7Software Timers
  43. 23.7.1How FreeRTOS Manages Timers
  44. 23.8A Case Study: Low-Power Management With an RTOS
  45. 23.8.1The idle Thread Hook
  46. Which Sleep Instruction to Use?
  47. 23.8.2The Tickless Mode in FreeRTOS
  48. Why tick Count Accuracy Is So Relevant?
  49. 23.8.2.1A Schema for the tickless Mode
  50. Read Carefully
  51. Read Carefully
  52. 23.8.2.2A Custom tickless Mode Policy
  53. A Note About LPTIM Timers
  54. 23.9Debugging Features
  55. 23.9.1configASSERT() Macro
  56. 23.9.2Run-Time Statistics and Thread State Information
  57. 23.9.3FreeRTOS Debugging in STM32CubeIDE
  58. 23.9.4FreeRTOS Kernel-Aware Debugging in STM32CubeIDE
  59. 23.10Alternatives to FreeRTOS
  60. 23.10.1AzureRTOS
  61. 23.10.2ChibiOS
  62. 23.10.3Contiki OS
  63. 23.10.4OpenRTOS

24.Advanced Debugging Techniques

  1. 24.1Understanding Cortex-M Fault-Related Exceptions
  2. 24.1.1The Cortex-M Exception Entrance Sequence and the ARM Calling Convention
  3. 24.1.1.1How to Interpret the Content of the LR Register on Exception Entrance
  4. 24.1.2Fault Exceptions and Faults Analysis
  5. 24.1.2.1Memory Management Exception
  6. 24.1.2.2Bus Fault Exception
  7. 24.1.2.3Usage Fault Exception
  8. 24.1.2.4Hard Fault Exception
  9. 24.1.2.5Secure Fault Exception
  10. 24.1.2.6Enabling Optional Fault Handlers
  11. 24.1.2.7Fault Analysis in Cortex-M0/0+ Based Processors
  12. 24.2STM32CubeIDE Advanced Debugging Features
  13. 24.2.1Expressions and Live Expressions
  14. 24.2.1.1Memory Monitors
  15. 24.2.2Watchpoints
  16. 24.2.3Instruction Stepping Mode
  17. Read Carefully
  18. 24.2.4SFRs View
  19. 24.2.5Fault Analyzer
  20. 24.2.5.1Tracing Fault-Related Registers Without the IDE Support
  21. 24.2.6Build Analyzer
  22. 24.2.7Static Stack Analyzer
  23. 24.3Serial Wire Viewer Tracing
  24. Differences Between JTAG and SWD Interfaces
  25. 24.3.1Enabling SWV Debugging
  26. 24.3.2Configuring SWV
  27. 24.3.3SWV Views
  28. 24.3.3.1SWV Trace Log
  29. 24.3.3.2SWV Exception Trace Log
  30. 24.3.3.3SWV Data Trace
  31. 24.3.3.4SWV Data Trace Timeline Graph
  32. 24.3.3.5SWV ITM Data Console
  33. 24.3.3.6SWV Statistical Profiling
  34. 24.4Debugging Aids from the CubeHAL
  35. 24.5External Debuggers
  36. 24.6Debugging two Nucleo Boards Simultaneously
  37. 24.7ARM Semihosting
  38. 24.7.1Enable Semihosting on a Project
  39. Read Carefully
  40. 24.7.2Semihosting Drawbacks
  41. 24.7.3Understanding How Semihosting Works

25.FAT Filesystem

  1. 25.1Introduction to FatFs Library
  2. 25.1.1Adding FatFs Library in Your Projects
  3. 25.1.1.1The Generic Disk Interface API
  4. 25.1.1.2The Implementation of a Driver to Access SD Cards in SPI Mode
  5. 25.1.2Relevant FatFs Structures and Functions
  6. 25.1.2.1Mounting a Filesystem
  7. 25.1.2.2Opening a File
  8. 25.1.2.3Reading From/Writing into a File
  9. 25.1.2.4Creating and Opening a Directory
  10. 25.1.3How to Configure the FatFs Library

26.Develop IoT Applications

  1. 26.1Solutions Offered by STM to Develop IoT Applications
  2. 26.2The W5500 Ethernet Controller
  3. 26.2.1How to Use the W5500 Shield and the ioLibrary_Driver Module
  4. 26.2.1.1Configuring the SPI Interface
  5. 26.2.1.2Configuring the Socket Buffers and the Network Interface
  6. 26.2.2Socket APIs
  7. Read Carefully
  8. 26.2.2.1Handling Sockets in TCP Mode
  9. 26.2.2.2Handling Sockets in UDP Mode
  10. 26.2.3I/O Retargeting to a TCP/IP Socket
  11. 26.2.4Building up an HTTP Server
  12. 26.2.4.1A Web-Based Oscilloscope

27.Universal Serial Bus

  1. 27.1USB 2.0 Specification Overview
  2. 27.1.1The “Before-To-Die” Guide to USB
  3. 27.1.2USB Physical Architecture Overview
  4. 27.1.3USB Logical Architecture Overview
  5. 27.1.3.1Device States
  6. 27.1.3.2Communication Endpoints
  7. 27.1.4USB 2.0 Communication Protocol Overview
  8. 27.1.4.1Packet Types
  9. 27.1.4.2Transaction Types
  10. 27.1.4.2.1Control Transactions
  11. 27.1.4.2.2IN/OUT Transactions
  12. 27.1.4.3Device and Interface Descriptors
  13. 27.1.4.3.1Device Descriptors
  14. 27.1.4.3.2Configuration Descriptors
  15. 27.1.4.3.3Interface Descriptors
  16. 27.1.4.3.4Endpoint Descriptors
  17. 27.1.4.3.5String Descriptors
  18. 27.1.4.4USB Classes
  19. 27.2STM32 USB Device Library
  20. 27.2.1Understanding Generated Code
  21. 27.2.2USB Initialization Sequence
  22. 27.2.3USB Enumeration Sequence
  23. 27.2.4The USB CDC Class
  24. 27.2.4.1USB CDC Descriptors
  25. 27.2.4.2USB CDC Class Initialization
  26. 27.2.4.3USB CDC Class Operations
  27. 27.3Building Custom USB Devices
  28. 27.3.1The USB HID Class
  29. 27.3.1.1USB HID Descriptors
  30. 27.3.1.2Overview of the Report Descriptor
  31. 27.3.1.3USB HID Class-Specific Requests
  32. 27.3.2Building a Vendor-Specific USB HID Device
  33. Read Carefully
  34. 27.4Debugging USB Devices
  35. 27.4.1Software Sniffers and Analyzers
  36. 27.4.2USB Hardware Analyzers
  37. 27.5Optimizing the STM32 USB Device Library
  38. 27.6Going to the Market

28.Getting Started with a New Design

  1. 28.1Hardware Design
  2. 28.1.1PCB Layer Stack-Up
  3. 28.1.2MCU Package
  4. 28.1.3Decoupling of Power-Supply Pins
  5. 28.1.4Clocks
  6. 28.1.5Filtering of RESET Pin
  7. 28.1.6Debug Port
  8. Read Carefully
  9. 28.1.7Boot Mode
  10. 28.1.8Pay attention to “pin-to-pin” Compatibility…
  11. 28.1.9…And to Selecting the Right Peripherals
  12. 28.1.10The Role of CubeMX During the Board Design Stage
  13. Read Carefully
  14. 28.1.11Board Layout Strategies
  15. 28.2Software Design
  16. 28.2.1Generating the binary image for production
  17. Appendix

A. Miscellaneous HAL functions and STM32 features

  1. Force MCU reset from the firmware
  2. STM32 96-bit Unique CPU ID

B. Troubleshooting Guide

  1. STM32CubeIDE Issues
  2. Debugging Continuously Breaks at Every Instruction During a Debug Session
  3. The Step-by-Step Debugging is Really Slow
  4. The Firmware Works Only Under a Debug Session
  5. STM32 Related Issues
  6. The Microcontroller Does Not Boot Correctly
  7. It is Not Possible to Flash or to Debug the MCU

C. Nucleo pin-out

  1. Nucleo-G474RE
  2. Arduino compatible headers
  3. Morpho headers
  4. Nucleo-F446RE
  5. Arduino compatible headers
  6. Morpho headers
  7. Nucleo-F401RE
  8. Arduino compatible headers
  9. Morpho headers
  10. Nucleo-F303RE
  11. Arduino compatible headers
  12. Morpho headers
  13. Nucleo-F103RB
  14. Arduino compatible headers
  15. Morpho headers
  16. Nucleo-F072RB
  17. Arduino compatible headers
  18. Morpho headers
  19. Nucleo-L476RG
  20. Arduino compatible headers
  21. Morpho headers
  22. Nucleo-L152RE
  23. Arduino compatible headers
  24. Morpho headers
  25. Nucleo-L073R8
  26. Arduino compatible headers
  27. Morpho headers

D. Differences with the 1st edition

  1. Chapter 1
  2. Chapter 2
  3. Chapter 3 and 4
  4. Chapter 5
  5. Chapter 6
  6. Chapter 7
  7. Chapter 8
  8. Chapter 9
  9. Chapter 10
  10. Chapter 11
  11. Chapter 12-22
  12. Chapter 23
  13. Chapter 24
  14. Chapter 25-26
  15. Chapter 27
  16. Chapter 28

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub