stm32l5x.cfg 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # script for stm32l5x family
  3. # stm32l5x 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 stm32l5x
  10. }
  11. source [find target/stm32x5x_common.cfg]
  12. proc stm32l5x_clock_config {} {
  13. set offset [expr {[stm32x5x_is_secure] ? 0x10000000 : 0}]
  14. # MCU clock is MSI (4MHz) after reset, set MCU freq at 110 MHz with PLL
  15. # RCC_APB1ENR1 = PWREN
  16. mww [expr {0x40021058 + $offset}] 0x10000000
  17. # delay for register clock enable (read back reg)
  18. mrw [expr {0x40021058 + $offset}]
  19. # PWR_CR1 : VOS Range 0
  20. mww [expr {0x40007000 + $offset}] 0
  21. # while (PWR_SR2 & VOSF)
  22. while {([mrw [expr {0x40007014 + $offset}]] & 0x0400)} {}
  23. # FLASH_ACR : 5 WS for 110 MHz HCLK
  24. mww 0x40022000 0x00000005
  25. # RCC_PLLCFGR = PLLP=PLLQ=0, PLLR=00=2, PLLREN=1, PLLN=55, PLLM=0000=1, PLLSRC=MSI 4MHz
  26. # fVCO = 4 x 55 /1 = 220
  27. # SYSCLOCK = fVCO/PLLR = 220/2 = 110 MHz
  28. mww [expr {0x4002100C + $offset}] 0x01003711
  29. # RCC_CR |= PLLON
  30. mmw [expr {0x40021000 + $offset}] 0x01000000 0
  31. # while !(RCC_CR & PLLRDY)
  32. while {!([mrw [expr {0x40021000 + $offset}]] & 0x02000000)} {}
  33. # RCC_CFGR |= SW_PLL
  34. mmw [expr {0x40021008 + $offset}] 0x00000003 0
  35. # while ((RCC_CFGR & SWS) != PLL)
  36. while {([mrw [expr {0x40021008 + $offset}]] & 0x0C) != 0x0C} {}
  37. }
  38. $_TARGETNAME configure -event reset-init {
  39. stm32l5x_clock_config
  40. # Boost JTAG frequency
  41. adapter speed 4000
  42. }