Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/frdm: fix flashing from invalid state #12261

Merged
merged 1 commit into from
Sep 20, 2019

Conversation

cladmi
Copy link
Contributor

@cladmi cladmi commented Sep 17, 2019

Contribution description

When flashing some applications the flasher sometimes gets stuck which
prevents flashing after.
It may be from a specific firmware or operation but do not have one yet.
Connect with reset asserted fix flashing from this state.

Testing procedure

I do not have an application that cannot flash anymore to really show the fix.
But I have been using a fix like this for several month and had no flashing issue in my test machine.

Flashing boards that use common/frdm so frdm-kw41z and other similar boards, frdm-k22f and frdm-k64f keep flashing correctly. (the

They now use connect_assert_srst when flashing instead of connect_deassert_srst as it was in `master

PR:
srst_only separate srst_nogate srst_open_drain connect_assert_srst

master

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Both appear with this PR as the deassert is the value in the configuration which is then changed by command line option.

frdm-k64f
BOARD=frdm-k64f RIOT_CI_BUILD=1 make -C examples/hello-world/ flash 
make: Entering directory '/home/harter/work/git/RIOT/examples/hello-world'
Building application "hello-world" for "frdm-k64f" with MCU "kinetis".

   text    data     bss     dec     hex filename
   9160     116    2544   11820    2e2c /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-k64f/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-k64f/hello-world.elf
### Flashing Target ###
/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-k64f/hello-world.elf is not locked.
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_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 : Listening on port 44403 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: 0x1fff0200
auto erase enabled
Info : Kinetis MK64FN1M0xxx12 detected: 2 flash blocks
Info : 2 PFlash banks: 1024k total
wrote 12288 bytes from file /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-k64f/hello-world.elf in 0.895014s (13.408 KiB/s)
Error: timed out while waiting for target halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000bd2 psp: 0x1fff0408
Error: error executing cortex_m crc algorithm
verified 9276 bytes in 20.942808s (0.433 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing
make: Leaving directory '/home/harter/work/git/RIOT/examples/hello-world'
frdm-kw41z
BOARD=frdm-kw41z RIOT_CI_BUILD=1 make -C examples/hello-world/ flash
make: Entering directory '/home/harter/work/git/RIOT/examples/hello-world'
Building application "hello-world" for "frdm-kw41z" with MCU "kinetis".

   text    data     bss     dec     hex filename
   9080     116    2544   11740    2ddc /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf
### Flashing Target ###
/home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf is not locked.
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 : add flash_bank kinetis klx.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 : J-Link OpenSDA 2 compiled May  6 2016 11:04:17
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Info : MDM: Chip is unsecured. Continuing.
Info : klx.cpu: hardware has 2 breakpoints, 2 watchpoints
Info : Listening on port 35329 for gdb connections
    TargetName         Type       Endian TapName            State
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            reset
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000758 msp: 0x1fff8200
auto erase enabled
Info : Kinetis MKW41Z512xxx4 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
Info : This device supports Program Longword execution only.
Info : Disabling Kinetis watchdog (initial SIM_COPC 0x0c)
Warn : not enough working area available(requested 2048)
Info : This device supports Program Longword execution only.
Warn : not enough working area available(requested 2048)
wrote 10240 bytes from file /home/harter/work/git/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf in 0.374071s (26.733 KiB/s)
verified 9196 bytes in 0.119052s (75.433 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing
make: Leaving directory '/home/harter/work/git/RIOT/examples/hello-world'

Issues/PRs references

When flashing some applications the flasher sometimes gets stuck which
prevents flashing after.
It may be from a specific firmware or operation but do not have one yet.
Connect with reset asserted fix flashing from this state.
@benpicco benpicco added Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Sep 17, 2019
@fjmolinas fjmolinas self-requested a review September 19, 2019 11:46
@fjmolinas fjmolinas added 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: 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 19, 2019
@fjmolinas
Copy link
Contributor

I do not see any reason why the added command could affect flashing or resetting the device, At worst it wouldn't change the base behavior. I do not have the hardware(frdm-kw41z, frdm-k64f) to test today but I will tomorrow, I will trust @cladmi restults with frdm-k22f.

I do not have an application that cannot flash anymore to really show the fix.

There was one before right? Maybe you can provide a patch that reverts the change that fixed that app? If I remember correctly it was a driver test application, but I don't remember which one... If it is not reproducible I will ACK once I test it isn't breaking anything (The only reason I do not ACK right away is that in #12158 there were some issues).

@fjmolinas
Copy link
Contributor

Also is this an alternative to #11549? Does this fix the issue you have in ##11549 as well?

@fjmolinas
Copy link
Contributor

Also is this an alternative to #11549? Does this fix the issue you have in ##11549 as well?

I looked again and #11549 and saw no new changes have been added since the last time I tested, so this is not an alternative.

@benemorius
Copy link
Member

benemorius commented Sep 19, 2019

You can put a kinetis board into an unflashable state by using #11789 and calling pm_set(0). This powers off the SWD hardware until reset is asserted or something else wakes the cpu.

@cladmi
Copy link
Contributor Author

cladmi commented Sep 19, 2019

@fjmolinas no the pba-d-01-kw2x uses a different openocd configuration even if it is a kinetis board.

@benemorius oh nice I will try it. Does this PR fixes flashing for you? and which board are you using.

@benemorius
Copy link
Member

Does this PR fixes flashing for you? and which board are you using.

I can confirm that definitely I do need connect_assert_srst or else I can't flash a kw41z-mini while it's in the lowest power mode. That's the reason for fc75cd1 in #11789.

But I don't have a board that can flash using make flash so I can't do a proper test of the PR.

@fjmolinas
Copy link
Contributor

Tested on frdm-k64f using #11789, the following output are after I flashed an application that has pm_set(0) right at the start.

OPENOCD_RESET_USE_CONNECT_ASSERT_SRST=0 make -C tests/periph_pm BOARD=frdm-k64f flash -j3
make: Entering directory '/home/francisco/workspace/RIOT/tests/periph_pm'
Building application "tests_periph_pm" for "frdm-k64f" with MCU "kinetis".

"make" -C /home/francisco/workspace/RIOT/boards/frdm-k64f
"make" -C /home/francisco/workspace/RIOT/core
"make" -C /home/francisco/workspace/RIOT/cpu/kinetis
"make" -C /home/francisco/workspace/RIOT/drivers
"make" -C /home/francisco/workspace/RIOT/cpu/cortexm_common
"make" -C /home/francisco/workspace/RIOT/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT/cpu/cortexm_common/periph
"make" -C /home/francisco/workspace/RIOT/cpu/kinetis/periph
"make" -C /home/francisco/workspace/RIOT/sys
"make" -C /home/francisco/workspace/RIOT/sys/auto_init
"make" -C /home/francisco/workspace/RIOT/sys/isrpipe
"make" -C /home/francisco/workspace/RIOT/sys/newlib_syscalls_default
"make" -C /home/francisco/workspace/RIOT/sys/pm_layered
"make" -C /home/francisco/workspace/RIOT/sys/shell
"make" -C /home/francisco/workspace/RIOT/sys/stdio_uart
"make" -C /home/francisco/workspace/RIOT/sys/tsrb
   text	   data	    bss	    dec	    hex	filename
  20732	    240	   2820	  23792	   5cf0	/home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.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
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.10
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/francisco/workspace/RIOT/tests/periph_pm/../../Makefile.include:600: recipe for target 'flash' failed
make: *** [flash] Error 1
make: Leaving directory '/home/francisco/workspace/RIOT/tests/periph_pm'


OPENOCD_RESET_USE_CONNECT_ASSERT_SRST=1 make -C tests/periph_pm BOARD=frdm-k64f flash -j3

make: Entering directory '/home/francisco/workspace/RIOT/tests/periph_pm'
Building application "tests_periph_pm" for "frdm-k64f" with MCU "kinetis".

"make" -C /home/francisco/workspace/RIOT/boards/frdm-k64f
"make" -C /home/francisco/workspace/RIOT/core
"make" -C /home/francisco/workspace/RIOT/cpu/kinetis
"make" -C /home/francisco/workspace/RIOT/drivers
"make" -C /home/francisco/workspace/RIOT/cpu/cortexm_common
"make" -C /home/francisco/workspace/RIOT/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT/cpu/cortexm_common/periph
"make" -C /home/francisco/workspace/RIOT/cpu/kinetis/periph
"make" -C /home/francisco/workspace/RIOT/sys
"make" -C /home/francisco/workspace/RIOT/sys/auto_init
"make" -C /home/francisco/workspace/RIOT/sys/isrpipe
"make" -C /home/francisco/workspace/RIOT/sys/newlib_syscalls_default
"make" -C /home/francisco/workspace/RIOT/sys/pm_layered
"make" -C /home/francisco/workspace/RIOT/sys/shell
"make" -C /home/francisco/workspace/RIOT/sys/stdio_uart
"make" -C /home/francisco/workspace/RIOT/sys/tsrb
   text	   data	    bss	    dec	    hex	filename
  20732	    240	   2820	  23792	   5cf0	/home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.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.10
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 46373 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: 0x1fff0200
auto erase enabled
Info : Kinetis MK64FN1M0xxx12 detected: 2 flash blocks
Info : 2 PFlash banks: 1024k total
wrote 24576 bytes from file /home/francisco/workspace/RIOT/tests/periph_pm/bin/frdm-k64f/tests_periph_pm.elf in 1.209991s (19.835 KiB/s)
Info : kx.cpu: external reset detected
Error: Failed to write memory and, additionally, failed to find out where
Warn : target was in unknown state when halt was requested
Error: error executing cortex_m crc algorithm
Error: Failed to read memory and, additionally, failed to find out where

/home/francisco/workspace/RIOT/tests/periph_pm/../../Makefile.include:600: recipe for target 'flash' failed
make: *** [flash] Error 1
make: Leaving directory '/home/francisco/workspace/RIOT/tests/periph_pm'

NOTE: my diff
diff --git a/boards/common/frdm/dist/openocd-klx.cfg b/boards/common/frdm/dist/openocd-klx.cfg
index 5d7f29cb1..7970abc14 100644
--- a/boards/common/frdm/dist/openocd-klx.cfg
+++ b/boards/common/frdm/dist/openocd-klx.cfg
@@ -19,7 +19,7 @@ source [find target/klx.cfg]
 # The debug module is stopped in low leakage modes, we use connect_assert_srst
 # to hold the device in reset while connecting with OpenOCD to make sure that we
 # always get a connection even when the application uses low power modes.
-reset_config srst_only connect_assert_srst
+reset_config srst_only
 
 $_TARGETNAME configure -event gdb-attach {
   halt
diff --git a/boards/common/frdm/dist/openocd-kx.cfg b/boards/common/frdm/dist/openocd-kx.cfg
index 2e128dcb9..84bd6243e 100644
--- a/boards/common/frdm/dist/openocd-kx.cfg
+++ b/boards/common/frdm/dist/openocd-kx.cfg
@@ -16,7 +16,7 @@ source [find target/kx.cfg]
 # The debug module is stopped in low leakage modes, we use connect_assert_srst
 # to hold the device in reset while connecting with OpenOCD to make sure that we
 # always get a connection even when the application uses low power modes.
-reset_config srst_only connect_assert_srst
+reset_config srst_only
 
 $_TARGETNAME configure -event gdb-attach {
   halt
diff --git a/tests/periph_pm/main.c b/tests/periph_pm/main.c
index 4fe74b3bf..3f5705956 100644
--- a/tests/periph_pm/main.c
+++ b/tests/periph_pm/main.c
@@ -241,6 +241,8 @@ int main(void)
          "needed.");
 #endif
 
+    pm_set(0);
+
     /* run the shell and wait for the user to enter a mode */
     shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

@fjmolinas fjmolinas added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Sep 20, 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.

I was able to test this fixes the issue for frdm-kw41z and frdm-k64f. Changes are good ACK.

@fjmolinas fjmolinas merged commit 6847d0d into RIOT-OS:master Sep 20, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 20, 2019

Thanks @benemorius for your feedback and giving the perfect test for this.
Thanks @fjmolinas for testing and reviewing.

@cladmi cladmi deleted the pr/frdm/fix_flashing branch September 20, 2019 08:29
@cladmi
Copy link
Contributor Author

cladmi commented Sep 20, 2019

I also cross-checked locally with frdm-kw41z and frdm-k64f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports 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: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants