Discussion:
[OpenOCD-devel] "flash erase_sector" fails with KL27Z
Florian Uekermann
2017-04-21 14:52:31 UTC
Permalink
Hi everyone,

"flash erase_sector" fails with my Kinetis L 27Z (kl27z) via ST-Link/V2.
This prevents programming.

Command:
openocd -d3 -f interface/stlink-v2.cfg -f target/klx.cfg -c "init; reset
halt; flash erase_sector 0 0 15"

Full output: https://pastebin.com/UnmyDQ0t

I guess the interesting part of the output is:
GNU ARM Eclipse 64-bits Open On-Chip Debugger 0.10.0-00114-g8419536
(2017-04-18-22:28)
<snip>
Debug: 458 37 command.c:143 script_debug(): command - ocd_flash
ocd_flash erase_sector 0 0 15
Debug: 460 37 hla_target.c:750 adapter_read_memory():
adapter_read_memory 0x40048024 4 1
Debug: 461 37 target.c:2240 target_read_u32(): address: 0x40048024,
value: 0x23161d82
Debug: 462 37 hla_target.c:750 adapter_read_memory():
adapter_read_memory 0x4004804c 4 1
Debug: 463 38 target.c:2240 target_read_u32(): address: 0x4004804c,
value: 0x09000000
Debug: 464 38 hla_target.c:750 adapter_read_memory():
adapter_read_memory 0x40048050 4 1
Debug: 465 38 target.c:2240 target_read_u32(): address: 0x40048050,
value: 0x10900000
Debug: 466 38 kinetis.c:1765 kinetis_probe(): SDID: 0x23161D82 FCFG1:
0x09000000 FCFG2: 0x10900000
Debug: 467 38 kinetis.c:1884 kinetis_probe(): FlexNVM: 0 PFlash: 262144
FlexRAM: 0 PFLSH: 1
Debug: 468 38 kinetis.c:1891 kinetis_probe(): 2 blocks total: 2 PFlash,
0 FlexNVM
Info : 469 38 kinetis.c:1893 kinetis_probe(): Probing flash info for bank 0
Debug: 470 38 hla_target.c:750 adapter_read_memory():
adapter_read_memory 0x4007e003 1 1
Debug: 471 39 target.c:2286 target_read_u8(): address: 0x4007e003,
value: 0x01
Debug: 472 39 hla_target.c:750 adapter_read_memory():
adapter_read_memory 0x40020000 1 1
Debug: 473 39 target.c:2286 target_read_u8(): address: 0x40020000,
value: 0x80
Debug: 474 39 hla_target.c:764 adapter_write_memory():
adapter_write_memory 0x40020004 4 3
Debug: 475 40 target.c:2368 target_write_u8(): address: 0x40020000,
value: 0x80
Debug: 476 40 hla_target.c:764 adapter_write_memory():
adapter_write_memory 0x40020000 1 1
Debug: 477 40 stlink_usb.c:407 stlink_usb_error_check(): Verify error
Debug: 478 40 target.c:2372 target_write_u8(): failed: -4
Warn : 479 40 kinetis.c:1223 kinetis_erase(): erase sector 0 failed
Error: 480 40 core.c:45 flash_driver_erase(): failed erasing sectors 0 to 15

Best regards,
Florian
Tomas Vanek
2017-04-21 18:46:06 UTC
Permalink
Post by Florian Uekermann
Hi everyone,
"flash erase_sector" fails with my Kinetis L 27Z (kl27z) via ST-Link/V2.
This prevents programming.
openocd -d3 -f interface/stlink-v2.cfg -f target/klx.cfg -c "init; reset
halt; flash erase_sector 0 0 15"
Please do not use ST-Link for NXP Kinetis flash programming.

1) It is quite easy to lock a Kinetis device into secure mode.
A high level adapter like ST-Link can not issue mass erase to unlock the
device.

2) ST-Link unlike other adapters triggers a verify error on every clear
of a 'w1c' bit in a register (write one to clear). Also a write to other
registers
with some read-only bits can do the same.

3) ST-Link does not implement 16-bit read/writes.

I recommend you to use a CMSIS-DAP, J-Link or a FTDI based adapter for
Kinetis.

Tom
Florian Uekermann
2017-04-22 12:25:01 UTC
Permalink
Post by Tomas Vanek
Please do not use ST-Link for NXP Kinetis flash programming.
1) It is quite easy to lock a Kinetis device into secure mode.
A high level adapter like ST-Link can not issue mass erase to unlock the
device.
Thanks for the advice Tom. I ordered a CMSIS-DAP based adapter. Due to slow mail service where I live, I'm stuck with ST-Link/V2 for a while, so it would be nice to be able to erase the flash somehow.
Post by Tomas Vanek
2) ST-Link unlike other adapters triggers a verify error on every clear
of a 'w1c' bit in a register (write one to clear). Also a write to other
registers
with some read-only bits can do the same.
Any way to work around that? Is it possible to ignore the verify error and clear the memory?

Best regards,
Florian
Tomas Vanek
2017-04-22 13:34:25 UTC
Permalink
Post by Florian Uekermann
Post by Tomas Vanek
Please do not use ST-Link for NXP Kinetis flash programming.
1) It is quite easy to lock a Kinetis device into secure mode.
A high level adapter like ST-Link can not issue mass erase to unlock the
device.
Thanks for the advice Tom. I ordered a CMSIS-DAP based adapter. Due to slow mail service where I live, I'm stuck with ST-Link/V2 for a while, so it would be nice to be able to erase the flash somehow.
Post by Tomas Vanek
2) ST-Link unlike other adapters triggers a verify error on every clear
of a 'w1c' bit in a register (write one to clear). Also a write to other
registers
with some read-only bits can do the same.
Any way to work around that? Is it possible to ignore the verify error and clear the memory?
If you can compile OpenOCD from source, try change
src/jtag/drivers/stlink_usb.c line 408

case STLINK_JTAG_WRITE_VERIF_ERROR:
LOG_DEBUG("Verify error");
return ERROR_OK; /* quick hack to ignore error on w1c
type registers */

Of course no warranty.
If you want to do it more acceptable way (and contribute to OpenOCD), a
new error type ERROR_WRITE_VERIFY
should be introduced and ignored on any write to a register with w1c or
read only bits.

Tom

Loading...