Skip to content

Commit 9355dce

Browse files
committed
[example] Adapt STM32G0 DMA ADC example to API change
1 parent 86dbceb commit 9355dce

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

examples/nucleo_g070rb/adc_dma/adc_dma.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define EXAMPLE_ADCDMA_HPP
1313

1414
#include <modm/platform.hpp>
15+
#include <span>
1516

1617
template<class Adc, class DmaChannel>
1718
class AdcDma
@@ -31,7 +32,7 @@ class AdcDma
3132
*/
3233
template<class SystemClock>
3334
static void
34-
initialize(uintptr_t destination_ptr, size_t length,
35+
initialize(std::span<uint16_t> buffer,
3536
modm::platform::DmaBase::Priority priority = modm::platform::DmaBase::Priority::Low,
3637
modm::platform::DmaBase::CircularMode circularMode =
3738
modm::platform::DmaBase::CircularMode::Enabled,
@@ -46,8 +47,8 @@ class AdcDma
4647
modm::platform::DmaBase::MemoryIncrementMode::Increment,
4748
modm::platform::DmaBase::PeripheralIncrementMode::Fixed, priority, circularMode);
4849
Dma::AdcChannel::setPeripheralAddress(Adc::getDataRegisterAddress());
49-
Dma::AdcChannel::setDataLength(length);
50-
Dma::AdcChannel::setMemoryAddress(destination_ptr);
50+
Dma::AdcChannel::setDataLength(buffer.size());
51+
Dma::AdcChannel::setMemoryAddress(reinterpret_cast<uintptr_t>(buffer.data()));
5152

5253
setTransferErrorCallback(transferErrorCallback);
5354
setHalfCompletedConversionCallback(halfCompletedCallback);

examples/nucleo_g070rb/adc_dma/main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace Board;
2727
using namespace modm::platform;
2828
using Adc1Dma = AdcDma<Adc1, Dma1::Channel1>;
2929

30-
std::array<uint16_t, 100> adc_results;
30+
std::array<uint16_t, 100> adc_results{};
3131
volatile bool dma_completed = false;
3232

3333
void
@@ -49,26 +49,21 @@ main()
4949
LedD13::setOutput();
5050
LedD13::reset();
5151

52-
adc_results.fill(0);
53-
5452
Adc1::connect<GpioInputA0::In0>();
5553
Adc1::connect<GpioInputA1::In1>();
5654

57-
const auto a0_channel = Adc1::getPinChannel<GpioInputA0>();
58-
const auto a1_channel = Adc1::getPinChannel<GpioInputA1>();
5955
Adc1::setSampleTime(Adc1::SampleTime::Cycles3_5);
6056
Adc1::initialize<SystemClock, Adc1::ClockMode::Asynchronous>();
61-
Adc1::enableScanMode();
6257
modm::delay(500ms);
6358
// On STM32G0 Event1 means TIM1's channel 4 capture and compare event.
6459
// Each controller has a different trigger mapping, check the reference
6560
// manual for more information on the trigger mapping of your controller.
6661
Adc1::enableRegularConversionExternalTrigger(Adc1::ExternalTriggerPolarity::RisingEdge,
6762
Adc1::RegularConversionExternalTrigger::Event1);
68-
Adc1::addChannel(a0_channel);
69-
Adc1::addChannel(a1_channel);
63+
64+
Adc1::setChannels(Adc1::channelSequenceFromPins<GpioInputA0, GpioInputA1>());
7065
Dma1::enable();
71-
Adc1Dma::initialize<SystemClock>((uintptr_t)(&adc_results[0]), adc_results.size());
66+
Adc1Dma::initialize<SystemClock>(adc_results);
7267
Adc1Dma::setCompletedConversionCallback(completedCallback);
7368
Adc1Dma::startDma();
7469
Adc1::startConversion();
@@ -83,7 +78,7 @@ main()
8378
dma_completed = false;
8479
MODM_LOG_INFO << "Measurements"
8580
<< "\r" << modm::endl;
86-
for (const uint16_t& sample : adc_results) { MODM_LOG_INFO << sample << ", "; }
81+
for (uint16_t sample : adc_results) { MODM_LOG_INFO << sample << ", "; }
8782
MODM_LOG_INFO << "\r" << modm::endl;
8883
adc_results.fill(0);
8984
timerStart<Timer1>();

0 commit comments

Comments
 (0)