You are on page 1of 24

Custom Signal generation

using PWM and DMA


Video Series: Hands-On with STM32 Timers

Nicolas FILLON
Objective

• Generate Custom Signal using PWM and DMA


• Output PWM on 1 channel CH1 of a STM32 Timer
Equipment utilized

NUCLEO-H745ZI-Q Micro USB Cable Oscilloscope


Software Tools

STM32CubeIDE
Custom Signal generation using PWM and DMA

• Generate Custom PWM signal using


Timer + DMA
• Transfer sine wave data to CCR reg
• Duty cycle defined by CCR register
• Using the DMA keeps the Cortex-M
core free
Sine wave table

• Sine wave data computed in a spreadsheet


• Normalize sine table data to use in CCR register
• Optionally, sine wave can be computed by STM32H7 on the fly
• Timer Feature Comparison
Table in STM32H745
reference manual (RM0399)
Configure Clock frequency (480/240 MHz)
STM32CubeIDE

• Select Cortex-M7
• Select PWM Generation CH1 for
Channel 1
Select Cortex-M7 & Configure TIM4
DMA Configuration
STM32CubeIDE final pin configuration

GPIO Pin PWM Channel

PD12 TIM4 CH1


Nucleo Pinout

Channel 1
Sine data array

• Create sine buffer array for DMA


• Replace any CCR = 0 in spreadsheet table with CCR = 1
Enable D & I cache and flush D cache
• Enable D & I cache

• Flush D cache
Start function to transfer data from RAM to timer
Placement of all memory in D1 domain – Other IDE

• https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
Placement of all memory in D1 domain – IAR IDE setup
Result (Oscilloscope output)

Yellow: TIM4 CH1


(GPIO Pin PD12)
Result (zoomed in)

Yellow: TIM4 CH1


(GPIO Pin PD12)
Result (Displayed on Logic analyzer)

CH1 (GPIO Pin PD12)

CH2 (GPIO Pin PD13)

CH3 (GPIO Pin PD14)


Links

• AN4013: https://www.st.com/resource/en/application_note/dm00042534-stm32-
crossseries-timer-overview-stmicroelectronics.pdf
• STM32H745 reference
manual: https://www.st.com/resource/en/reference_manual/dm00176879-
stm32h745755-and-stm32h747757-advanced-armbased-32bit-mcus-
stmicroelectronics.pdf
• STM32H745 datasheet: https://www.st.com/resource/en/datasheet/stm32h745zg.pdf
• Memory domain configuration: https://community.st.com/s/article/FAQ-DMA-is-not-
working-on-STM32H7-devices
Thank you

© STMicroelectronics - All rights reserved.


ST logo is a trademark or a registered trademark of STMicroelectronics International NV or its affiliates in the EU and/or other countries.
For additional information about ST trademarks, please refer to www.st.com/trademarks.
All other product or service names are the property of their respective owners.

You might also like