K21 constantly reset after downloading code

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

K21 constantly reset after downloading code

562 Views
kevinledinh
Contributor II

Hi all,

This is a long story so bear with me a bit.

I received a K60 projects a year ago and now I'm trying to port it to a K21. I've done the pin change and project name change without any errors. The project is compiled OK.

The first time I debug the code, the IDE jumps to a Hardfault Handler when the code tries to declare some pointer variables after start up LED sequence finishes. Fixed that. However, the code only run from top to bottom in debug mode (JLink programmer attached and controlled via CodeWarrior 10.6). When I try a power reset, the K21 constantly resets (start up LED sequence continuously runs).

There are two questions that I want to ask:

  1. What are the differences between debug mode and run mode?
  2. Could this maybe a clock configuration problem? At the moment, my clock configs are: Core clock 100MHz, Bus 50 MHz, Ext Bus clk 25Mhz, Flash clk 25MHz

Appreciate any help. Thanks

Labels (1)
4 Replies

417 Views
dave408
Senior Contributor II

Kevin, by any chance did you remember to change the CPU preprocessor definition in your project's C build settings?  For example:

pastedImage_1.png

0 Kudos

417 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Kevin Le Dinh:

If the watchdog is enabled it may be that the project is using one of the CodeWarrior semihosting libraries. Please check the next discussion about this issue:

Re: MK10DX256VLK7 doesn't run standalone, just when debugging. Verified it's running from FLASH, not...

Otherwise please let us know the full part numbers of your K21 and K60 and if possible share the project so I can give it a check from my side.


Regards!,
Jorge Gonzalez

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

0 Kudos

417 Views
kevinledinh
Contributor II

Hi,

I finally found the solution to my problem. It all comes down to pointer initialisation in my code. Because I didn't write this code, I didn't know that there there was a typdef variable which had various pointers. These needs to be initialised properly.

Thank you all for your help

417 Views
kevinledinh
Contributor II

Thanks for your reply. The watchdog is disabled and I'm not using any semihosting libraries as described. I am debug printf through UART.

community-1.png

The full part number is K21FN1M0VMC12 and K60DN512ZVLL10. I want to convert from a K60 project to K21. Is there any safe way to share the project with you?

An update to the problem. When I make some changes to the code and debug on the target, the hardfault handler is triggered. Looking closely at the handler, there is a bus fault and the rogue address is saved in the Bus Fault Address Register (BFAR). This address is assigned as a value to a pointer variable in my code.

stack-variables.JPG

Memory settings of the target:

memory.JPG

If I debug a gain with the same code, the micro (or sth else) seems to realise the problem and assign a more appropriate value to the pointer. Now I know where the problem is actually is.

The question really is why the correct behaviour is observed in debug mode?

Many thanks.

0 Kudos