Skip to content

Commit 1367bd6

Browse files
Sergey Pluzhnikovchris-durand
authored andcommitted
STM32G4: Generate complementary output setup for Timers 15,16,17
1 parent 9e75da6 commit 1367bd6

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/modm/platform/timer/stm32/general_purpose.cpp.in

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,39 @@ modm::platform::Timer{{ id }}::configureOutputChannel(uint32_t channel,
197197
}
198198
}
199199

200+
%% if target.family in ["g4"] and id in [15, 16, 17]
201+
void
202+
modm::platform::Timer{{ id }}::configureOutputChannel(uint32_t channel,
203+
OutputCompareMode mode,
204+
PinState out, OutputComparePolarity polarity,
205+
PinState out_n, OutputComparePolarity polarity_n,
206+
OutputComparePreload preload)
207+
{
208+
modm_assert(channel == 1, "Timer{{ id }}", "This timer has complementary output only on channel 1!", "{{ id }}");
209+
210+
channel -= 1;
211+
212+
// disable output
213+
TIM{{ id }}->CCER &= ~(0xf << (channel * 4));
214+
215+
uint32_t flags = static_cast<uint32_t>(mode) | static_cast<uint32_t>(preload);
216+
217+
const uint32_t offset = 8 * channel;
218+
219+
flags <<= offset;
220+
flags |= TIM{{ id }}->CCMR1 & ~(0xff << offset);
221+
222+
TIM{{ id }}->CCMR1 = flags;
223+
224+
// CCER Flags (Enable/Polarity)
225+
flags = (static_cast<uint32_t>(polarity_n) << 2) |
226+
(static_cast<uint32_t>(out_n) << 2) |
227+
static_cast<uint32_t>(polarity) | static_cast<uint32_t>(out);
228+
229+
TIM{{ id }}->CCER |= flags << (channel * 4);
230+
}
231+
%% endif
232+
200233
// ----------------------------------------------------------------------------
201234
void
202235
modm::platform::Timer{{ id }}::enableInterruptVector(bool enable, uint32_t priority)
@@ -240,4 +273,4 @@ modm::platform::Timer{{ id }}::isChannelConfiguredAsInput(uint32_t channel)
240273
}
241274
return isInput;
242275
}
243-
%% endif
276+
%% endif

src/modm/platform/timer/stm32/general_purpose.hpp.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,28 @@ public:
387387
configureOutputChannel(channel, mode, compareValue, out, enableComparePreload);
388388
}
389389

390+
%% if target.family in ["g4"] and id in [15, 16, 17]
391+
static void
392+
configureOutputChannel(uint32_t channel, OutputCompareMode mode,
393+
PinState out, OutputComparePolarity polarity,
394+
PinState out_n,
395+
OutputComparePolarity polarity_n = OutputComparePolarity::ActiveHigh,
396+
OutputComparePreload preload = OutputComparePreload::Disable);
397+
398+
template<typename Signal>
399+
static void
400+
configureOutputChannel(OutputCompareMode mode,
401+
PinState out, OutputComparePolarity polarity,
402+
PinState out_n,
403+
OutputComparePolarity polarity_n = OutputComparePolarity::ActiveHigh,
404+
OutputComparePreload preload = OutputComparePreload::Disable)
405+
{
406+
constexpr auto channel = signalToChannel<Peripheral::Tim{{ id }}, Signal>();
407+
static_assert(channel == 1, "Timer{{ id }} has complementary output only on channel 1");
408+
configureOutputChannel(channel, mode, out, polarity, out_n, polarity_n, preload);
409+
}
410+
%% endif
411+
390412
/// Switch to Pwm Mode 2
391413
///
392414
/// While upcounting channel will be active as long as the time value is

0 commit comments

Comments
 (0)