diff --git a/src/shared/drivers/dma/DMA.cpp b/src/shared/drivers/dma/DMA.cpp index 5ee1dc1316394989fc6a69ff6cf9a07cdf1fb861..07679e4f915c0dc2f2223815d7261e21e59b1de5 100644 --- a/src/shared/drivers/dma/DMA.cpp +++ b/src/shared/drivers/dma/DMA.cpp @@ -370,7 +370,8 @@ void DMAStream::setup(DMATransaction transaction) registers->CR |= static_cast<uint32_t>(transaction.priority); if (transaction.circularMode) registers->CR |= DMA_SxCR_CIRC; - registers->NDTR = transaction.numberOfDataItems; + + setNumberOfDataItems(transaction.numberOfDataItems); if (transaction.direction == DMATransaction::Direction::MEM_TO_PER) { @@ -551,6 +552,13 @@ void DMAStream::readFlags() directModeErrorFlag = flags & DMA_LISR_DMEIF0; } +void DMAStream::setNumberOfDataItems(const uint16_t nBytes) +{ + // TODO: assert that the stream is disabled while doing it + currentSetup.numberOfDataItems = nBytes; + registers->NDTR = nBytes; +} + int DMAStream::getCurrentBufferNumber() { return (registers->CR & DMA_SxCR_CT) != 0 ? 2 : 1; diff --git a/src/shared/drivers/dma/DMA.h b/src/shared/drivers/dma/DMA.h index e36a70d900d787f0642f00ce55c398aa2737b2cd..8fda416dbd9a7b59718410b2e8fea646da569afe 100644 --- a/src/shared/drivers/dma/DMA.h +++ b/src/shared/drivers/dma/DMA.h @@ -210,6 +210,13 @@ public: */ void readFlags(); + /** + * @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. + */ + void setNumberOfDataItems(const uint16_t nBytes); + /** * @brief Returns the last read status of the half transfer flag. *