nrf52.cfg 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #
  2. # Nordic nRF52 series: ARM Cortex-M4 @ 64 MHz
  3. #
  4. source [find target/swj-dp.tcl]
  5. if { [info exists CHIPNAME] } {
  6. set _CHIPNAME $CHIPNAME
  7. } else {
  8. set _CHIPNAME nrf52
  9. }
  10. # Work-area is a space in RAM used for flash programming
  11. # By default use 16kB
  12. if { [info exists WORKAREASIZE] } {
  13. set _WORKAREASIZE $WORKAREASIZE
  14. } else {
  15. set _WORKAREASIZE 0x4000
  16. }
  17. if { [info exists CPUTAPID] } {
  18. set _CPUTAPID $CPUTAPID
  19. } else {
  20. set _CPUTAPID 0x2ba01477
  21. }
  22. swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
  23. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
  24. set _TARGETNAME $_CHIPNAME.cpu
  25. target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap
  26. adapter speed 1000
  27. $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  28. if { [using_hla] } {
  29. echo ""
  30. echo "nRF52 device has a CTRL-AP dedicated to recover the device from AP lock."
  31. echo "A high level adapter (like a ST-Link) you are currently using cannot access"
  32. echo "the CTRL-AP so 'nrf52_recover' command will not work."
  33. echo "Do not enable UICR APPROTECT."
  34. echo ""
  35. } else {
  36. cortex_m reset_config sysresetreq
  37. $_TARGETNAME configure -event examine-fail nrf52_check_ap_lock
  38. }
  39. flash bank $_CHIPNAME.flash nrf5 0x00000000 0 1 1 $_TARGETNAME
  40. flash bank $_CHIPNAME.uicr nrf5 0x10001000 0 1 1 $_TARGETNAME
  41. # Test if MEM-AP is locked by UICR APPROTECT
  42. proc nrf52_check_ap_lock {} {
  43. set dap [[target current] cget -dap]
  44. set err [catch {set APPROTECTSTATUS [$dap apreg 1 0xc]}]
  45. if {$err == 0 && $APPROTECTSTATUS != 1} {
  46. echo "****** WARNING ******"
  47. echo "nRF52 device has AP lock engaged (see UICR APPROTECT register)."
  48. echo "Debug access is denied."
  49. echo "Use 'nrf52_recover' to erase and unlock the device."
  50. echo ""
  51. poll off
  52. }
  53. }
  54. # Mass erase and unlock the device using proprietary nRF CTRL-AP (AP #1)
  55. # http://www.ebyte.com produces modules with nRF52 locked by default,
  56. # use nrf52_recover to enable flashing and debug.
  57. proc nrf52_recover {} {
  58. set target [target current]
  59. set dap [$target cget -dap]
  60. set IDR [$dap apreg 1 0xfc]
  61. if {$IDR != 0x02880000} {
  62. echo "Error: Cannot access nRF52 CTRL-AP!"
  63. return
  64. }
  65. poll off
  66. # Reset and trigger ERASEALL task
  67. $dap apreg 1 4 0
  68. $dap apreg 1 4 1
  69. for {set i 0} {1} {incr i} {
  70. set ERASEALLSTATUS [$dap apreg 1 8]
  71. if {$ERASEALLSTATUS == 0} {
  72. echo "$target device has been successfully erased and unlocked."
  73. break
  74. }
  75. if {$i == 0} {
  76. echo "Waiting for chip erase..."
  77. }
  78. if {$i >= 150} {
  79. echo "Error: $target recovery failed."
  80. break
  81. }
  82. sleep 100
  83. }
  84. # Assert reset
  85. $dap apreg 1 0 1
  86. # Deassert reset
  87. $dap apreg 1 0 0
  88. # Reset ERASEALL task
  89. $dap apreg 1 4 0
  90. sleep 100
  91. $target arp_examine
  92. poll on
  93. }
  94. add_help_text nrf52_recover "Mass erase and unlock nRF52 device"