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

cpu+board: Add support for NXP Kinetis KW41Z and FRDM-KW41Z development board #6995

Merged
merged 11 commits into from
Mar 2, 2018

Conversation

jnohlgard
Copy link
Member

@jnohlgard jnohlgard commented May 2, 2017

Port RIOT to the recently released NXP FRDM-KW41Z development boards.

Currently missing support for the radio and the onboard NOR flash.
I2C needs a rewrite, this CPU has one i2c module clocked from the bus clock, and one clocked by the system clock. The I2C rewrite will be on hold until the I2C API is reworked, so for now, one of the two available I2C buses will be clocked at the wrong speed, this can be worked around in the application by requesting a different speed or modifying the configuration to fit.

A radio transceiver driver is available in #7107

depends on #7362 #6994 #6978 #6916 #6993 #7434 #7882 #8560

@jnohlgard jnohlgard added Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels May 2, 2017
@jnohlgard jnohlgard added this to the Release 2017.07 milestone May 2, 2017
@jnohlgard
Copy link
Member Author

This requires a patched openocd which can be found at https://github.com/gebart/openocd/tree/pr/kwxxz-support?files=1

@jnohlgard
Copy link
Member Author

The required openocd patches have been merged into the upstream master branch for what I assume will be released as openocd version 0.11.

@emmanuelsearch
Copy link
Member

@gebart meaning that I could just clone master from http://git.code.sf.net/p/openocd/code and use that?

@jnohlgard
Copy link
Member Author

Yes, I believe so. I did not test it myself yet, but I got some emails yesterday from the Gerrit system that my patches have been merged. If openocd doesn't have the new CPU support you will get a message saying "unsupported MCU" or something similar and the flashing will fail.

I think you may need to have libusb-dev installed for building openocd with jlink support. The configure script will enable all supported interfaces automatically based on which libraries are installed on your machine and you will see a summary of which interfaces are enabled at the end of configure, if jlink is not enabled you will need some other lib.

@kYc0o
Copy link
Contributor

kYc0o commented Jun 27, 2017

I have a board now so I can test and review the code. I'll try to merge this on today's Hack'n'ACK

@kYc0o
Copy link
Contributor

kYc0o commented Jun 27, 2017

Well, I think I have everything configured now but no success while flashing:

### Flashing Target ###
/Users/facosta/git/RIOT2/RIOT/examples/default/bin/frdm-kw41z/default.elf is fine.
Open On-Chip Debugger 0.10.0+dev-00161-g1725abc (2017-06-27-19:26)
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
Info : No device selected, using first device.
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
Error: MDM: failed to read ID register
Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000ed00
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            reset
Polling target klx.cpu failed, trying to reexamine
Info : SWD DPIDR 0x0bc11477
Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
Warn : **** Common reason is a blank flash (at least a reset vector).  ****
Warn : **** Issue 'kinetis mdm halt' command or if SRST is connected   ****
Warn : **** and configured, use 'reset halt'                           ****
Warn : **** If MCU cannot be halted, it is likely secured and running  ****
Warn : **** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase'         ****
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000edfc
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe0001000
Info : klx.cpu: hardware has 0 breakpoints, 0 watchpoints
Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
Warn : **** Common reason is a blank flash (at least a reset vector).  ****
Warn : **** Issue 'kinetis mdm halt' command or if SRST is connected   ****
Warn : **** and configured, use 'reset halt'                           ****
Warn : **** If MCU cannot be halted, it is likely secured and running  ****
Warn : **** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase'         ****
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
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)
Info : This device supports Program Longword execution only.
Error: jaylink_swd_io() failed: JAYLINK_ERR_DEV_NO_MEMORY.
Warn : Sending data to device timed out, retrying.
Warn : Sending data to device timed out, retrying.
Error: Sending data to device timed out.
Error: transport_write() failed: timeout occurred.
Error: jaylink_swd_io() failed: JAYLINK_ERR_TIMEOUT.
Warn : Last read operation left 16 bytes.
Warn : Sending data to device timed out, retrying.
Error: Failed to send data to device: input/output error.
Error: transport_write() failed: input/output error.
Error: jaylink_swd_io() failed: JAYLINK_ERR_IO.
Warn : Last read operation left 16 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Error: klx.cpu -- clearing lockup after double fault
Warn : Last read operation left 34 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 9 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 15 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 9 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 33 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 9 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 33 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 22 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 16 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 33 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Error: klx.cpu -- clearing lockup after double fault
Warn : Last read operation left 33 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Warn : Last read operation left 9 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Error: error waiting for target flash write algorithm
Error: Error executing kinetis Flash programming algorithm
Warn : Last read operation left 15 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_swd_io() failed: JAYLINK_ERR.
Error: error writing to flash at address 0x00000000 at offset 0x00000000

Warn : Last read operation left 28 bytes.
Error: Failed to send data to device: LIBUSB_ERROR_PIPE.
Error: transport_write() failed: unspecified error.
Error: jaylink_unregister() failed: JAYLINK_ERR.
make: *** [flash] Error 1

Maybe I need to press some buttons or something?

@jnohlgard
Copy link
Member Author

@kYc0o try running make debug-server and connect with telnet to openocd and run the listed command (kinetis mdm mass_erase) followed by reset halt. Then you can kill the debug server and try make flash again

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

I have tried that without success (same error as above)... I'll try today to flash it using a Segger J-Link adapter, maybe there's still some things to erase or program before having a functional openocd programming.

However, it's quite uncomfortable this way, since it means we cannot flash these devices out of the box. You board was flashable without any problem since the beginning? Have you updated the J-Link firmware? It's maybe only my board which is concerned...

Once I succeed, maybe we can merge this as a first or "early" support, since anyways we need to compile the latest master of openocd to have support for flashing this board.

@jnohlgard
Copy link
Member Author

Now that you mention it, my board was factory flashed with some LED blink app, so it wasn't stuck at all. I have only used openocd together with the on board jlink adapter. I did reflash one of my boards with a cmsis dap firmware just to try it out, and that one works as well (with FRDM_IFACE=dap)

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

Using an external J-Link adapter the flashing is successful, then if I try again with the default (openocd with onboard jlink) I still have the errors.

What I notice is that the flasher doesn't event succeed to read the MDM number, which I think is essential. However, the external J-Link succeeds even with this errors.

Below the output of a successful flashing with an external Segger J-Link:

Open On-Chip Debugger 0.10.0+dev-00161-g1725abc (2017-06-27-20:01)
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
Info : No device selected, using first device.
Info : J-Link V9 compiled Feb  2 2016 18:43:46
Info : Hardware version: 9.30
Info : VTarget = 2.985 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Error: MDM: failed to read ID register
Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000edfc
Info : klx.cpu: hardware has 0 breakpoints, 2 watchpoints
Polling target klx.cpu failed, trying to reexamine
Error: The 'check_security' command must be used after 'init'.
in procedure 'init' 
in procedure 'ocd_bouncer' 
in procedure 'flash' 
in procedure 'ocd_bouncer'

Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000edfc
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0xe0001028
Info : klx.cpu: hardware has 0 breakpoints, 2 watchpoints
Polling target klx.cpu failed, trying to reexamine
Info : SWD DPIDR 0x0bc11477
Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
Warn : **** Common reason is a blank flash (at least a reset vector).  ****
Warn : **** Issue 'kinetis mdm halt' command or if SRST is connected   ****
Warn : **** and configured, use 'reset halt'                           ****
Warn : **** If MCU cannot be halted, it is likely secured and running  ****
Warn : **** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase'         ****
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe000ed00
Examination failed, GDB will be halted. Polling again in 100ms
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            unknown
Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
Warn : **** Common reason is a blank flash (at least a reset vector).  ****
Warn : **** Issue 'kinetis mdm halt' command or if SRST is connected   ****
Warn : **** and configured, use 'reset halt'                           ****
Warn : **** If MCU cannot be halted, it is likely secured and running  ****
Warn : **** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase'         ****
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
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)
Info : This device supports Program Longword execution only.
Warn : Flash Configuration Field written.
Warn : Reset or power off the device to make settings effective.
Info : This device supports Program Longword execution only.
wrote 12288 bytes from file /Users/facosta/git/RIOT2/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf in 0.422928s (28.374 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x61000000 pc: 0x00000764 msp: 0x1fff8200
verified 11472 bytes in 0.139199s (80.483 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing

@jnohlgard
Copy link
Member Author

Did you try reflashing the debugger on the board?
Either the latest jlink frdm-kw41z firmware from Segger, or the mbed cmsis dap from nxp.com

Also, do you have the same problem with both boards? (I assume you have two since the frdm-kw41z box comes with two identical boards)

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

I was just doing that when you posted your comment. Now I have different errors:

### Flashing Target ###
/Users/facosta/git/RIOT2/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf is fine.
Open On-Chip Debugger 0.10.0+dev-00161-g1725abc (2017-06-27-20:01)
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
Info : No device selected, using first device.
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
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            halted
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x0001541c msp: 0x20000428
auto erase enabled
Info : Kinetis MKW41Z512xxx4 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
Error: Flash operation failed, protection violated
Warn : erase sector 0 failed
Error: failed erasing sectors 0 to 5

make: *** [flash] Error 1

I don't know if I succeeded by updating it since I still have Hardware version: 1.00.

I can try with CMSIS-DAP and post the output.

@jnohlgard
Copy link
Member Author

@kYc0o did you move the jumper near the reset button to connect the reset button to the debugger instead of to the target? You need to move the jumper from the default position.
See https://community.nxp.com/docs/DOC-333763

Hold the reset button while connecting the USB cable, and keep holding it until the board shows up on the PC.
If it works, the USB mass storage device will be labeled BOOT or BOOTLOADER, instead of FRDM-KW41Z or DAPLINK.
Copy the debugger firmware image to the bootloader USB drive, the board will reset and reconnect after a few seconds.

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

Thanks! I succeeded to update the firmware but no succeess so far... I uploaded a CMSIS-DAP firmware but it's not recognised by default. Do I need to set some variable like "PROGRAMMER" or something like that?

Regarding the second board, unfortunately I only grabbed one from @emmanuelsearch, who still has it afaik.

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

I modified the interface to dap instead of jlink, which seems to recognise the dap interface but still no flashing...

### Flashing Target ###
/Users/facosta/git/RIOT2/RIOT/examples/hello-world/bin/frdm-kw41z/hello-world.elf is fine.
Open On-Chip Debugger 0.10.0+dev-00161-g1725abc (2017-06-27-20:01)
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
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Error: MDM: failed to read ID register
Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0xe0002008
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe0001000
Info : klx.cpu: hardware has 2 breakpoints, 0 watchpoints
Polling target klx.cpu failed, trying to reexamine
Error: The 'check_security' command must be used after 'init'.
in procedure 'init' 
in procedure 'ocd_bouncer' 
in procedure 'flash' 
in procedure 'ocd_bouncer'

Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to write memory at 0xe000200c
Info : klx.cpu: hardware has 2 breakpoints, 2 watchpoints
Polling target klx.cpu failed, trying to reexamine
Error: The 'check_security' command must be used after 'init'.
in procedure 'init' 
in procedure 'ocd_bouncer' 
in procedure 'pld' 
in procedure 'ocd_bouncer'

Info : SWD DPIDR 0x0bc11477
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0xe0001000
Info : klx.cpu: hardware has 2 breakpoints, 0 watchpoints
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            reset
Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
Warn : **** Common reason is a blank flash (at least a reset vector).  ****
Warn : **** Issue 'kinetis mdm halt' command or if SRST is connected   ****
Warn : **** and configured, use 'reset halt'                           ****
Warn : **** If MCU cannot be halted, it is likely secured and running  ****
Warn : **** in RESET/WDOG loop. Issue 'kinetis mdm mass_erase'         ****
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x0001541c msp: 0x20000428
auto erase enabled
Info : Kinetis MKW41Z512xxx4 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
Error: Flash operation failed, protection violated
Warn : erase sector 0 failed
Error: failed erasing sectors 0 to 5

make: *** [flash] Error 1

@kYc0o
Copy link
Contributor

kYc0o commented Jun 28, 2017

And now I think I bricked my device... no flashing possible even with the external Segger J-Link...

@jnohlgard
Copy link
Member Author

Btw, the environment variable for selecting jlink or dap is named FRDM_IFACE.
export FRDM_IFACE=dap

@kYc0o
Copy link
Contributor

kYc0o commented Feb 28, 2018

Yes I'm able to flash but as I pointed out in a previous comment, I have flashed the DAP firmware to my board, thus I need to to the following:

DEBUG_ADAPTER=dap BOARD=frdm-kw41z make -C examples/default flash term

which results in a successful flashing.

@jnohlgard
Copy link
Member Author

@kYc0o @haukepetersen @emmanuelsearch Thanks for testing

@kYc0o
Copy link
Contributor

kYc0o commented Feb 28, 2018

I just grabbed @emmanuelsearch board with JLink firmware and successfully flashed. Thus I suspect there's something in the configuration of either openocd or the usb ports on @emmanuelsearch setup.

@kYc0o
Copy link
Contributor

kYc0o commented Feb 28, 2018

I'm about to merge this PR but still have a small doubt. @gebart can you check if the modification to the existing files are completely coupled with this PR goals? It's just that I see some commits which modify some behaviour (e.g. 6c7c3e1 ) which looks "somehow" unrelated. I'm not against merging this PR as is, but just for consistency I'd prefer to keep only the commits for this PR and if needed separate the rest in other PRs (which can be merged asap given that they were already reviewed and tested here).

@jnohlgard
Copy link
Member Author

Will split some commits

@jnohlgard jnohlgard merged commit ab0a2f7 into RIOT-OS:master Mar 2, 2018
@jnohlgard jnohlgard deleted the pr/frdm-kw41z branch March 2, 2018 16:04
@kYc0o
Copy link
Contributor

kYc0o commented Mar 2, 2018

Wow excellent!! Congrats @gebart this was a long trip!

@emmanuelsearch
Copy link
Member

emmanuelsearch commented Mar 2, 2018

@gebart great! very much looking forward to #7107 ;)

@jnohlgard
Copy link
Member Author

Thank you for the help with reviewing this pretty big PR!

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 Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants