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

Pwm remap: another try #147

Merged
merged 3 commits into from
Dec 1, 2019
Merged

Pwm remap: another try #147

merged 3 commits into from
Dec 1, 2019

Conversation

burrbull
Copy link
Contributor

This is something average between #124 and #146.

But it's need for testing.

cc @geomatsi

@burrbull
Copy link
Contributor Author

burrbull commented Nov 27, 2019

TIM Remaps should be in timer.rs I think.

@geomatsi
Copy link
Contributor

I will help with testing in the next few days.

BTW, friendly reminder, you need to update document section in src/pwm.rs. Alternatively, you may just remove it and add another 1-2 sections into pwm_custom.rs example to show how to use different PWM mappings.

Regards,
Sergey

@burrbull burrbull mentioned this pull request Nov 27, 2019
move Remap to timer.rs, add gpio::Mode
@burrbull
Copy link
Contributor Author

Rebased.

cc @TheZoq2

@burrbull
Copy link
Contributor Author

burrbull commented Nov 28, 2019

On this image PWM is not available for pins PA15 and PB3. Is this right?

изображение

CubeMX don't block for setting such combination

изображение

@geomatsi
Copy link
Contributor

@burrbull ,
Why not available ? I see T2C2 for PB3 and T2C1E for PA15 which is according to TIM2 table from TRM.

@geomatsi
Copy link
Contributor

Ok, now I see wave notation now. No idea why. I did a quick search through TRM, but couldn't find anything useful so far. The fastest option is just to give it a try.

@geomatsi
Copy link
Contributor

Hi @burrbull ,

Just for the record... On BluePill all the TIM/PWM configurations available on that package work properly on all 4 channels. Here is the list of supported timers/mappings/pins combinations:

  • TIM2 (0b00): PA0, PA1, PA2, PA3
  • TIM2 (0b01): PA15, PB3, PA2, PA3
  • TIM2 (0b10): PA0, PA1, PB10, PB11
  • TIM2 (0b11): PA15, PB3, PB10, PB11
  • TIM3 (0b00): PA6, PA7, PB0, PB1
  • TIM3 (0b10): PB4, PB5, PB0, PB1
  • TIM4 (0b00): PB6, PB7, PB8, PB9

In several cases afio.mapr.disable_jtag shall be used to reconfigure pins PA15, PB3, PB4 before using them as PWM output. Otherwise all works as expected, w/o surprises.

Note that for now these are the reference results that were obtained w/o your PR.

Regards,
Sergey

geomatsi added a commit to geomatsi/rust-blue-pill-tests that referenced this pull request Nov 30, 2019
This example is based on new PWM implementation in stm32f1xx HAL:
see stm32-rs/stm32f1xx-hal#147

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
@geomatsi
Copy link
Contributor

geomatsi commented Nov 30, 2019

Ok, PWM testing is completed for all the 4-channels combinations available on BluePill. Besides, random selection of 1/2/3-channels combinations has been tested as well. No testing for pwm_input and QEI from me though...

In brief, using this implementation is very convenient. With this implementation it is hard to end up with a misconfigured PWM. Full example is available here. Note that test example explicitly specifies all the mappings in the form pwm::<Tim3PartialRemap, _, _, _>. But in fact it is needed only if there is ambiguity in pin selection. Normally it can be skipped on the first pass and compiler will complain if it can not figure out the specific pin combination.

Tested-by: Sergey Matyukevich geomatsi@gmail.com

Regards,
Sergey

@@ -14,10 +14,10 @@
```rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole document subsection about pre-defined channel combinations can be removed.

feature = "stm32f105",
))]
impl Timer<TIM1> {
pub fn pwm_input<REMAP, PINS, T>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with using pwm_input and qei. So the question based on comparison with pwm implementation. I assume it is not pwm_input<REMAP, P, PINS, T> just because only (Ch1, Ch2) are allowed for pwm_input mode as well as QEI mode. Is this correct ? Or more configurations are supported, but this is current limitation of stm32f1xx_hal ?

where
REMAP: Remap<Periph = TIM>,
P1: Ch1<REMAP> + gpio::Mode<Input<Floating>>,
P2: Ch2<REMAP> + gpio::Mode<Input<Floating>> {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geomatsi pwm_input use other Pins trait/implementation with only first two channels. I did not change this.

Copy link
Member

@TheZoq2 TheZoq2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall (though i'm not super familiar with PWM input or QEI). I left some nitpick comments, mostly related to docs

CHANGELOG.md Outdated
@@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Breaking changes

- Implement more pin combinations for PWM configuration, added PWM for TIM1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like a breaking change, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone use old custom API, now he need to rewrite his code. So yes, it is breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea, makes sense. Perhaps the changelog should clarify that though

@@ -58,12 +34,12 @@ fn main() -> ! {
let p0 = pb4.into_alternate_push_pull(&mut gpiob.crl);
let p1 = gpiob.pb5.into_alternate_push_pull(&mut gpiob.crl);

//let pa1 = gpioa.pa1.into_alternate_push_pull(&mut gpioa.crl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused comments

timer::Timer,
//timer::Tim2NoRemap,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused comment

src/pwm.rs Outdated
@@ -28,227 +28,157 @@

// Put the timer in PWM mode using the specified pins
// with a frequency of 100 hz.
// In some cases you need to specify remap you need, especcially for TIM2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to point users to where they can find what remaps they can specify.

Also double 'c' in especially

@TheZoq2
Copy link
Member

TheZoq2 commented Dec 1, 2019

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants