Skip to content

stm32l4-multi: fix STM32N6 dshot driver to detect non DMA timers#597

Open
winderdoot wants to merge 1 commit into
masterfrom
kradzewicz/stm32n6_pwm
Open

stm32l4-multi: fix STM32N6 dshot driver to detect non DMA timers#597
winderdoot wants to merge 1 commit into
masterfrom
kradzewicz/stm32n6_pwm

Conversation

@winderdoot

Copy link
Copy Markdown
Contributor

JIRA: RTOS-1102

Small fix to include guarding against using a non DMA compatible TIMx peripheral for DSHOT.

Description

Motivation and Context

Types of changes

  • 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 change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (armv8m55-stm32n6-nucram).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @winderdoot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a crucial bug fix for the STM32N6 DSHOT driver by introducing a mechanism to ensure that DSHOT operations are only performed on timers that support Direct Memory Access (DMA). This prevents potential issues arising from attempting to use non-DMA compatible timers, thereby enhancing the robustness and reliability of the DSHOT functionality within the system.

Highlights

  • DMA Timer Identification: A new macro, PWM_TIM_DMA, has been introduced in pwm_n6.h to explicitly define which timers are capable of Direct Memory Access (DMA) for Pulse Width Modulation (PWM) operations.
  • DSHOT Driver Safeguard: A check has been added to the pwm_setBitSequence function in pwm_n6.c to prevent the DSHOT driver from attempting to use timers that are not DMA-compatible, returning an error (-EINVAL) if a non-DMA timer is selected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a safeguard in the STM32N6 DSHOT driver to prevent the use of timers that are not compatible with DMA. This is achieved by defining a PWM_TIM_DMA bitmask for DMA-capable timers and adding a validation check in pwm_setBitSequence. The change is logical and correctly placed to fail early. My review includes a suggestion to improve code style for better readability and maintainability by adhering to common line length conventions.

#define PWM_TIM_GP2 ((1 << pwm_tim9) | (1 << pwm_tim12) | (1 << pwm_tim15))
#define PWM_TIM_NO_MASTER_SLAVE ((1 << pwm_tim10) | (1 << pwm_tim11) | (1 << pwm_tim13) | (1 << pwm_tim14) | (1 << pwm_tim16) | (1 << pwm_tim17))
#define PWM_TIM_32BIT ((1 << pwm_tim2) | (1 << pwm_tim3) | (1 << pwm_tim4) | (1 << pwm_tim5))
#define PWM_TIM_DMA ((1 << pwm_tim1) | (1 << pwm_tim2) | (1 << pwm_tim3) | (1 << pwm_tim4) | (1 << pwm_tim5) | (1 << pwm_tim8) | (1 << pwm_tim15) | (1 << pwm_tim16) | (1 << pwm_tim17))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This line is very long and exceeds common style guide recommendations for line length (e.g., 80 or 100 characters), which can make the code harder to read and maintain. Consider splitting it across multiple lines for improved readability.

Suggested change
#define PWM_TIM_DMA ((1 << pwm_tim1) | (1 << pwm_tim2) | (1 << pwm_tim3) | (1 << pwm_tim4) | (1 << pwm_tim5) | (1 << pwm_tim8) | (1 << pwm_tim15) | (1 << pwm_tim16) | (1 << pwm_tim17))
#define PWM_TIM_DMA ((1 << pwm_tim1) | (1 << pwm_tim2) | (1 << pwm_tim3) | (1 << pwm_tim4) | (1 << pwm_tim5) | \
(1 << pwm_tim8) | (1 << pwm_tim15) | (1 << pwm_tim16) | (1 << pwm_tim17))

@github-actions

Copy link
Copy Markdown

Unit Test Results

9 433 tests  ±0   8 844 ✅ ±0   49m 12s ⏱️ +24s
  545 suites ±0     589 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 9dc257a. ± Comparison against base commit 8f4f81d.

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.

1 participant