Skip to content

Conversation

@radekszewczyk01
Copy link

Change pwmbitseq_t structure

Description

Change pwmbitseq_t structure in order to optimize communication with multidriver

Motivation and Context

Multidriver required seperate message for each channel, which was inefficient.

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

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

Summary of Changes

Hello @radekszewczyk01, 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 primarily focuses on optimizing embedded system communication and driver efficiency. It introduces a more flexible structure for Pulse Width Modulation (PWM) bit sequences, allowing multiple sequences to be transmitted in a single operation to a multidriver. Concurrently, the UART 16550 driver has been refactored to remove an intermediate software buffer and simplify its interrupt handling mechanism, aiming for a more direct and efficient interaction with the hardware.

Highlights

  • PWM Bit Sequence Structure Optimization: The pwmbitseq_t structure has been refactored to support sending multiple PWM bit sequences in a single message, improving communication efficiency with the multidriver.
  • UART Driver Refactoring: The UART 16550 driver has undergone significant changes, including the removal of an internal software buffer and a simplification of interrupt handling logic, particularly for non-RISC-V architectures.
  • Streamlined Interrupt Processing: UART interrupt processing has been moved more directly into a dedicated thread (uart_intthr), reducing the complexity of the interrupt service routine and enabling more efficient data handling.
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.

Copy link

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

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 an optimization for PWM bit sequence handling by modifying the pwmbitseq_t structure to support multiple channels in a single message. It also includes a significant refactoring of the uart16550 driver, simplifying its interrupt handling logic. I've found a critical issue in the new PWM handling loop that includes a compile error and a logic bug that could mask errors. I've also noted some newly introduced macros that appear to be unused. Other changes, including style adjustments, seem appropriate.

Comment on lines 268 to 272
for (uint8_t i = 0; i < imsg->pwm_bitseq.count; i++) {
assert(imsg->bitseqTable[i]);
err = pwm_setBitSequence(imsg->pwm_bitseq.bitseqTable[i].timer, imsg->pwm_bitseq.bitseqTable[i].chn, imsg->pwm_bitseq.bitseqTable[i].data,
imsg->pwm_bitseq.bitseqTable[i].nbits, imsg->pwm_bitseq.bitseqTable[i].datasize, imsg->pwm_bitseq.bitseqTable[i].flags);
}

Choose a reason for hiding this comment

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

critical

This loop has a couple of issues:

  1. Compile Error: The assert on line 269 contains a typo (imsg->bitseqTable[i]). The correct member is imsg->pwm_bitseq.bitseqTable. This will prevent the code from compiling.
  2. Error Handling: The err variable is overwritten in each iteration. If pwm_setBitSequence() fails for any but the last item, the error will be lost, and the operation might be considered successful. The loop should terminate on the first error.

I suggest replacing the loop with a version that corrects the assertion and handles errors properly.

            if (imsg->pwm_bitseq.count > 0) {
                assert(imsg->pwm_bitseq.bitseqTable != NULL);
                for (uint8_t i = 0; i < imsg->pwm_bitseq.count; i++) {
                    err = pwm_setBitSequence(imsg->pwm_bitseq.bitseqTable[i].timer, imsg->pwm_bitseq.bitseqTable[i].chn, imsg->pwm_bitseq.bitseqTable[i].data,
                            imsg->pwm_bitseq.bitseqTable[i].nbits, imsg->pwm_bitseq.bitseqTable[i].datasize, imsg->pwm_bitseq.bitseqTable[i].flags);
                    if (err < 0) {
                        break;
                    }
                }
            }

Comment on lines 18 to 19
#define SIZE_SERIALS 2
#define SIZE_SERIAL_CHUNK 256

Choose a reason for hiding this comment

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

medium

These newly added macros, SIZE_SERIALS and SIZE_SERIAL_CHUNK, do not appear to be used in any of the files modified in this pull request. If they are not intended for immediate use, they should be removed to avoid clutter and potential confusion for future developers.

@github-actions
Copy link

github-actions bot commented Nov 18, 2025

Unit Test Results

9 462 tests  +16   8 873 ✅ +16   53m 11s ⏱️ + 1m 5s
  561 suites +16     589 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit d428f04. ± Comparison against base commit 4615adf.

♻️ This comment has been updated with latest results.

Copy link
Member

@nalajcie nalajcie left a comment

Choose a reason for hiding this comment

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

why there is some revert commit here without any rationale? (unrelated change)

lots of unnecessary reformatting (either make them a separate commit or revert)

Please make a meaningful PR title.

@radekszewczyk01 radekszewczyk01 force-pushed the radekszewczyk01/pwmbitseq_multi branch from 181e794 to 45e5e62 Compare November 19, 2025 06:56
@radekszewczyk01 radekszewczyk01 changed the title Radekszewczyk01/pwmbitseq multi stm32l4-multi: pwmbitseq_t refactor Nov 19, 2025
@radekszewczyk01 radekszewczyk01 marked this pull request as draft November 19, 2025 07:00
@radekszewczyk01 radekszewczyk01 force-pushed the radekszewczyk01/pwmbitseq_multi branch from 45e5e62 to 07a4fcf Compare November 19, 2025 07:06
@radekszewczyk01 radekszewczyk01 force-pushed the radekszewczyk01/pwmbitseq_multi branch from 07a4fcf to d428f04 Compare November 19, 2025 07:08
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.

3 participants