8000 STM32: Rework LSE clock init, allow clock overrides by hierophect · Pull Request #3009 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

STM32: Rework LSE clock init, allow clock overrides #3009

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

Merged
merged 3 commits into from
Jun 8, 2020
Merged

STM32: Rework LSE clock init, allow clock overrides #3009

merged 3 commits into from
Jun 8, 2020

Conversation

hierophect
Copy link
Collaborator
@hierophect hierophect commented Jun 4, 2020

This PR significantly reworks the STM32 clock system, moving all LSE related settings to the peripherals directory, and streamlining clock settings across all development boards. Resolves a number of crashes that could occur across dev boards due to incorrect LSE setup, and adds LSE capability to the F7 and H7 chip families.

The restructuring of the clock system merges the clock setup of all SoCs in a family, reducing chip-line differences and defaults to macros only. Also introduces the ability for boards to override their frequency settings in the mpconfigboard.h profile, for cases where a user needs to reduce frequency operation to match a certain on-board peripheral or achieve better low-power performance.

Other changes:

  • removes redundant OSC_DIV setting
  • Raises the frequency of a number of boards to the maximum, including all F411 boards and F743 boards
  • Allows boards to use a separate PLL for USB when possible
  • Sets STM32 dev boards to use the BYPASS setting for the HSE, which may have been causing unnoticed stability issues
  • Correctly lists the presence or absence of LSE oscillators on all development boards. Boards will experience a traceable crash if the LSE oscillator settings are incorrect.
  • EDIT: now also overrides HAL_Delay and HAL_GetTick, and turns off SysTick immediately after PortInit so that low power operation works as intended, without needing to call Microcontroller.

Tested on: Feather F405, Discovery F412, Open MV H7, Nucleo F767. Any additional testing is greatly appreciated!

Resolves #2886
Resolves #3010
Older related temporary-fix PRs: #2866, #2979
Original low power PR: #2685

@hierophect hierophect requested review from tannewt, k0d and jepler June 4, 2020 17:24
@hierophect hierophect added the stm label Jun 4, 2020
Copy link
@jepler jepler left a comment

Choose a reason for hiding this comment

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

I concentrated on the parts relevant to the STM32F405 Feather and didn't see any problems.

I initially thought there was something functionally wrong about the code, because I merged it into my SDIO branch and got I/O errors. However, I am now seeing these I/O errors with the current tip of that PR's branch, so they do not seem to be due to this PR's changes after all.

@hierophect
Copy link
Collaborator Author
hierophect commented Jun 5, 2020

Now overrides HAL_Delay and HAL_GetTick, replacing the HAL Systick with a port.c static variable systick_ms. Systick is used for the RTC and RCC clock setup, and then disabled at the end of port_init, after which @tannewt's system tick takes over. Tested on Feather F405.

@hierophect hierophect requested a review from jepler June 5, 2020 15:55
Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Overall a really good cleanup. Just a couple questions and two boards that fail to build.

#define HSE_VALUE ((uint32_t)25000000)
#define BOARD_OSC_PLLN (400)
#define BOARD_OSC_PLLQ (9)
// Lower frequency to allow external RAM use
Copy link
Member

Choose a reason for hiding this comment

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

8000

Please explain this further. What clock needs to be lower to use external RAM? Why?

Copy link
Collaborator Author
@hierophect hierophect Jun 5, 2020

Choose a reason for hiding this comment

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

@tannewt this is @k0d's deal, I don't know much about it. I just edited his macros to match style.

@hierophect
Copy link
Collaborator Author

@tannewt CI failure was just a silly typo. I think the HAL timing thing shouldn't be an issue, so pending whether you'd like a better comment for @k0d's board I think this is good to go.

@hierophect hierophect requested a review from tannewt June 5, 2020 18:31
Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Great! Thank you!

@tannewt tannewt merged commit 004d644 into adafruit:master Jun 8, 2020
@hierophect hierophect deleted the stm32-LSE-startup-fix branch June 8, 2020 15:08
@hierophect hierophect restored the stm32-LSE-startup-fix branch June 9, 2020 15:37
@hierophect hierophect deleted the stm32-LSE-startup-fix branch June 9, 2020 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STM32: HAL_Delay and HAL_GetTick can cause infinite hang STM32: LSE is not enabled on F7 or H7
3 participants
0