Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(uart): HardwareSerial begin() causes Infinite Loop#2785

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 2 commits intostm32duino:mainfrombaftii:main
Sep 8, 2025

Conversation

@baftii
Copy link
Contributor

I found an issue while using HardwareSerial. Sometimes, when calling begin() function, the ClockPrescaler field inside huart->Init contains a garbage value. This wrong value is then passed to HAL_UART_Init(), and later used in UART_SetConfig() → UART_DIV_SAMPLING16() macro. When this happens, the MCU triggers an interrupt and get stuck in an infinite loop.

I didn't see this problem with every HardwareSerial instance. Although I couldn't exactly find what it depends on probably it is happening when the HardwareSerial object is a member of another class, and begin() is called from that class’s constructor.

I am using PlatformIO, but I replaced framework by Arduino Core STM32 version with the latest one from GitHub. I encountered this issue while using STM32H750VBT chip.

To solve this issue I added some functions and code blocks in uart.c and uart.h files.

  • Added clockPrescaler setter in uart_init() function for devices which support clockPrescaler for UART. However, while setting I needed value of connected Peripharel clock and clockPrescaler finder function.

  • Therefore, Added a function to calculate the correct ClockPrescaler based on the UART’s PCLK frequency.

  • Added a helper function to get the PCLK frequency. I inspected all the datasheets while making this function but I am newbie so that this function still needs more review and testing for different STM32 series.

Tried to make the solution generic. Changes passed from CI tool but review gonna be good.

Testing

  • I tested on STM32H750VBT6, and it worked.

Copy link
Member

@fpistmfpistm left a comment
edited
Loading

Choose a reason for hiding this comment

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

Hi@baftii
Thanks for this PR.
I've made a first round review with some proposal.
I will review the getPCLK deeply later.

@baftii
Copy link
ContributorAuthor

Hi, I looked at your proposals for the first review and commented on a few. However, I'm a bit new to PR, so I don't know if I need to do anything right now. Do I need to batch commit your proposed changes or call a resolve conversation for proposals? Or is that all handled by you?

@fpistm
Copy link
Member

Hi, I looked at your proposals for the first review and commented on a few. However, I'm a bit new to PR, so I don't know if I need to do anything right now. Do I need to batch commit your proposed changes or call a resolve conversation for proposals? Or is that all handled by you?

Simply update your code, commit and push on your branch then it will be updated here.

baftiiand others added2 commitsAugust 29, 2025 16:08
uartPCLK getter function added.Signed-off-by: Bartu Özcan <bartu.ozcan2004@gmail.com>
Signed-off-by: Bartu Özcan <bartu.ozcan2004@gmail.com>Co-authored-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm
Copy link
Member

fpistm commentedAug 29, 2025
edited
Loading

Hi@baftii
I've updated the PR:

  • rebased on main
  • harden the check of the computed prescaler
  • made the clock freq more generic and cover (I hope) all possible case.

I have to perform some tests next week. Anyway if you can have a look and tests on your side it would be fine.

@fpistmfpistm merged commitd35fec3 intostm32duino:mainSep 8, 2025
24 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fpistmfpistmfpistm left review comments

Assignees

No one assigned

Labels

fix 🩹Bug fix

Projects

Milestone

2.12.0

Development

Successfully merging this pull request may close these issues.

2 participants

@baftii@fpistm

[8]ページ先頭

©2009-2025 Movatter.jp