2023-05-17 06:36 PM
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.
2023-05-17 09:55 PM
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
2023-05-18 03:29 PM
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.
2023-05-18 03:58 PM
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
2023-05-18 08:15 PM
Thanks JW. It works now. I should have read the RM more carefully.