Skip to content

Commit

Permalink
[stm32] Add basic DMA support to F3 ADC driver
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Feb 5, 2024
1 parent a3cb641 commit d941ea4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/modm/platform/adc/stm32f3/adc.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ public:
%% endif
};

enum class DmaMode : uint32_t
{
Disabled = 0,
%% if target["family"] in ["h7"] and resolution == 12:
OneShot = ADC3_CFGR_DMAEN,
Circular = ADC3_CFGR_DMACFG | ADC3_CFGR_DMAEN,
Mask = Circular
%% elif target["family"] in ["h7"] and resolution == 16:
OneShot = ADC_CFGR_DMNGT_0,
Dfsdm = ADC_CFGR_DMNGT_1,
Circular = ADC_CFGR_DMNGT_1 | ADC_CFGR_DMNGT_0,
Mask = ADC_CFGR_DMNGT_Msk
%% else
OneShot = ADC_CFGR_DMAEN,
Circular = ADC_CFGR_DMACFG | ADC_CFGR_DMAEN,
Mask = Circular
%% endif
};

enum class Interrupt : uint32_t
{
Ready = ADC_IER_ADRDYIE,
Expand Down Expand Up @@ -581,6 +600,16 @@ public:
static inline void
acknowledgeInterruptFlags(const InterruptFlag_t flags);

/// @return ADC data register pointer, for DMA use only.
static inline volatile uint32_t*
dataRegister()
{
return &(ADC{{ id }}->DR);
}

static inline void
setDmaMode(DmaMode mode);

private:
static inline bool
configureChannel(Channel channel, SampleTime sampleTime);
Expand Down
7 changes: 7 additions & 0 deletions src/modm/platform/adc/stm32f3/adc_impl.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ modm::platform::Adc{{ id }}::isInjectedConversionFinished()
return static_cast<bool>(getInterruptFlags() & InterruptFlag::EndOfInjectedSequenceOfConversions);
}

void
modm::platform::Adc{{ id }}::setDmaMode(DmaMode mode)
{
constexpr uint32_t mask = std::to_underlying(DmaMode::Mask);
ADC{{ id }}->CFGR = (ADC{{ id }}->CFGR & ~mask) | std::to_underlying(mode);
}

// ----------------------------------------------------------------------------
void
modm::platform::Adc{{ id }}::enableInterruptVector(const uint32_t priority,
Expand Down

0 comments on commit d941ea4

Please sign in to comment.