cancel
Showing results for 
Search instead for 
Did you mean: 

How to change NDTR after enabling DMA stream?

YoungKim
Associate III

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.

4 REPLIES 4

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
Associate III

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.

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
Associate III

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