Files
tinygo/src/runtime/runtime_stm32f469.go
T
Konstantin Sharlaimov 5f02d6b659 feat(machine/stm32): make HSE crystal frequency selectable.
Define the board's external crystal (HSE) frequency `xtalHz` in the
respective `board_*.go` files. Per-topology PLL tables (F1, F4, F7)
will compute the register dividers from it.

Moving this parameter to the board definition level cleanly isolates
board hardware characteristics from general MCU chip configurations,
eliminating the need for custom target build tags. Targets using
HSE-clocked STM32 chips must define `xtalHz` or fail to build.
2026-07-19 10:56:14 +02:00

30 lines
892 B
Go

//go:build stm32f4 && stm32f469
package runtime
import (
"device/stm32"
"machine"
)
/*
clock settings
+-------------+--------------------------------+
| HSE | selectable (xtal_8/12/16_mhz) |
| SYSCLK | 180mhz |
| HCLK | 180mhz |
| APB2(PCLK2) | 90mhz |
| APB1(PCLK1) | 45mhz |
+-------------+--------------------------------+
*/
const HSE_STARTUP_TIMEOUT = 0x0500
// pllCFGR builds the RCC_PLLCFGR value for the current xtal - see RM0386
// Reference Manual pg. 148.
func pllCFGR() uint32 {
pll := machine.PLLParams180MHz()
return pll.M | (pll.N << stm32.RCC_PLLCFGR_PLLN_Pos) | (((pll.P >> 1) - 1) << stm32.RCC_PLLCFGR_PLLP_Pos) |
(1 << stm32.RCC_PLLCFGR_PLLSRC_Pos) | (pll.Q << stm32.RCC_PLLCFGR_PLLQ_Pos) | (pll.R << stm32.RCC_PLLCFGR_PLLR_Pos)
}