Microcontrollers interact with analog signals.
Analog input signal respective to STM32 will go to ADC or Comparators to be digitized.
Analog output signal are also common in embedded applications, they come from DAC (Digital to Analog Converters).
There are mainly 2 ways to generate analog output signals:
PWM: Pulse Width Modulation
This is the most common choice as it's a digital (compact) solution. It looks like a square wave with a specific frequency (period) and duty cycle. This is usually generated by TIMER Output Compares (Timer CC pins) function.
On the GPIO configured as Timer Alternate CC function, a low pass RC filter is typically put to average the signal and convert the square wave into analog.
What is the highest signal frequency you need to generate? Multiply it at least 3 times and this will be (rule of thumb) the PWM frequency. Size the cut off frequency of the RC filter properly. How many steps do you need? If you need 8 bit, it's 256 steps (duty cycles), multiply the frequency again and this will be the minimum frequency of the timer you'll need.
Most timers can have up to 4 CC so 4 PWM.
Obviously, if you stop the MCU clock for low power mode, the PWMs will die. One solution? R-DAC
Some STM32 have one or two R DAC (resistive based dac) which is similar to a switch array of resistors. This is also how your LCD screen pixel color level are generated by source (column driver) on the top side of the display glass.
Their merit is that they are fast and do not need clocks, the analog output is maintained in stop mode and the output sample rate is typically 1 Msps (mega samples per second).
STM32 DAC have optional buffer which decrease the output impedence at the cost of a slight voltage offset.
DACs are typically on PA4 and PA5 which are also connected to ADCs. This way, without connecting the GPIO, the ADC can be directly tested with a DAC and monitored by an osciloscope probe. Handy!
The DAC has a slew rate so it won't be able to swing from 0 to Vref so fast. Check the datasheet.
SW can update the DAC value instantly or delayed by a trigger edge which can be a specific GPIO.
To generate waverforms, predefined waveforms are available by HW (ramps). Or using DMA sweeping around a RAM buffer will do the trick to make sinewave or anything with a period.
An advanced example of fun thing to do with ADC and DAC is a digital filter on audio signals. Link.
This is where matlab/simulink on STM32 enables lots of experiments.