rp2040.cfg 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # RP2040 is a microcontroller with dual Cortex-M0+ core.
  3. # https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html
  4. # The device requires multidrop SWD for debug.
  5. transport select swd
  6. source [find target/swj-dp.tcl]
  7. if { [info exists CHIPNAME] } {
  8. set _CHIPNAME $CHIPNAME
  9. } else {
  10. set _CHIPNAME rp2040
  11. }
  12. if { [info exists WORKAREASIZE] } {
  13. set _WORKAREASIZE $WORKAREASIZE
  14. } else {
  15. set _WORKAREASIZE 0x10000
  16. }
  17. if { [info exists CPUTAPID] } {
  18. set _CPUTAPID $CPUTAPID
  19. } else {
  20. set _CPUTAPID 0x01002927
  21. }
  22. # Set to '1' to start rescue mode
  23. if { [info exists RESCUE] } {
  24. set _RESCUE $RESCUE
  25. } else {
  26. set _RESCUE 0
  27. }
  28. # Set to '0' or '1' for single core configuration, 'SMP' for -rtos hwthread
  29. # handling of both cores, anything else for isolated debugging of both cores
  30. if { [info exists USE_CORE] } {
  31. set _USE_CORE $USE_CORE
  32. } else {
  33. set _USE_CORE SMP
  34. }
  35. set _BOTH_CORES [expr { $_USE_CORE != 0 && $_USE_CORE != 1 }]
  36. swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
  37. # The rescue debug port uses the DP CTRL/STAT bit DBGPWRUPREQ to reset the
  38. # PSM (power on state machine) of the RP2040 with a flag set in the
  39. # VREG_AND_POR_CHIP_RESET register. Once the reset is released
  40. # (by clearing the DBGPWRUPREQ flag), the bootrom will run, see this flag,
  41. # and halt. Allowing the user to load some fresh code, rather than loading
  42. # the potentially broken code stored in flash
  43. if { $_RESCUE } {
  44. dap create $_CHIPNAME.rescue_dap -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0xf -ignore-syspwrupack
  45. init
  46. # Clear DBGPWRUPREQ
  47. $_CHIPNAME.rescue_dap dpreg 0x4 0x00000000
  48. # Verifying CTRL/STAT is 0
  49. set _CTRLSTAT [$_CHIPNAME.rescue_dap dpreg 0x4]
  50. if {[expr {$_CTRLSTAT & 0xf0000000}]} {
  51. echo "Rescue failed, DP CTRL/STAT readback $_CTRLSTAT"
  52. } else {
  53. echo "Now restart OpenOCD without RESCUE flag and load code to RP2040"
  54. }
  55. shutdown
  56. }
  57. # core 0
  58. if { $_USE_CORE != 1 } {
  59. dap create $_CHIPNAME.dap0 -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0
  60. set _TARGETNAME_0 $_CHIPNAME.core0
  61. target create $_TARGETNAME_0 cortex_m -dap $_CHIPNAME.dap0 -coreid 0
  62. # srst does not exist; use SYSRESETREQ to perform a soft reset
  63. $_TARGETNAME_0 cortex_m reset_config sysresetreq
  64. }
  65. # core 1
  66. if { $_USE_CORE != 0 } {
  67. dap create $_CHIPNAME.dap1 -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 1
  68. set _TARGETNAME_1 $_CHIPNAME.core1
  69. target create $_TARGETNAME_1 cortex_m -dap $_CHIPNAME.dap1 -coreid 1
  70. $_TARGETNAME_1 cortex_m reset_config sysresetreq
  71. }
  72. if {[string compare $_USE_CORE SMP] == 0} {
  73. $_TARGETNAME_0 configure -rtos hwthread
  74. $_TARGETNAME_1 configure -rtos hwthread
  75. target smp $_TARGETNAME_0 $_TARGETNAME_1
  76. }
  77. if { $_USE_CORE == 1 } {
  78. set _FLASH_TARGET $_TARGETNAME_1
  79. } else {
  80. set _FLASH_TARGET $_TARGETNAME_0
  81. }
  82. # Backup the work area. The flash probe runs an algorithm on the target CPU.
  83. # The flash is probed during gdb connect if gdb_memory_map is enabled (by default).
  84. $_FLASH_TARGET configure -work-area-phys 0x20010000 -work-area-size $_WORKAREASIZE -work-area-backup 1
  85. set _FLASHNAME $_CHIPNAME.flash
  86. flash bank $_FLASHNAME rp2040_flash 0x10000000 0 0 0 $_FLASH_TARGET
  87. if { $_BOTH_CORES } {
  88. # Alias to ensure gdb connecting to core 1 gets the correct memory map
  89. flash bank $_CHIPNAME.alias virtual 0x10000000 0 0 0 $_TARGETNAME_1 $_FLASHNAME
  90. # Select core 0
  91. targets $_TARGETNAME_0
  92. }