Skip to content

Proposal: stm32: move oscillator + pll config to machine package #1750

@kenbell

Description

@kenbell

Problem

Currently, the pattern for STM32 MCUs is to do the oscillator and PLL configuration in the runtime package. This is causing a few issues:

  1. Declaration of magic values separate from the code that initializes the system frequency, e.g.: https://github.com/tinygo-org/tinygo/blob/dev/src/machine/machine_stm32l0.go#L13
  2. Lack of access to tick counter in machine package, leading to

Proposed Changes

  1. Move the initCLK (and where present initOSC) functions to machine package
  2. Move runtime_stm32_timers.go to machine package
  3. Make initCLK initialize: Oscillators, PLL, Timers

The runtime package would be responsible for calling initCLK (to preserve initialization order) as well as UART initialization / putchar

Bigger Picture

This would be the first of multiple steps to improve the clock frequency code:

  1. Move OSC, PLL code into machine package
  2. Specify external oscillator frequencies in board-specific files (HSE/LSE)
  3. Remove magic values, use calculated clock frequencies based on actual clock speed
  4. Remove arbitrary retry/tick counts in i2c/other driver logic, use calculated delays (more robust across chips with different clock frequencies)
  5. Harmonize the PLL & OSC initialization code (there's a few basic patterns)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions