cancel
Showing results for 
Search instead for 
Did you mean: 

How do I transfer input capture values from TIM1 to the DAC1 output via DMA?

KHarb.1
Senior

I'm new to STM parts and toolchain and I need to send input capture values from TIM1 to the DAC output via DMA. Cube doesn't support peripheral to peripheral DMA, but its been suggested I can accomplish it with a peripheral to memory DMA transfer, triggered by TIM1\CH4 if I supply the address of the DHR12RD register as a destination address. The user guide says this register is not memory mapped, but I can see what address is from the generated code. What happens if I attempt this? Is there another way to do it?

Also, the DAC is 12 bit and TIM1 is 16 bit, so I'm hoping the top four bits are simply ignored. Since the above method is non-standard, I'm not sure if this could make things not work. Under normal functioning, the capture registers will not record values above 4096, so overflows are not anticipated.

1 ACCEPTED SOLUTION

Accepted Solutions

CubeIDE only narrowly supports DMA. By adding post-config steps to the code to change CPAR and CMAR registers, the desired transfer is easy to accomplish.

View solution in original post

6 REPLIES 6

Which STM32?

> The user guide says this register is not memory mapped

What user guide say this?

> its been suggested

By whom?

> I can accomplish it with a peripheral to memory DMA transfer, triggered by TIM1\CH4

Probably yes, but why TIM1/CH4?

Have you tried?

JW

Depending on the part you'd use a DMA to move from the TIMx->CCRx that's triggered by the TIMx Update or CCx, and write the content to the DAC

This might need to be a DMA unit capable of memory-to-memory.

Experiment

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

STM32L43

Manual

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwj1_9Gzpoz-AhWEGjQIHTXJDqgQFnoECBgQAQ&url=https%3A%2F%2Fwww.st.com%2Fresource%2Fen%2Freference_manual%2Frm0432-stm32l4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf&usg=AOvVaw2ZGFj0WmMh988QfgbpTsR8

22.4.3 Mentions the memory mapping

TIM1_CH4_TRIG/COM is the only available trigger shown Cube. Using should work just fine.

Sometime doing weird stuff like this can brick the unit and I lack means of debug, so I'm asking in advance.

Memory to memory is also an option if you can just read and write from the relevant registers by the memory addresses...but I need to establish that.

KHarb.1
Senior

I've worked through some other problems and I have the unit running PWM that feeds ETR1 and TIM1\CH4. Without using DMA I wrote TIM1\CCR4 to DAC1 and I was able to observe correcty output. I tried to switch the DMA trick above and it didn't work. There may be different ways to do it, but I lack observability.

I used this line to start DMA:

HAL_DAC_Start_DMA(&hdac1,DAC_CHANNEL1,(uint32_t *) 0x40012C40U,1,DAC_ALIGN_12_B);

TIM1 base address is 0x40012C00

CCR4 off set is 0x40.

Any ideas on what to try are appreciated.

CubeIDE only narrowly supports DMA. By adding post-config steps to the code to change CPAR and CMAR registers, the desired transfer is easy to accomplish.