Why do I get "ERROR: Failed to prepare for programming" when flashing?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why do I get "ERROR: Failed to prepare for programming" when flashing?

Jump to solution
12,801 Views
donturner
Contributor III

I have a new Freescale FRDM-K22F board. I'm unable to load any programs onto it.

When I attempt to load the program I get the following error message from JLinkGDBServer: ERROR: Failed to prepare for programming

Here's my working environment:

Host OS: Mac OS X 10.11.5 El Capitan

Toolchain: GNU ARM (gcc-arm-none-eabi-4_8-2014q3)

Firmware: SEGGER OpenSDA 2.1 generic firmware from https://www.segger.com/downloads/jlink/OpenSDA_V2_1.bin

JLink: V5.12i Command Line Version from https://www.segger.com/downloads/jlink/JLink_MacOSX_V512i.pkg

Here's what happens when I attempt to load the hello_world example:

1. Start JLinkGDBServer from Terminal

./JLinkGDBServer -select USB -device MK22FN512xxx12 -if SWD -speed 1000

SEGGER J-Link GDB Server V5.12i Command Line Version

JLinkARM.dll V5.12i (DLL compiled Jul  5 2016 19:02:37)

-----GDB Server start settings-----

GDBInit file:                  none

GDB Server Listening port:     2331

SWO raw output listening port: 2332

Terminal I/O port:             2333

Accept remote connection:      yes

Generate logfile:              off

Verify download:               off

Init regs on start:            off

Silent mode:                   off

Single run mode:               off

Target connection timeout:     0 ms

------J-Link related settings------

J-Link Host interface:         USB

J-Link script:                 none

J-Link settings file:          none

------Target related settings------

Target device:                 MK22FN512xxx12

Target interface:              SWD

Target interface speed:        1000kHz

Target endian:                 little

Connecting to J-Link...

J-Link is connected.

Firmware: J-Link OpenSDA 2 compiled Jul 12 2016 12:33:05

Hardware: V1.00

S/N: 621000000

Checking target voltage...

Target voltage: 3.30 V

Listening on TCP/IP port 2331

Connecting to target...Connected to target

Waiting for GDB connection...

2. Run GDB and load hello_world

arm-none-eabi-gdb hello_world.elf

(gdb) target remote localhost:2331

<JLink output>

Reading all registers

WARNING: Failed to read memory @ address 0xFFFFFFFE

(gdb) load

<JLink output>

Downloading 1024 bytes @ address 0x00000000

Downloading 16 bytes @ address 0x00000400

Downloading 16096 bytes @ address 0x00000410

Downloading 4080 bytes @ address 0x000042F0

Downloading 8 bytes @ address 0x000052E0

Downloading 4 bytes @ address 0x000052E8

Downloading 4 bytes @ address 0x000052EC

Downloading 164 bytes @ address 0x000052F0

ERROR: Failed to prepare for programming.

Failed to execute RAMCode for RAM check!

Writing register (PC = 0x000004d8)

I have tried various other firmwares and the beta version of JLink, as well as various combinations of `monitor halt` and `monitor reset` but I am still unable to load any programs onto the K22F board. Can anyone help?

0 Kudos
Reply
1 Solution
9,175 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Don Turner

The LED next to the MK22F on is no normal, It means that the Target can be halt.

It seems to be a version problem with the firmware for FRDM-K22F. Could you try with the attached file? Again the same process, holding down the reset button and then connect the USB cable, copy the firmware to the bootloader, disconnect and reconnect and then try to program. (If a message proms that tell you to erase the device to unsecure please click "yes" immediately).

Please try this and tell me what you get and if you have any question also tell me.


Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

7 Replies
9,175 Views
donturner
Contributor III

Thank you! That fixed it. Now I can upload programs and debug properly. 

0 Kudos
Reply
9,175 Views
donturner
Contributor III

Anyone able to help here? I currently have a K22F board which I would really like to start developing on but cannot load any programs onto it. I will happily switch to some other bootloader/firmware in order to use it.

0 Kudos
Reply
9,175 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Don Turner

Have you tried to program your FRDM-K22F using KDS 3.2 IDE?

KDS IDE support Segger in MAC OS, Could you try it and tell me what you get?


Have a great day,
Jorge Alcala

0 Kudos
Reply
9,175 Views
donturner
Contributor III

Thanks for responding Jorge. I have tried using KDS v3.2.0 and I still get an error. Here's the full output I get from the debugger:

SEGGER J-Link GDB Server V5.10n Command Line Version

JLinkARM.dll V5.10n (DLL compiled Feb 19 2016 18:41:43)

-----GDB Server start settings-----

GDBInit file:                  none

GDB Server Listening port:     2331

SWO raw output listening port: 2332

Terminal I/O port:             2333

Accept remote connection:      localhost only

Generate logfile:              off

Verify download:               on

Init regs on start:            on

Silent mode:                   off

Single run mode:               on

Target connection timeout:     0 ms

------J-Link related settings------

J-Link Host interface:         USB

J-Link script:                 none

J-Link settings file:          none

------Target related settings------

Target device:                 MK22FN512xxx12

Target interface:              SWD

Target interface speed:        1000kHz

Target endian:                 little

Connecting to J-Link...

J-Link is connected.

Firmware: J-Link OpenSDA 2 compiled Jul 12 2016 12:33:05

Hardware: V1.00

S/N: 621000000

Checking target voltage...

Target voltage: 3.30 V

Listening on TCP/IP port 2331

Connecting to target...Connected to target

Waiting for GDB connection...Connected to 127.0.0.1

Reading all registers

Read 4 bytes @ address 0x00000000 (Data = 0xFFFFFFFF)

Target interface speed set to 1000 kHz

Resetting target

Halting target CPU...

...Target halted (PC = 0xFFFFFFFE)

R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000

R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000

R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000

R12= 00000000, R13= FFFFFFFC, MSP= FFFFFFFC, PSP= 00000000

R14(LR) = FFFFFFFF, R15(PC) = FFFFFFFE

XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000

CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00

Reading all registers

Select auto target interface speed (1429 kHz)

Flash breakpoints enabled

Semi-hosting enabled (Handle on BKPT)

Semihosting I/O set to TELNET Client

Downloading 1024 bytes @ address 0x00000000 - Verified OK

Downloading 16 bytes @ address 0x00000400 - Verified OK

Downloading 496 bytes @ address 0x00000410 - Verified OK

Downloading 8 bytes @ address 0x00000600 - Verified OK

Downloading 4 bytes @ address 0x00000608 - Verified OK

Downloading 4 bytes @ address 0x0000060C - Verified OK

Downloading 100 bytes @ address 0x00000610 - Verified OK

ERROR: Failed to prepare for programming.

Failed to execute RAMCode for RAM check!

Writing register (PC = 0x000004d8)

Read 4 bytes @ address 0x000004D8 (Data = 0xFFFFFFFF)

Resetting target

Halting target CPU...

...Target halted (PC = 0xFFFFFFFE)

Read 2 bytes @ address 0x0000050C (Data = 0xFFFF)

Read 2 bytes @ address 0x0000050C (Data = 0xFFFF)

Read 2 bytes @ address 0x0000050C (Data = 0xFFFF)

R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000

R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000

R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000

R12= 00000000, R13= FFFFFFFC, MSP= FFFFFFFC, PSP= 00000000

R14(LR) = FFFFFFFF, R15(PC) = FFFFFFFE

XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000

CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00

Reading all registers

WARNING: Failed to read memory @ address 0xFFFFFFFE

Setting breakpoint @ address 0x0000050C, Size = 2, BPHandle = 0x0001

Starting target CPU...

ERROR: Can not read register 15 (R15) while CPU is running

...Target halted (PC = 0x00000000)

Reading all registers

ERROR: Can not read register 0 (R0) while CPU is running

ERROR: Can not read register 1 (R1) while CPU is running

ERROR: Can not read register 2 (R2) while CPU is running

ERROR: Can not read register 3 (R3) while CPU is running

ERROR: Can not read register 4 (R4) while CPU is running

ERROR: Can not read register 5 (R5) while CPU is running

ERROR: Can not read register 6 (R6) while CPU is running

ERROR: Can not read register 7 (R7) while CPU is running

ERROR: Can not read register 8 (R8) while CPU is running

ERROR: Can not read register 9 (R9) while CPU is running

ERROR: Can not read register 10 (R10) while CPU is running

ERROR: Can not read register 11 (R11) while CPU is running

ERROR: Can not read register 12 (R12) while CPU is running

ERROR: Can not read register 13 (R13) while CPU is running

ERROR: Can not read register 14 (R14) while CPU is running

ERROR: Can not read register 15 (R15) while CPU is running

ERROR: Can not read register 16 (XPSR) while CPU is running

ERROR: Can not read register 17 (MSP) while CPU is running

ERROR: Can not read register 18 (PSP) while CPU is running

ERROR: Can not read register 24 (PRIMASK) while CPU is running

ERROR: Can not read register 25 (BASEPRI) while CPU is running

ERROR: Can not read register 26 (FAULTMASK) while CPU is running

ERROR: Can not read register 27 (CONTROL) while CPU is running

ERROR: Can not read register 32 (FPSCR) while CPU is running

ERROR: Can not read register 33 (FPS0) while CPU is running

ERROR: Can not read register 34 (FPS1) while CPU is running

ERROR: Can not read register 35 (FPS2) while CPU is running

ERROR: Can not read register 36 (FPS3) while CPU is running

ERROR: Can not read register 37 (FPS4) while CPU is running

ERROR: Can not read register 38 (FPS5) while CPU is running

ERROR: Can not read register 39 (FPS6) while CPU is running

ERROR: Can not read register 40 (FPS7) while CPU is running

ERROR: Can not read register 41 (FPS8) while CPU is running

ERROR: Can not read register 42 (FPS9) while CPU is running

ERROR: Can not read register 43 (FPS10) while CPU is running

ERROR: Can not read register 44 (FPS11) while CPU is running

ERROR: Can not read register 45 (FPS12) while CPU is running

ERROR: Can not read register 46 (FPS13) while CPU is running

ERROR: Can not read register 47 (FPS14) while CPU is running

ERROR: Can not read register 48 (FPS15) while CPU is running

ERROR: Can not read register 49 (FPS16) while CPU is running

ERROR: Can not read register 50 (FPS17) while CPU is running

ERROR: Can not read register 51 (FPS18) while CPU is running

ERROR: Can not read register 52 (FPS19) while CPU is running

ERROR: Can not read register 53 (FPS20) while CPU is running

ERROR: Can not read register 54 (FPS21) while CPU is running

ERROR: Can not read register 55 (FPS22) while CPU is running

ERROR: Can not read register 56 (FPS23) while CPU is running

ERROR: Can not read register 57 (FPS24) while CPU is running

ERROR: Can not read register 58 (FPS25) while CPU is running

ERROR: Can not read register 59 (FPS26) while CPU is running

ERROR: Can not read register 60 (FPS27) while CPU is running

ERROR: Can not read register 61 (FPS28) while CPU is running

ERROR: Can not read register 62 (FPS29) while CPU is running

ERROR: Can not read register 63 (FPS30) while CPU is running

ERROR: Can not read register 64 (FPS31) while CPU is running

Removing breakpoint @ address 0x0000050C, Size = 2

WARNING: Failed to read memory @ address 0x00000000

WARNING: Failed to read memory @ address 0x00000000

0 Kudos
Reply
9,175 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Don Turner

Could you tried to download the board-specific firmware for FRDM-K22F while the device is in bootloader mode? you could find it in the next link: SEGGER - The Embedded Experts - Downloads​ . After you drag and drop the .bin please unplug and re-plug and tell me if you get any error message. Try to reprogram again and let me know if something change.

Also, could you show me what you have in the Hardware->USB tab of the System information. it should appear the j-link listed.


Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
9,175 Views
donturner
Contributor III

Thanks for your help. Here's the steps I went through (just in case I'm missing something obvious).

1. Reboot the device into bootloader mode

2. In terminal do the following:

sudo mount -u -w -o sync /Volumes/BOOTLOADER

cp -X ~/Downloads/01_OpenSDA_FRDM-K22F.bin /Volumes/BOOTLOADER

The board immediately reboots. The LED next to the OpenSDA port is green, the LED next to the MK22F is red (is that normal?).

3. Verify that the OpenSDA firmware is installed. It is:

pastedImage_1.png

4. Load KDS and attempt to debug a "hello world" program. Same error as before "ERROR: Failed to prepare for programming."

5.  Checked in System information Hardware->USB and the device is *not* listed. Could I have a faulty board?

0 Kudos
Reply
9,176 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Don Turner

The LED next to the MK22F on is no normal, It means that the Target can be halt.

It seems to be a version problem with the firmware for FRDM-K22F. Could you try with the attached file? Again the same process, holding down the reset button and then connect the USB cable, copy the firmware to the bootloader, disconnect and reconnect and then try to program. (If a message proms that tell you to erase the device to unsecure please click "yes" immediately).

Please try this and tell me what you get and if you have any question also tell me.


Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------