stm32f3x.cfg 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # script for stm32f3x family
  3. #
  4. # stm32 devices support both JTAG and SWD transports.
  5. #
  6. source [find target/swj-dp.tcl]
  7. source [find mem_helper.tcl]
  8. if { [info exists CHIPNAME] } {
  9. set _CHIPNAME $CHIPNAME
  10. } else {
  11. set _CHIPNAME stm32f3x
  12. }
  13. set _ENDIAN little
  14. # Work-area is a space in RAM used for flash programming
  15. # By default use 16kB
  16. if { [info exists WORKAREASIZE] } {
  17. set _WORKAREASIZE $WORKAREASIZE
  18. } else {
  19. set _WORKAREASIZE 0x4000
  20. }
  21. # Allow overriding the Flash bank size
  22. if { [info exists FLASH_SIZE] } {
  23. set _FLASH_SIZE $FLASH_SIZE
  24. } else {
  25. # autodetect size
  26. set _FLASH_SIZE 0
  27. }
  28. # JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
  29. #
  30. # Since we may be running of an RC oscilator, we crank down the speed a
  31. # bit more to be on the safe side. Perhaps superstition, but if are
  32. # running off a crystal, we can run closer to the limit. Note
  33. # that there can be a pretty wide band where things are more or less stable.
  34. adapter speed 1000
  35. adapter srst delay 100
  36. if {[using_jtag]} {
  37. jtag_ntrst_delay 100
  38. }
  39. #jtag scan chain
  40. if { [info exists CPUTAPID] } {
  41. set _CPUTAPID $CPUTAPID
  42. } else {
  43. if { [using_jtag] } {
  44. # See STM Document RM0316
  45. # Section 29.6.3 - corresponds to Cortex-M4 r0p1
  46. set _CPUTAPID 0x4ba00477
  47. } {
  48. set _CPUTAPID 0x2ba01477
  49. }
  50. }
  51. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  52. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
  53. if {[using_jtag]} {
  54. jtag newtap $_CHIPNAME bs -irlen 5
  55. }
  56. set _TARGETNAME $_CHIPNAME.cpu
  57. target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
  58. $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  59. set _FLASHNAME $_CHIPNAME.flash
  60. flash bank $_FLASHNAME stm32f1x 0 $_FLASH_SIZE 0 0 $_TARGETNAME
  61. reset_config srst_nogate
  62. if {![using_hla]} {
  63. # if srst is not fitted use SYSRESETREQ to
  64. # perform a soft reset
  65. cortex_m reset_config sysresetreq
  66. }
  67. proc stm32f3x_default_reset_start {} {
  68. # Reset clock is HSI (8 MHz)
  69. adapter speed 1000
  70. }
  71. proc stm32f3x_default_examine_end {} {
  72. # Enable debug during low power modes (uses more power)
  73. mmw 0xe0042004 0x00000007 0 ;# DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
  74. # Stop watchdog counters during halt
  75. mmw 0xe0042008 0x00001800 0 ;# DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
  76. }
  77. proc stm32f3x_default_reset_init {} {
  78. # Configure PLL to boost clock to HSI x 8 (64 MHz)
  79. mww 0x40021004 0x00380400 ;# RCC_CFGR = PLLMUL[3:1] | PPRE1[2]
  80. mmw 0x40021000 0x01000000 0 ;# RCC_CR |= PLLON
  81. mww 0x40022000 0x00000012 ;# FLASH_ACR = PRFTBE | LATENCY[1]
  82. sleep 10 ;# Wait for PLL to lock
  83. mmw 0x40021004 0x00000002 0 ;# RCC_CFGR |= SW[1]
  84. # Boost JTAG frequency
  85. adapter speed 8000
  86. }
  87. # Default hooks
  88. $_TARGETNAME configure -event examine-end { stm32f3x_default_examine_end }
  89. $_TARGETNAME configure -event reset-start { stm32f3x_default_reset_start }
  90. $_TARGETNAME configure -event reset-init { stm32f3x_default_reset_init }
  91. tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 0 -baseaddr 0xE0040000
  92. lappend _telnet_autocomplete_skip _proc_pre_enable_$_CHIPNAME.tpiu
  93. proc _proc_pre_enable_$_CHIPNAME.tpiu {_targetname} {
  94. targets $_targetname
  95. # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
  96. # change this value accordingly to configure trace pins
  97. # assignment
  98. mmw 0xe0042004 0x00000020 0
  99. }
  100. $_CHIPNAME.tpiu configure -event pre-enable "_proc_pre_enable_$_CHIPNAME.tpiu $_TARGETNAME"