Skip to content

drivers: serial: stm32: return error for bad baud #92119

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edenfrosst
Copy link

The uart_stm32 driver gives no way for a user to tell if setting a new baud rate was successful.
Propagate error checks up to the API level.

Copy link

Hello @edenfrosst, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@github-actions github-actions bot added platform: STM32 ST Micro STM32 area: UART Universal Asynchronous Receiver-Transmitter labels Jun 24, 2025
@edenfrosst edenfrosst force-pushed the stm32-uart-baud-rate-error branch from 232d3eb to 8949a45 Compare June 24, 2025 20:06
@kartben kartben requested a review from Copilot June 24, 2025 20:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the STM32 serial driver to propagate errors when setting the baud rate, ensuring the API reflects possible failures during configuration.

  • Change uart_stm32_set_baudrate and uart_stm32_parameters_set to return error codes.
  • Propagate error checks in uart_stm32_configure and uart_stm32_registers_configure.
  • Update return statements to provide specific error codes for failure cases.
Comments suppressed due to low confidence (2)

drivers/serial/uart_stm32.c:184

  • The error code returned when the baud rate prescaler index is out of range differs from the error code used in uart_stm32_configure (-ENOTSUP) and uart_stm32_registers_configure (-EINVAL). Consider standardizing the error codes returned across functions for a more consistent API.
			return -EINVAL;

drivers/serial/uart_stm32.c:491

  • Since the return type of uart_stm32_parameters_set has been changed from void to int for error propagation, ensure that the function's documentation (comments or API docs) is updated to reflect this change.
static int uart_stm32_parameters_set(const struct device *dev,

Copy link
Collaborator

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Some minor comment and a free question.
Otherwise LGTM.

@edenfrosst edenfrosst force-pushed the stm32-uart-baud-rate-error branch from 8949a45 to 4631b47 Compare June 27, 2025 15:55
GeorgeCGV
GeorgeCGV previously approved these changes Jun 27, 2025
@erwango erwango added this to the v4.3.0 milestone Jun 30, 2025
etienne-lms
etienne-lms previously approved these changes Jun 30, 2025
@edenfrosst edenfrosst dismissed stale reviews from etienne-lms and GeorgeCGV via e4bc214 July 2, 2025 14:48
@edenfrosst edenfrosst force-pushed the stm32-uart-baud-rate-error branch from 4631b47 to e4bc214 Compare July 2, 2025 14:48
Copy link
Collaborator

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

LGTM.

Maybe could you fix the commit message header line:

-drivers: serial: stm32: return error for bad baud
+drivers: serial: stm32: return error for bad baud rate

or

drivers: serial: stm32: propagate baud rate config failure

The uart_stm32 driver gives no way for a user to
tell if setting a new baud rate was successful.
Propagate error checks up to the API level.

Signed-off-by: Eden Frosst <edenfrosst@gmail.com>
@edenfrosst edenfrosst force-pushed the stm32-uart-baud-rate-error branch from e4bc214 to 23e3549 Compare July 2, 2025 19:05
Copy link

sonarqubecloud bot commented Jul 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants