stm32u5x.cfg 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # script for stm32u5x family
  3. # stm32u5x devices support both JTAG and SWD transports.
  4. source [find target/swj-dp.tcl]
  5. source [find mem_helper.tcl]
  6. if { [info exists CHIPNAME] } {
  7. set _CHIPNAME $CHIPNAME
  8. } else {
  9. set _CHIPNAME stm32u5x
  10. }
  11. source [find target/stm32x5x_common.cfg]
  12. proc stm32u5x_clock_config {} {
  13. set offset [expr {[stm32x5x_is_secure] ? 0x10000000 : 0}]
  14. # MCU clock is at MSI 4MHz after reset, set MCU freq at 160 MHz with PLL
  15. # Enable voltage range 1 for frequency above 100 Mhz
  16. # RCC_AHB3ENR = PWREN
  17. mww [expr {0x46020C94 + $offset}] 0x00000004
  18. # delay for register clock enable (read back reg)
  19. mrw [expr {0x46020C94 + $offset}]
  20. # PWR_VOSR : VOS Range 1
  21. mmw [expr {0x4602080C + $offset}] 0x00030000 0
  22. # while !(PWR_VOSR & VOSRDY)
  23. while {!([mrw [expr {0x4602080C + $offset}]] & 0x00008000)} {}
  24. # FLASH_ACR : 4 WS for 160 MHz HCLK
  25. mww [expr {0x40022000 + $offset}] 0x00000004
  26. # RCC_PLL1CFGR => PLL1MBOOST=0, PLL1M=0=/1, PLL1FRACEN=0, PLL1SRC=MSI 4MHz
  27. # PLL1REN=1, PLL1RGE => VCOInputRange=PLLInputRange_4_8
  28. mww [expr {0x46020C28 + $offset}] 0x00040009
  29. # Enable EPOD Booster
  30. mmw [expr {0x4602080C + $offset}] 0x00040000 0
  31. # while !(PWR_VOSR & BOOSTRDY)
  32. while {!([mrw [expr {0x4602080C + $offset}]] & 0x00004000)} {}
  33. # RCC_PLL1DIVR => PLL1P=PLL1Q=PLL1R=000001=/2, PLL1N=0x4F=80
  34. # fVCO = 4 x 80 /1 = 320
  35. # SYSCLOCK = fVCO/PLL1R = 320/2 = 160 MHz
  36. mww [expr {0x46020C34 + $offset}] 0x0101024F
  37. # RCC_CR |= PLL1ON
  38. mmw [expr {0x46020C00 + $offset}] 0x01000000 0
  39. # while !(RCC_CR & PLL1RDY)
  40. while {!([mrw [expr {0x46020C00 + $offset}]] & 0x02000000)} {}
  41. # RCC_CFGR1 |= SW_PLL
  42. mmw [expr {0x46020C1C + $offset}] 0x00000003 0
  43. # while ((RCC_CFGR1 & SWS) != PLL)
  44. while {([mrw [expr {0x46020C1C + $offset}]] & 0x0C) != 0x0C} {}
  45. }
  46. $_TARGETNAME configure -event reset-init {
  47. stm32u5x_clock_config
  48. # Boost JTAG frequency
  49. adapter speed 4000
  50. }