Author Topic: STM32 DMA PWM two channels  (Read 11257 times)

0 Members and 2 Guests are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1980
  • Country: ca
Re: STM32 DMA PWM two channels
« Reply #25 on: March 20, 2021, 09:02:15 pm »
It sounds  great! >:D
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6467
  • Country: es
Re: STM32 DMA PWM two channels
« Reply #26 on: March 21, 2021, 12:57:45 am »
I got it working in Burst mode. Hence, now it's doing stereo with the same resources.

In this mode, when the timer triggers the DMA, it does it multiple times, and uses a virtual register (DMAR) that will redirect the data to register offset set in DCR.
In this case , burst=2, offset=CCR1, so it will update 2 channels at once (CCR1 + CCR2).
Only 3 lines of code, however getting it configured correctly took a few tries


Code: [Select]
/* Configure timer in DMA burst mode
*
*  Timer start offset = CCR1
*  DMA trigger source = Timer Update
*  DMA source = PCMdata[]
*  Burst count = 2
*/ Total data length = PCMsize (it's a #define here)

HAL_TIM_DMABurst_MultiWriteStart(&htim1, TIM_DMABASE_CCR1, TIM_DMA_UPDATE, (uint32_t*)&PCMdata[0], TIM_DMABURSTLENGTH_2TRANSFERS, PCMsize);


// Start PWM channels

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);

But I have bad news: STM32 F0 and F1 series don't have it... only single transfer.
It seems it does! AN4776 said that... but it's wrong.
« Last Edit: March 21, 2021, 10:04:02 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6467
  • Country: es
Re: STM32 DMA PWM two channels
« Reply #27 on: March 21, 2021, 05:21:28 am »
I finally added WAV parsing, it can recognize and play 16/32/48KHz mono/stereo 8-bit WAV files.
I uploaded the sample project here:

https://github.com/deividAlfa/STM32F411-Black-pill-USB-wav-player
« Last Edit: March 21, 2021, 05:33:41 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1980
  • Country: ca
Re: STM32 DMA PWM two channels
« Reply #28 on: March 21, 2021, 09:36:12 am »
Thanks for sharing >:D
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: au
Re: STM32 DMA PWM two channels
« Reply #29 on: March 21, 2021, 08:47:21 pm »
I got it working in Burst mode. Hence, now it's doing stereo with the same resources.

In this mode, when the timer triggers the DMA, it does it multiple times, and uses a virtual register (DMAR) that will redirect the data to register offset set in DCR.
In this case , burst=2, offset=CCR1, so it will update 2 channels at once (CCR1 + CCR2).
Only 3 lines of code, however getting it configured correctly took a few tries

...


But I have bad news: STM32 F0 and F1 series don't have it... only single transfer.

Don't have burst mode? I've not done much with F1s, and nothing at all with an F0, but from a quick peek at the reference manuals, burst mode DMA is supported for some of the timers.
 
The following users thanked this post: DavidAlfa

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6467
  • Country: es
Re: STM32 DMA PWM two channels
« Reply #30 on: March 21, 2021, 10:03:04 pm »
Don't have burst mode? I've not done much with F1s, and nothing at all with an F0, but from a quick peek at the reference manuals, burst mode DMA is supported for some of the timers.


You're right!

I checked both STM32F0xx and STM32F10x series reference manuals.
TIM1 has DMAR/DCR registers, clearly stating the DMA burst capabilities.

What I posted was based on the AN4776 application note, which might refer to other F1 series.
Or just BS to trick you into buying a more expensive part?

Quote
In STM32 microcontroller families, there are two DMA peripheral variants:
• The DMA burst transfer feature supported only by the STM32F2 products DMA
peripheral variant where the DMA peripheral can transfer a configurable number of
data elements next to a single data transfer trigger.
• In another variant, like the one on the STM32F1 products, the DMA peripheral variant
supports only single transfers; this means that only one data element is transferred
next to a data transfer trigger.
« Last Edit: March 21, 2021, 10:05:12 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf