Skip to content

boards/pba-d-01-kw2x: fix flashing from invalid state#11549

Merged
fjmolinas merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/pba_d_01_kw2x/fix_flashing
Sep 23, 2019
Merged

boards/pba-d-01-kw2x: fix flashing from invalid state#11549
fjmolinas merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/pba_d_01_kw2x/fix_flashing

Conversation

@cladmi
Copy link
Contributor

@cladmi cladmi commented May 20, 2019

Contribution description

When in an invalid state, the board could not flash anymore.
Like for example after flashing tests/driver_adt7310 this makes it
flash again.

I used reset_config srst_only as the other kinetis boards are also
configured that way.

cortex_m reset_config sysresetreq
#reset_config srst_only srst_nogate connect_assert_srst

Testing procedure

Thy flashing two or more times tests/driver_adt7310 compile first and run flash-only.

With this pull request it works without issues.

RIOT_CI_BUILD=1 BOARD=pba-d-01-kw2x make -C tests/driver_adt7310/ flash-only

RIOT_CI_BUILD=1 BOARD=pba-d-01-kw2x make -C tests/driver_adt7310/ flash-only
make: Entering directory '/home/harter/work/git/worktree/riot_master/tests/driver_adt7310'
/home/harter/work/git/worktree/riot_master/dist/tools/openocd/openocd.sh flash /home/harter/work/git/worktree/riot_master/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf
### Flashing Target ###
/home/harter/work/git/worktree/riot_master/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf is fine.
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : Connecting under reset
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 38973 for gdb connections
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0* kx.cpu             cortex_m   little kx.cpu             reset
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000740 msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 16384 bytes from file /home/harter/work/git/worktree/riot_master/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf in 0.605979s (26.404 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004076s (8.146 KiB/s)
target halted due to breakpoint, current mode: Thread
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 14388 bytes in 0.437898s (32.087 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
Error: Failed to write memory and, additionally, failed to find out where
Error: Failed to enable the FPB
Polling target kx.cpu failed, trying to reexamine
Error: MDM: failed to read ID register
Error: Could not find MEM-AP to control the core
Examination failed, GDB will be halted. Polling again in 100ms
shutdown command invoked
Done flashing
make: Leaving directory '/home/harter/work/git/worktree/riot_master/tests/driver_adt7310'

With master after the second time it fails:

Flash fails without error message

RIOT_CI_BUILD=1 BOARD=pba-d-01-kw2x make -C tests/driver_adt7310/ flash-only
make: Entering directory '/home/harter/work/git/worktree/riot_master/tests/driver_adt7310'
/home/harter/work/git/worktree/riot_master/dist/tools/openocd/openocd.sh flash /home/harter/work/git/worktree/riot_master/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf
### Flashing Target ###
/home/harter/work/git/worktree/riot_master/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf is fine.
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz


/home/harter/work/git/worktree/riot_master/tests/driver_adt7310/../../Makefile.include:541: recipe for target 'flash-only' failed
make: *** [flash-only] Error 1
make: Leaving directory '/home/harter/work/git/worktree/riot_master/tests/driver_adt7310'

Issues/PRs references

Found while running the test suite on the board in #10870

@cladmi cladmi added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: build system Area: Build system Area: tools Area: Supplementary tools Area: boards Area: Board ports labels May 20, 2019
@cladmi cladmi added this to the Release 2019.07 milestone May 20, 2019
@cladmi cladmi requested review from MrKevinWeiss and aabadie May 20, 2019 12:20
@cladmi cladmi requested a review from smlng May 28, 2019 12:08
@cladmi cladmi force-pushed the pr/pba_d_01_kw2x/fix_flashing branch from 46f298e to 917d598 Compare June 3, 2019 12:34
@cladmi cladmi requested a review from fjmolinas June 4, 2019 15:22
@cladmi
Copy link
Contributor Author

cladmi commented Jun 4, 2019

I think I should also test debugging. I put this as a reminder.

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the issue, but DEBUG is not working properly anymore on this branch, while it is on master. I'll take a closer look tomorrow.

@cladmi
Copy link
Contributor Author

cladmi commented Jun 13, 2019

It still works for me for debugging:

BOARD=pba-d-01-kw2x make -C examples/hello-world/ flash debug
...
reset_handler_default () at /home/harter/work/git/RIOT/cpu/cortexm_common/vectors_cortexm.c:79
79      {
(gdb) b main
Breakpoint 1 at 0x10fe: file /home/harter/work/git/RIOT/examples/hello-world/main.c, line 26.
(gdb) monitor reset halt
MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000740 msp: 0x1fffc200
(gdb) monitor reset init
MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000740 msp: 0x1fffc200
Disabling Kinetis watchdog (initial WDOG_STCTRLH = 0x01d3)
WDOG_STCTRLH = 0x01d2
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at /home/harter/work/git/RIOT/examples/hello-world/main.c:26
26          puts("Hello World!");

I could also debug examples/default.

@cladmi cladmi force-pushed the pr/pba_d_01_kw2x/fix_flashing branch from a03ef73 to 917d598 Compare June 13, 2019 12:46
@fjmolinas
Copy link
Contributor

I executed this:

BOARD=pba-d-01-kw2x make -C examples/hello-world/ flash debug

on master:

### Starting Debugging ###
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf...
Remote debugging using :3333
pm_set_lowest () at /home/francisco/workspace/RIOT/cpu/cortexm_common/include/cpu.h:177
177	    irq_restore(state);

with this PR:

### Starting Debugging ###
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf...
Remote debugging using :3333
0x2000002e in ?? ()

@cladmi
Copy link
Contributor Author

cladmi commented Sep 2, 2019

This one is now based on #11976

@fjmolinas would this work for your board right now? and if I replace the reset_config to reset_config trst_and_srst ?

With trst_and_srst it works on mine.

@cladmi cladmi force-pushed the pr/pba_d_01_kw2x/fix_flashing branch from f7fa42c to 75c6fcb Compare September 2, 2019 13:46
When in an invalid state, the board could not flash anymore.
Like for example after flashing `tests/driver_adt7310` this makes it
flash again.

I used `reset_config srst_only` as the other kinetis boards are also
configured that way.
@cladmi cladmi force-pushed the pr/pba_d_01_kw2x/fix_flashing branch from 75c6fcb to 94dfc4d Compare September 2, 2019 13:56
@cladmi
Copy link
Contributor Author

cladmi commented Sep 2, 2019

Rebased now that #11976 is merged.

@fjmolinas
Copy link
Contributor

@cladmi I'm still having the same issue, but as discussed IRL this could be an issue with my board. Maybe @smlng could test? I think he has some pba-d-01-kw2x. If not i'll try to find some time to see If I can find a working config for my board.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 2, 2019

@cladmi I'm still having the same issue, but as discussed IRL this could be an issue with my board. Maybe @smlng could test? I think he has some pba-d-01-kw2x. If not i'll try to find some time to see If I can find a working config for my board.

Does it also fail with trst_and_srst? because both configurations work on my board (it is not in a 'non flashable' state though).

diff --git a/boards/pba-d-01-kw2x/dist/openocd.cfg b/boards/pba-d-01-kw2x/dist/openocd.cfg
index 94a704212..1a5dbc6a2 100644
--- a/boards/pba-d-01-kw2x/dist/openocd.cfg
+++ b/boards/pba-d-01-kw2x/dist/openocd.cfg
@@ -1,3 +1,3 @@
 source [find target/kx.cfg]
-reset_config srst_only
+reset_config trst_and_srst
 $_TARGETNAME configure -rtos auto

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 17, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 20, 2019

@fjmolinas indeed, there was no change as you mentioned in #12261 (comment) I had the diff to try in the previous comment. I pushed it to simplify testing :)

@fjmolinas
Copy link
Contributor

@cladmi I'm trying to get it to work on my board ass wll but I still have the same issues as stated before. I tried to go back to the board documentation but it seems @PHYTEC-Messtechnik-GmbH has dropped there wiki entries for this board...

@fjmolinas
Copy link
Contributor

@cladmi as I had told you IRL my board had some issue that could have explained why it wasn't working for me. I managed to fix them and know I have the following behaviour:

  • Flashing tests/driver_adt7310/ twice suceeds:
RIOT_CI_BUILD=1 BOARD=pba-d-01-kw2x make -C tests/driver_adt7310/ flash
make: Entering directory '/home/francisco/workspace/RIOT/tests/driver_adt7310'
Building application "tests_driver_adt7310" for "pba-d-01-kw2x" with MCU "kinetis".

   text	   data	    bss	    dec	    hex	filename
  14516	    116	   2632	  17264	   4370	/home/francisco/workspace/RIOT/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf is not locked.
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : Connecting under reset
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : kx.cpu: external reset detected
Info : Listening on port 35111 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* kx.cpu             cortex_m   little kx.cpu             reset
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0000073c msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 16384 bytes from file /home/francisco/workspace/RIOT/tests/driver_adt7310/bin/pba-d-01-kw2x/tests_driver_adt7310.elf in 0.599877s (26.672 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004033s (8.233 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 14632 bytes in 0.403877s (35.380 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
Error: Failed to write memory and, additionally, failed to find out where
Error: Failed to enable the FPB
Polling target kx.cpu failed, trying to reexamine
Error: MDM: failed to read ID register
Error: Could not find MEM-AP to control the core
Examination failed, GDB will be halted. Polling again in 100ms
shutdown command invoked
Done flashing
make: Leaving directory '/home/francisco/workspace/RIOT/tests/driver_adt7310'
  • flash debug works correctly:
.RIOT_CI_BUILD=1 BOARD=pba-d-01-kw2x make -C examples/hello-world/ flash debug
make: Entering directory '/home/francisco/workspace/RIOT/examples/hello-world'
Building application "hello-world" for "pba-d-01-kw2x" with MCU "kinetis".

   text	   data	    bss	    dec	    hex	filename
   9552	    116	   2564	  12232	   2fc8	/home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf is not locked.
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : Connecting under reset
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : kx.cpu: external reset detected
Info : Listening on port 40109 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* kx.cpu             cortex_m   little kx.cpu             reset
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0000073c msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 10240 bytes from file /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf in 0.385966s (25.909 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004036s (8.227 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 9668 bytes in 0.378957s (24.914 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh debug /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
### Starting Debugging ###
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Reading symbols from /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf...
Remote debugging using :3333
pm_set_lowest () at /home/francisco/workspace/RIOT/cpu/cortexm_common/include/cpu.h:177
177	    irq_restore(state);
(gdb) 

This is independent of using srst_only and tsrst_and_srst. So please squash keeping the initial srst_only config. I'm sorry that the issue I had with my board stalled this PR so much.

@fjmolinas fjmolinas added CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Sep 23, 2019
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK!

@cladmi
Copy link
Contributor Author

cladmi commented Sep 23, 2019

@cladmi as I had told you IRL my board had some issue that could have explained why it wasn't working for me. I managed to fix them and know I have the following behaviour:

Do you know in which state you were before as a reference? or what did you do to become again in the "normal" state?

IIRC @MichelRottleuthner had some boards that could not flash and it may help him too.

This is independent of using srst_only and tsrst_and_srst. So please squash keeping the initial srst_only config. I'm sorry that the issue I had with my board stalled this PR so much.

I agree, as srst_only works, no reason to add the other one.
I tried to see if it would trigger your board reset also but was not the case.

No worry for the delay, these things are still black magic for me and any additional input forces to re-consider what I know.
Also waiting allowed basing on your PR which made it way better.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 23, 2019

I will remove the last commit and push force.

@cladmi cladmi force-pushed the pr/pba_d_01_kw2x/fix_flashing branch from d1a476c to 94dfc4d Compare September 23, 2019 09:30
@fjmolinas fjmolinas removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Sep 23, 2019
@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 23, 2019
@fjmolinas fjmolinas merged commit abdebaa into RIOT-OS:master Sep 23, 2019
@cladmi cladmi deleted the pr/pba_d_01_kw2x/fix_flashing branch September 23, 2019 11:16
@cladmi
Copy link
Contributor Author

cladmi commented Sep 23, 2019

Thank you for the review and testing.

@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: build system Area: Build system Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants