Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

STM32 Tutorial #65 – Optimized PWM BITBANG

711 views on YouTube

In this Tutorial video we will dive further into timers by using a timer to bit bang PWM on a GPIO where no timer channel is available (such as PC13). We will begin by letting STM32CubeMX generate all the code but then optimize that by creating our own interrupt handler.

A secondary point (or main point) of this video is also to look at the statistical profiler of STM32CubeIDE. It is an amazing tool.

First PWM video: https://youtu.be/4eVfLC05spU

STM32World Wiki: https://stm32world.com/wiki
Wiki page about bit bang PWM: https://stm32world.com/wiki/STM32_bit_bang_PWM

#STM32 #GettingStarted #Tutorial #STM32CubeIDE #STM32CubeMX #Timer #PWM #BitBang #Profiling #STM32World

00:00 Intro
00:30 Remembering topics already covered on the channel
02:00 The Blue Pill and Black Pill boards using PC13 for LED
03:05 Why PC13 is a poor choice for LED (no timer channel)
05:10 STM32CubeMX configuration – timer 4
07:00 The code
08:30 Starting the timer and implementing the timer callback
11:15 Running the code
13:05 Checking the performance penalty by looking at the loop count
14:10 Running the statistical profiling
15:20 About 2 % performance penalty when using callback
16:10 Further optimization – looking at the HAL interrupt handler
18:00 Implementing our own optimized interrupt handler
21:20 Running the optimized interrupt handler
22:00 Running statistical profiling again
23:05 Further optimization – removing check for interrupt cause
24:05 Profiling again 0.4 % wasted cpu cycles
26:00 Recap and conclusion
27:00 Why HAL is NOT evil – use HAL and THEN optimization where needed