From 395b6cd4c621fe460c1d61a99bc0fc38913d5481 Mon Sep 17 00:00:00 2001 From: Antun Skuric <36178713+askuric@users.noreply.github.com> Date: Tue, 14 Oct 2025 08:27:56 +0200 Subject: [PATCH 1/2] Create PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..6d9b79ae --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,30 @@ +# Description + +Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any architectures/sensors/motors that the PR is targeting if appicable. + +The best approach would be to create an issue and reference it in this pull request. +Example: + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] This change requires a documentation update + +# How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration + +**Test Configuration/Setup**: +* Hardware: +* IDE: Arduino/Platformio +* MCU package version (stm32duino/arduino-esp32/..) + +# **IMPORTANT** when opening the pull request + +* Your pull request MUST target the `dev` branch on this repository. By default you'll probably target `master`, make sure to change it. From a916bfaa015085da923ac1164098c0593b5eb381 Mon Sep 17 00:00:00 2001 From: JP Thomas Date: Wed, 5 Nov 2025 14:00:38 -0700 Subject: [PATCH 2/2] Update teensy4_mcu.cpp _writeDutyCycle6PWM to handle phase_state Handles phase_state so that PWM pins will be disabled when motor.disable() is called. This enables coasting the motor on drivers where the enable pin does not fully disable the driver and all 6 PWM pins must be disabled. --- .../hardware_specific/teensy/teensy4_mcu.cpp | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/drivers/hardware_specific/teensy/teensy4_mcu.cpp b/src/drivers/hardware_specific/teensy/teensy4_mcu.cpp index 47108447..ea0be35f 100644 --- a/src/drivers/hardware_specific/teensy/teensy4_mcu.cpp +++ b/src/drivers/hardware_specific/teensy/teensy4_mcu.cpp @@ -526,16 +526,59 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons } +// Helper function to enable or disable pwm pins based on phase state (allows for disabling the motor) +static inline void _teensy4_apply_phase_state( + IMXRT_FLEXPWM_t *flexpwm, int submodule, PhaseState state +) +{ + uint16_t submodule_mask = 1u << submodule; + uint16_t enable_a = FLEXPWM_OUTEN_PWMA_EN( submodule_mask ); + uint16_t enable_b = FLEXPWM_OUTEN_PWMB_EN( submodule_mask ); + + switch ( state ) + { + case PhaseState::PHASE_OFF: + flexpwm->OUTEN &= ~( enable_a | enable_b ); + break; + case PhaseState::PHASE_HI: + flexpwm->OUTEN |= enable_a; + flexpwm->OUTEN &= ~enable_b; + break; + case PhaseState::PHASE_LO: + flexpwm->OUTEN &= ~enable_a; + flexpwm->OUTEN |= enable_b; + break; + case PhaseState::PHASE_ON: + default: + flexpwm->OUTEN |= ( enable_a | enable_b ); + break; + } +} // function setting the pwm duty cycle to the hardware // - Stepper motor - 6PWM setting // - hardware specific void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void* params){ - Teensy4DriverParams* p = (Teensy4DriverParams*)((TeensyDriverParams*)params)->additional_params; - _UNUSED(phase_state); - write_pwm_pair (p->flextimers[0], p->submodules[0], dc_a); - write_pwm_pair (p->flextimers[1], p->submodules[1], dc_b); - write_pwm_pair (p->flextimers[2], p->submodules[2], dc_c); + Teensy4DriverParams *p = (Teensy4DriverParams *)( (TeensyDriverParams *)params )->additional_params; + + PhaseState phase_a = phase_state ? phase_state[ 0 ] : PhaseState::PHASE_ON; + PhaseState phase_b = phase_state ? phase_state[ 1 ] : PhaseState::PHASE_ON; + PhaseState phase_c = phase_state ? phase_state[ 2 ] : PhaseState::PHASE_ON; + + if ( PhaseState::PHASE_OFF == phase_a ) + dc_a = 0.0f; + if ( PhaseState::PHASE_OFF == phase_b ) + dc_b = 0.0f; + if ( PhaseState::PHASE_OFF == phase_c ) + dc_c = 0.0f; + + _teensy4_apply_phase_state( p->flextimers[ 0 ], p->submodules[ 0 ], phase_a ); + _teensy4_apply_phase_state( p->flextimers[ 1 ], p->submodules[ 1 ], phase_b ); + _teensy4_apply_phase_state( p->flextimers[ 2 ], p->submodules[ 2 ], phase_c ); + + write_pwm_pair( p->flextimers[ 0 ], p->submodules[ 0 ], dc_a ); + write_pwm_pair( p->flextimers[ 1 ], p->submodules[ 1 ], dc_b ); + write_pwm_pair( p->flextimers[ 2 ], p->submodules[ 2 ], dc_c ); } void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channel, float duty)