Hi,
I'm trying to debug a custom board with a MKE02Z64VFM4 with the Kinetis Design Studio 2.0 and a CMSIS-DAP JTAG.
I'm facing an issue when downloading a simple application created with KDS "Create new project" wizard. The result is that the MKE02 cannot be programmed because " Cannot access device, device is secured. Mass erasing a device will unsecure it until the next reset. To permanently unsecure, mass erase then flash a program containing an appropriate flash configuration field.". And then KDS ends the debug session.
Note that working with KEIL uVision, with the same JTAG and a GPIO demo from Freescale, the MKE02 works OK and can be reached by the JTAG an debugged with no problems. But for other reasons I cannot develop the final project using KEIL.
This is the complete output from KDS, executing OpenOCD with the "-f kinetis.cfg --debug 4" parameters (full debug output). The bold at the end was added by me.
Open On-Chip Debugger 0.8.0-dev (2014-10-31-11:10)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html
User : 13 3 command.c:546 command_print(): debug_level: 3
Debug: 14 3 options.c:138 add_default_dirs(): pkgdatadir=/../
Debug: 15 3 options.c:139 add_default_dirs(): run_prefix=C:/Freescale/KDS_2.0.0/openocd/bin
Debug: 16 3 configuration.c:44 add_script_search_dir(): adding C:\Users\Utente\AppData\Roaming/OpenOCD
Debug: 17 4 configuration.c:44 add_script_search_dir(): adding C:/Freescale/KDS_2.0.0/openocd/bin/..//site
Debug: 18 409 configuration.c:44 add_script_search_dir(): adding C:/Freescale/KDS_2.0.0/openocd/bin/..//scripts
Debug: 19 409 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_gdb_port 3333
Debug: 20 410 command.c:145 script_debug(): command - gdb_port ocd_gdb_port 3333
Debug: 22 410 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_telnet_port 4444
Debug: 23 410 command.c:145 script_debug(): command - telnet_port ocd_telnet_port 4444
Debug: 25 411 configuration.c:84 find_file(): found C:/Freescale/KDS_2.0.0/openocd/bin/..//scripts/kinetis.cfg
Debug: 26 411 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_interface cmsis-dap
Debug: 27 412 command.c:145 script_debug(): command - interface ocd_interface cmsis-dap
Debug: 29 412 command.c:366 register_command_handler(): registering 'ocd_cmsis-dap'...
Debug: 30 412 command.c:366 register_command_handler(): registering 'ocd_cmsis_dap_vid_pid'...
Debug: 31 412 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 32 412 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 33 412 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 34 412 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 35 413 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 36 413 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 37 413 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 38 413 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Debug: 39 413 command.c:366 register_command_handler(): registering 'ocd_jtag'...
Info : 40 413 transport.c:118 allow_transports(): only one transport option; autoselect 'cmsis-dap'
Debug: 41 413 command.c:401 register_command(): command 'cmsis-dap' is already registered in '<global>' context
Debug: 42 414 command.c:366 register_command_handler(): registering 'ocd_cmsis-dap'...
Info : 43 433 cmsis_dap_usb.c:566 cmsis_dap_get_caps_info(): CMSIS-DAP: SWD Supported
Info : 44 433 cmsis_dap_usb.c:568 cmsis_dap_get_caps_info(): CMSIS-DAP: JTAG Supported
Info : 45 435 cmsis_dap_usb.c:843 cmsis_dap_swd_init(): CMSIS-DAP: Interface Initialised (SWD)
Debug: 46 435 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_cmsis-dap newdap kinetis cpu -irlen 4
Debug: 47 436 command.c:145 script_debug(): command - ocd_cmsis-dap ocd_cmsis-dap newdap kinetis cpu -irlen 4
Debug: 48 436 tcl.c:551 jim_newtap_cmd(): Creating New Tap, Chip: kinetis, Tap: cpu, Dotted: kinetis.cpu, 2 params
Debug: 49 436 tcl.c:568 jim_newtap_cmd(): Processing option: -irlen
Debug: 50 436 core.c:1319 jtag_tap_init(): Created Tap: kinetis.cpu @ abs position 0, irlen 4, capture: 0x1 mask: 0x3
Debug: 51 436 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target create kinetis.cpu cortex_m -chain-position kinetis.cpu
Debug: 52 437 command.c:145 script_debug(): command - ocd_target ocd_target create kinetis.cpu cortex_m -chain-position kinetis.cpu
Debug: 53 437 target.c:1716 target_free_all_working_areas_restore(): freeing all working areas
Debug: 54 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 55 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 56 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 57 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 58 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 59 437 command.c:366 register_command_handler(): registering 'ocd_arm'...
Debug: 60 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 61 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 62 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 63 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 64 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 65 438 command.c:366 register_command_handler(): registering 'ocd_dap'...
Debug: 66 438 command.c:366 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 67 439 command.c:366 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 68 439 command.c:366 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 69 439 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 70 439 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 71 439 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 72 439 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 73 439 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 74 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 75 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 76 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 77 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 78 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 79 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 80 440 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 81 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 82 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 83 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 84 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 85 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 86 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 87 441 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 88 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 89 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 90 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 91 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 92 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 93 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 94 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 95 442 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 96 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 97 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 98 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 99 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 100 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 101 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 102 443 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 103 444 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 104 444 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 105 444 command.c:366 register_command_handler(): registering 'ocd_kinetis.cpu'...
Debug: 106 444 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_kinetis.cpu configure -work-area-phys 0x20000000 -work-area-size 0x1000 -work-area-backup 0
Debug: 107 444 command.c:145 script_debug(): command - ocd_kinetis.cpu ocd_kinetis.cpu configure -work-area-phys 0x20000000 -work-area-size 0x1000 -work-area-backup 0
Debug: 108 445 target.c:1716 target_free_all_working_areas_restore(): freeing all working areas
Debug: 109 445 target.c:1716 target_free_all_working_areas_restore(): freeing all working areas
Debug: 110 445 target.c:1716 target_free_all_working_areas_restore(): freeing all working areas
Debug: 111 445 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_flash bank kinetis.flash kinetis 0 0 0 0 kinetis.cpu
Debug: 112 446 command.c:145 script_debug(): command - ocd_flash ocd_flash bank kinetis.flash kinetis 0 0 0 0 kinetis.cpu
Info : 114 446 kinetis.c:249 kinetis_flash_bank_command(): add flash_bank kinetis kinetis.flash
Debug: 115 446 command.c:366 register_command_handler(): registering 'ocd_fcf_write_enable'...
Debug: 116 446 command.c:366 register_command_handler(): registering 'ocd_fcf_write_disable'...
Debug: 117 446 tcl.c:807 handle_flash_bank_command(): 'kinetis' driver usage field missing
Debug: 118 446 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_cortex_m reset_config sysresetreq
Debug: 119 447 command.c:145 script_debug(): command - ocd_cortex_m ocd_cortex_m reset_config sysresetreq
User : 121 447 command.c:546 command_print(): cortex_m reset_config sysresetreq
Debug: 122 447 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_adapter_khz 1000
Debug: 123 447 command.c:145 script_debug(): command - adapter_khz ocd_adapter_khz 1000
Debug: 125 447 core.c:1644 jtag_config_khz(): handle jtag khz
Debug: 126 447 core.c:1611 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 127 447 core.c:1611 adapter_khz_to_speed(): convert khz to interface specific speed value
User : 128 448 command.c:546 command_print(): adapter speed: 1000 kHz
Debug: 129 448 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_kinetis.cpu configure -event gdb-attach
halt
Debug: 130 448 command.c:145 script_debug(): command - ocd_kinetis.cpu ocd_kinetis.cpu configure -event gdb-attach
halt
Debug: 131 449 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_init
Debug: 132 449 command.c:145 script_debug(): command - init ocd_init
Debug: 134 449 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_target init
Debug: 135 449 command.c:145 script_debug(): command - ocd_target ocd_target init
Debug: 137 450 target.c:1279 handle_target_init_command(): Initializing targets...
Debug: 138 450 command.c:366 register_command_handler(): registering 'ocd_target_request'...
Debug: 139 450 command.c:366 register_command_handler(): registering 'ocd_trace'...
Debug: 140 450 command.c:366 register_command_handler(): registering 'ocd_trace'...
Debug: 141 450 command.c:366 register_command_handler(): registering 'ocd_fast_load_image'...
Debug: 142 450 command.c:366 register_command_handler(): registering 'ocd_fast_load'...
Debug: 143 451 command.c:366 register_command_handler(): registering 'ocd_profile'...
Debug: 144 451 command.c:366 register_command_handler(): registering 'ocd_virt2phys'...
Debug: 145 451 command.c:366 register_command_handler(): registering 'ocd_reg'...
Debug: 146 451 command.c:366 register_command_handler(): registering 'ocd_poll'...
Debug: 147 451 command.c:366 register_command_handler(): registering 'ocd_wait_halt'...
Debug: 148 451 command.c:366 register_command_handler(): registering 'ocd_halt'...
Debug: 149 451 command.c:366 register_command_handler(): registering 'ocd_resume'...
Debug: 150 452 command.c:366 register_command_handler(): registering 'ocd_reset'...
Debug: 151 452 command.c:366 register_command_handler(): registering 'ocd_soft_reset_halt'...
Debug: 152 452 command.c:366 register_command_handler(): registering 'ocd_step'...
Debug: 153 452 command.c:366 register_command_handler(): registering 'ocd_mdw'...
Debug: 154 452 command.c:366 register_command_handler(): registering 'ocd_mdh'...
Debug: 155 452 command.c:366 register_command_handler(): registering 'ocd_mdb'...
Debug: 156 452 command.c:366 register_command_handler(): registering 'ocd_mww'...
Debug: 157 452 command.c:366 register_command_handler(): registering 'ocd_mwh'...
Debug: 158 453 command.c:366 register_command_handler(): registering 'ocd_mwb'...
Debug: 159 453 command.c:366 register_command_handler(): registering 'ocd_bp'...
Debug: 160 453 command.c:366 register_command_handler(): registering 'ocd_rbp'...
Debug: 161 453 command.c:366 register_command_handler(): registering 'ocd_wp'...
Debug: 162 453 command.c:366 register_command_handler(): registering 'ocd_rwp'...
Debug: 163 453 command.c:366 register_command_handler(): registering 'ocd_load_image'...
Debug: 164 453 command.c:366 register_command_handler(): registering 'ocd_dump_image'...
Debug: 165 454 command.c:366 register_command_handler(): registering 'ocd_verify_image'...
Debug: 166 454 command.c:366 register_command_handler(): registering 'ocd_test_image'...
Debug: 167 454 command.c:366 register_command_handler(): registering 'ocd_reset_nag'...
Debug: 168 454 command.c:366 register_command_handler(): registering 'ocd_ps'...
Debug: 169 454 command.c:366 register_command_handler(): registering 'ocd_test_mem_access'...
Info : 170 456 cmsis_dap_usb.c:546 cmsis_dap_get_version_info(): CMSIS-DAP: FW Version = 1.0
Debug: 171 458 cmsis_dap_usb.c:756 cmsis_dap_init(): CMSIS-DAP: Packet Size = 64
Debug: 172 460 cmsis_dap_usb.c:767 cmsis_dap_init(): CMSIS-DAP: Packet Count = 64
Info : 173 462 cmsis_dap_usb.c:587 cmsis_dap_get_status(): SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Debug: 174 470 cmsis_dap_usb.c:597 cmsis_dap_reset_link(): CMSIS-DAP: cmsis_dap_reset_link
Info : 175 470 cmsis_dap_usb.c:598 cmsis_dap_reset_link(): DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Debug: 176 483 cmsis_dap_usb.c:690 cmsis_dap_reset_link(): DAP Write Abort
Debug: 177 486 cmsis_dap_usb.c:699 cmsis_dap_reset_link(): Result 0x00
Info : 178 488 cmsis_dap_usb.c:809 cmsis_dap_init(): CMSIS-DAP: Interface ready
Debug: 179 488 core.c:1611 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 180 488 core.c:1614 adapter_khz_to_speed(): have interface set up
Debug: 181 490 core.c:1611 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 182 490 core.c:1614 adapter_khz_to_speed(): have interface set up
Info : 183 490 core.c:1400 adapter_init(): clock speed 1000 kHz
Debug: 184 490 openocd.c:132 handle_init_command(): Debug Adapter init complete
Debug: 185 490 command.c:145 script_debug(): command - ocd_command ocd_command type ocd_transport init
Debug: 186 491 command.c:145 script_debug(): command - ocd_transport ocd_transport init
Debug: 188 491 transport.c:240 handle_transport_init(): handle_transport_init
Info : 189 493 adi_v5_cmsis_dap.c:315 cmsis_dap_init(): IDCODE 0x0bc11477
Debug: 190 497 core.c:717 jtag_add_reset(): SRST line released
Debug: 191 497 core.c:741 jtag_add_reset(): TRST line released
Debug: 192 497 core.c:321 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 193 497 openocd.c:145 handle_init_command(): Examining targets...
Debug: 194 497 target.c:1395 target_call_event_callbacks(): target event 21 (examine-start)
Debug: 195 497 arm_adi_v5.c:764 ahbap_debugport_init():
Debug: 196 499 adi_v5_cmsis_dap.c:103 cmsis_dap_queue_dp_write(): disabling overrun detection
Debug: 197 503 adi_v5_cmsis_dap.c:103 cmsis_dap_queue_dp_write(): disabling overrun detection
Debug: 198 509 adi_v5_cmsis_dap.c:103 cmsis_dap_queue_dp_write(): disabling overrun detection
Debug: 199 521 arm_adi_v5.c:866 ahbap_debugport_init(): MEM_AP Packed Transfers: disabled
Debug: 200 527 target.c:2104 target_read_u8(): address: 0x0000040c, value: 0xff
Error: 201 527 cortex_m.c:1807 cortex_m_examine(): Cannot access device, device is secured
Info : 202 527 cortex_m.c:1810 cortex_m_examine(): Mass erasing a device will unsecure it until the next reset. To permanently unsecure, mass erase then flash a program containing an appropriate flash configuration field.
Trying to understand more I've downloaded the KDS 2.0 source code (http://cache.freescale.com/lgfiles/KDS/KDS-v2.0.0-source-files.zip?fpsp=1&WT_TYPE=IDE%20-%20Debug,%2...) to see the modifications Freescale has made to OpenOCD to enable MKE devices support.
Looking at the patch file openocd-0b26376_kds-2.0.0.patch I've noticed that OpenOCD was modified to do the following:
retval = target_read_u8(target, FSEC, &fsec);
if (retval != ERROR_OK) {
LOG_ERROR("Cannot read FSEC. Device may be secured");
LOG_INFO("Mass erasing a device will unsecure it until the next reset. "
"To permanently unsecure, mass erase then flash a "
"program containing an appropriate flash configuration field.");
exit(-1);
}
else if ((fsec & 0x3) != 0x2) {
LOG_ERROR("Cannot access device, device is secured");
LOG_INFO("Mass erasing a device will unsecure it until the next reset. "
"To permanently unsecure, mass erase then flash a "
"program containing an appropriate flash configuration field.");
exit(-1);
}
But FSEC, on the same patch, is defined as
#define FSEC 0x0000040C
I know other Kinetis devices have the Flash Security Byte located at 0x40C, but for the MKE02 it's different:

So the question is: Is KDS 2.0 enabled to debug MKE02 devices with OpenOCD with CMSIS-DAP?
Has anyone managed to work and debug with said configuration?
Thank you.