diff --git a/src/shared/drivers/dma/DMA.cpp b/src/shared/drivers/dma/DMA.cpp index c23edfe8479af7871091b9192b088c5bd8cb5a4b..6a1903e6c5c6ed26aa7000ec8cf11e668d7bc21d 100644 --- a/src/shared/drivers/dma/DMA.cpp +++ b/src/shared/drivers/dma/DMA.cpp @@ -613,11 +613,18 @@ void DMAStream::readFlags() directModeErrorFlag = flags & DMA_LISR_DMEIF0; } -void DMAStream::setNumberOfDataItems(const uint16_t nBytes) +bool DMAStream::setNumberOfDataItems(const uint16_t nBytes) { - // TODO: assert that the stream is disabled while doing it + // Verify that the stream is disabled while doing it + if (registers->CR & DMA_SxCR_EN != 0) + { + // Cannot proceed + return false; + } + currentSetup.numberOfDataItems = nBytes; registers->NDTR = nBytes; + return true; } void DMAStream::setChannel(const DMADefs::Channel channel) diff --git a/src/shared/drivers/dma/DMA.h b/src/shared/drivers/dma/DMA.h index b1276864a47ca7532704f1c0ac675295f7913b6f..cabb4de6f3994c6267b23aec010241a08a26562e 100644 --- a/src/shared/drivers/dma/DMA.h +++ b/src/shared/drivers/dma/DMA.h @@ -213,9 +213,11 @@ public: /** * @brief Set the number of bytes to be exchanged during a * dma transaction. Useful in case you don't want to change - * the entire configuration. + * the entire configuration. Use while the stream is not + * enabled. + * @return True if the operation succeeded, false otherwise. */ - void setNumberOfDataItems(const uint16_t nBytes); + bool setNumberOfDataItems(const uint16_t nBytes); /** * @brief Select the channel to be used by the stream during