stm32f3x.cfg 3.0 KB

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