cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4 DMAMUX

Tommino
Senior

Hello,

Can you help me to use the DMAMUX in the STM32G474 microcontroller?

How can I program the uC to make TIM2_CH1 sends a DMA request when CC. I have found this in the reference manual but I can't undesrtand which channel of the DMA is involved. Thanks for the clarification 0693W00000LvzUZQAZ.png

1 ACCEPTED SOLUTION

Accepted Solutions

0693W00000NpSASQA3.pngProblem is, that there's no good documented way for this wait. ST published this as errata for older STM32 families, and some of the proposed workarounds are known to not work (and ST does not care, as usually). ST's "libraries" are usually inefficient enough so that timing issues such as these simply never come up.

You can try to insert a couple of NOPs, or dummy reads. A bulletproof solution would be to loop writing and reading back one DMAMUX register utnil it reads back the value written.

What I do is, that I enable all peripheral clocks for peripherals used in the given application early in the program, starting with GPIOs' clocks; then I initialize all GPIOs, then I do any other peripheral initialization. I don't subscribe to the "everything related to given peripheral should be changed at one place" notion (related to my reluctance to use any "abstraction" in microcontrollers).

JW

View solution in original post

21 REPLIES 21
TDK
Guru

You can use any channel you want. You need to set up the MUX such that that channel's input is tied to the request that you want.

For example, if you want to use DMA1 channel 1, set DMAREQ_ID=56 in DMAMUX_C0CR.

If you want to use DMA2 channel 8, use DMAMUX_C15CR instead.

(Note that DMA channel indices are 1-based while DMAMUX indices are 0-based.)

0693W00000Lw04NQAR.png

If you feel a post has answered your question, please click "Accept as Solution".
Tommino
Senior

Hi @TDK​ 

Now I see, The register I write sets the DMA channel: DMAMUX_C0CR refers to DMA1channel1, DMAMUX_C1CR refers to DMA1channel2, and so forth.

Thanks

Tommino
Senior

Can the same peripheral (e.g. tim2_ch1) send DMA request to two different DMA channel?

Can I write the same DMAREQ_ID in more than one dedicated register?

No.

0693W00000Lw0aOQAR.png

If you feel a post has answered your question, please click "Accept as Solution".
Tommino
Senior

Hi @TDK​ 

Sorry to bother you again..

But the expression DMAMUX -> C0CR = 56; does not work because of a syntax error.

I think it is beacuse the CMSIS STM32G474xx Device Peripheral Access Layer Header File lacks of some definitions. Can you help me to suitably code that DMAREQ_ID=56 in DMAMUX_C0CR ?

Thanks a lot

ST is not very consistent in keeping RM nomenclature en sync with symbols in CMSIS-mandated device headers. As ST declines to provide normal examples, sometimes you may be required to have a look at the header yourself:

0693W00000LzCYBQA3.png 

0693W00000LzCXmQAN.pngi.e. you'd use DMAMUX1_Channel0->CCR = 56;

JW

Tommino
Senior

Hi,

@Community member​ 

it seems that the DMAMUX1_Channel0->CCR = 56 does not have syntax error but the DMAMUX register does not change when debugging my code. Do you think there is an error yet?

0693W00000NpE3SQAV.png

And when you stop execution (place breakpoint) somewhere after those two lines, can you change the DMAMUX register values in the debugger?

I bet you can't as you probably did not enable DMAMUX clock in RCC:

0693W00000NpMrLQAV.png 

JW

Tommino
Senior

Hi @Community member​ 

yes I forgot to enable the DMAMUX clock in the RCC.

As you explained, now I can edit the register in the debugger and that works.

However with my code (relevant part reported below) the registers still do not change.

Do you have any idea about this latter issue?

void DMA1_Init(void){
	// Enable the DMA Clock
	RCC-> AHB1ENR |= (1<<0)|(1<<2); // Enable DMA1 and DMAMUX1 Clock
	// DMAMUX mapping:
	//DMAMUX1_Channel0 (connected to DMA1_Channel1) receives a request form TIM2_Ch1.
	DMAMUX1_Channel0 -> CCR = 56;
	// DMAMUX1_Channel1 (connected to DMA1_Channel2) receives a request form TIM2_Ch2
	DMAMUX1_Channel1 -> CCR=57;
}
int main(void)
{
DMA1_Init();
}