stm32l1.cfg 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. #
  3. # stm32l1 devices support both JTAG and SWD transports.
  4. #
  5. source [find target/swj-dp.tcl]
  6. source [find mem_helper.tcl]
  7. if { [info exists CHIPNAME] } {
  8. set _CHIPNAME $CHIPNAME
  9. } else {
  10. set _CHIPNAME stm32l1
  11. }
  12. set _ENDIAN little
  13. # Work-area is a space in RAM used for flash programming
  14. # By default use 10kB
  15. if { [info exists WORKAREASIZE] } {
  16. set _WORKAREASIZE $WORKAREASIZE
  17. } else {
  18. set _WORKAREASIZE 0x2800
  19. }
  20. # JTAG speed should be <= F_CPU/6.
  21. # F_CPU after reset is 2MHz, so use F_JTAG max = 333kHz
  22. adapter speed 300
  23. adapter srst delay 100
  24. if {[using_jtag]} {
  25. jtag_ntrst_delay 100
  26. }
  27. #jtag scan chain
  28. if { [info exists CPUTAPID] } {
  29. set _CPUTAPID $CPUTAPID
  30. } else {
  31. if { [using_jtag] } {
  32. # See STM Document RM0038
  33. # Section 30.6.3 - corresponds to Cortex-M3 r2p0
  34. set _CPUTAPID 0x4ba00477
  35. } else {
  36. # SWD IDCODE (single drop, arm)
  37. set _CPUTAPID 0x2ba01477
  38. }
  39. }
  40. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  41. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
  42. if {[using_jtag]} {
  43. jtag newtap $_CHIPNAME bs -irlen 5
  44. }
  45. set _TARGETNAME $_CHIPNAME.cpu
  46. target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
  47. $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  48. # flash size will be probed
  49. set _FLASHNAME $_CHIPNAME.flash
  50. flash bank $_FLASHNAME stm32lx 0x08000000 0 0 0 $_TARGETNAME
  51. reset_config srst_nogate
  52. if {![using_hla]} {
  53. # if srst is not fitted use SYSRESETREQ to
  54. # perform a soft reset
  55. cortex_m reset_config sysresetreq
  56. }
  57. proc stm32l_enable_HSI {} {
  58. # Enable HSI as clock source
  59. echo "STM32L: Enabling HSI"
  60. # Set HSION in RCC_CR
  61. mmw 0x40023800 0x00000101 0
  62. # Set HSI as SYSCLK
  63. mmw 0x40023808 0x00000001 0
  64. # Increase JTAG speed
  65. adapter speed 2000
  66. }
  67. $_TARGETNAME configure -event reset-init {
  68. stm32l_enable_HSI
  69. }
  70. $_TARGETNAME configure -event reset-start {
  71. adapter speed 300
  72. }
  73. $_TARGETNAME configure -event examine-end {
  74. # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
  75. mmw 0xE0042004 0x00000007 0
  76. # Stop watchdog counters during halt
  77. # DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
  78. mmw 0xE0042008 0x00001800 0
  79. }
  80. tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 0 -baseaddr 0xE0040000
  81. lappend _telnet_autocomplete_skip _proc_pre_enable_$_CHIPNAME.tpiu
  82. proc _proc_pre_enable_$_CHIPNAME.tpiu {_targetname} {
  83. targets $_targetname
  84. # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
  85. # change this value accordingly to configure trace pins
  86. # assignment
  87. mmw 0xE0042004 0x00000020 0
  88. }
  89. $_CHIPNAME.tpiu configure -event pre-enable "_proc_pre_enable_$_CHIPNAME.tpiu $_TARGETNAME"