Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32G4: modm interface hides some of Timer features #1011

Closed
ser-plu opened this issue May 2, 2023 · 3 comments · Fixed by #1018
Closed

STM32G4: modm interface hides some of Timer features #1011

ser-plu opened this issue May 2, 2023 · 3 comments · Fixed by #1018

Comments

@ser-plu
Copy link

ser-plu commented May 2, 2023

  1. Timers 15/16/17 have complementary outputs, but use configureOutputChannel function from simple timers (cannot enable the complementary channel). configureOutputChannel from AdvancedControlTimer is more appropriate. There could be also more similarities between the timers.
  2. GeneralPurposeTimer::signalToChannel does not work with complementary channels.
    Need to add || Signal::Signal == Gpio::Signal::Ch1n to every if check.
@ser-plu ser-plu changed the title STM32G4: Interface hides some of Timer features STM32G4: modm interface hides some of Timer features May 2, 2023
@rleh rleh added this to the 2023q2 milestone May 4, 2023
@rleh
Copy link
Member

rleh commented May 4, 2023

Do you want to propose a fix?

@hshose
Copy link
Contributor

hshose commented May 5, 2023

I just ran into the same issue; hacky workaround is:

using Timer = Timer1;
Timer::enable();
Timer::setMode(Timer::Mode::UpCounter);
// Timer clock: APB2 timer clock (170MHz)
Timer::setPrescaler(10);
// Prescaler: 1 -> Timer counter frequency: 170MHz
Timer::setOverflow(4250);
// Pwm frequency: 170MHz / 4250 / 10 = 4kHz

// configureOutputChannel for ChXn channels does not work
// Timer::configureOutputChannel<GpioC13::Ch1n>(Timer::OutputCompareMode::Pwm, 0);

// However, the configure output channel with Ch1 pin disabled works as expected
Timer::configureOutputChannel(1,
	Timer::OutputCompareMode::Pwm,
	Timer::PinState::Disable, // disable Ch1 output
	Timer::OutputComparePolarity::ActiveHigh, // this doesn't matter
	Timer::PinState::Enable, // enable Ch1n output
	Timer::OutputComparePolarity::ActiveHigh, // OutputComparePolarity for Ch1n
	Timer::OutputComparePreload::Disable
	);
Timer::applyAndReset();

Timer::setCompareValue(1,0);
Timer::applyAndReset();
Timer::pause();
Timer::enableOutput();
Timer::connect<GpioC13::Ch1n>(); // it works to just connect the Ch1n channel
Timer::start();

@salkinium
Copy link
Member

This has been fixed, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants