cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate PWM signals with DMA on STM32L476RG?

YFuku.3
Associate III

Environment

  • board: NUCLEO-L476RG
  • STM32CubeMX v5.6.0
  • IDE: SW4STM32

I'm attempting to generate PWM signals with DMA in normal mode, but doesn't work. I'm stack in this issue for a week. I'm very happy if you give me any advice. Thank you in advance.

other info

  • PWM without DMA works fine.
  • build doesn't cause errors.
  • Can't see any signal on oscilloscope.
  • Checked the pin assignment is correct, which is PA10

I attached files.

This is a whole project

https://github.com/yusukezmp/LED_L476

7 REPLIES 7
berendi
Principal
Imen GH
ST Employee

Hello,

You can find the example under the STM32Cube directory:

STM32Cube\Repository\STM32Cube_FW_L4_V1.15.1\Projects\NUCLEO-L476RG\Examples\TIM\TIM_DMA\src.

This example can help you to solve your problem. You can compare your files with the mentioned example.

Note: In your file STM32L4xx_hal_msp.c,

you put:  hdma_tim1_ch3.Init.Direction = DMA_PERIPH_TO_MEMORY;

But, you must put:   hdma_tim1_ch3.Init.Direction =DMA_MEMORY_TO_PERIPH;

Please find attached the example allowing to generate PWM signals using DMA on two channels.

Regards

Imen GH
ST Employee

Here attached the file STM32L4xx_hal_msp.c

Hi, ICHOR.1

Thank you for your reply.

>You can find the example under the STM32Cube directory:

I've already tried the example code.

The code itself works out, but when I copy and paste files below to my project and run them, no signal is generated.

-------------

main.c

stm32l4xx_hal_msp.c

stm32l4xx_it.c

system_stm32l4xx.c

main.h

stm32l4xx_hal_conf.h

stm32l4xx_it.h

-------------

 At that time, I commented out

- #include "stm32l4xx_nucleo.h" in main.h

- two lines for LED in main.c

because they causes errors.

>But, you must put:  hdma_tim1_ch3.Init.Direction =DMA_MEMORY_TO_PERIPH;

I tried this but no change

I also copied and pasted your files to my project, but no change.

YFuku.3
Associate III

This is a whole project

https://github.com/yusukezmp/LED_L476

Hi, berendi,

I would like to code using HAL.

HAL functions are rather poorly documented. It is often not clear what exactly a function or parameter is supposed to do.

You can of course try to solve it using HAL. You might get lucky, and find a working solution. I have found that reading the reference manual and using the registers directly is a more reliable way to get results in a finite amount of time.