Skip to main content
YoungKim
Associate II
May 18, 2023
Question

How to change NDTR after enabling DMA stream?

  • May 18, 2023
  • 4 replies
  • 1830 views

I can want to change NDTR after enabling DMA stream. but I can't. This is the part of code

...
 LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5);
 // works fine now
 // but I want to change the data length only
 
 LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_5, 11); // this doesn't work 
 
 LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_5);
 LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_5, 12); // this works
 LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5); // but this doesn't work !!

I checked the result in SFRs of debugger.

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
May 18, 2023

Which STM32?

You can't change NDTR while stream is enabled. You can change it when stream is disabled, but that also restarts the internal memory/peripheral pointers, that's probably what confused you.

JW

YoungKim
YoungKimAuthor
Associate II
May 18, 2023

It is STM32F767.

I can see the stream is enabled in debugger after add the block of code below:

 /* Enable DMA Channels */
 
 LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5);
 
 
 
 {
 
 LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_5);
 
 LL_DMA_SetPeriphAddress(DMA1, LL_DMA_STREAM_5, LL_USART_DMA_GetRegAddr(USART2, LL_USART_DMA_REG_DATA_RECEIVE));
 
 LL_DMA_SetMemoryAddress(DMA1, LL_DMA_STREAM_5, (uint32_t)servoDmaRxBuffer);
 
 LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_5, 30);
 
 
 
 LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5);
 
 }

But It doesn't generate DMA interrupt if I add this block.

DMA interrupt works find if I remove the block.

waclawek.jan
Super User
May 18, 2023

To disable/enable stream, follow procedure prescribed by RM.

After clearing CR.EN, read it back and wait until it reads zero. Then, before setting it again, clear the status flags.

JW

YoungKim
YoungKimAuthor
Associate II
May 19, 2023

Thanks JW. It works now. I should have read the RM more carefully.