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:
Appreciate any help. Thanks
Kevin, by any chance did you remember to change the CPU preprocessor definition in your project's C build settings? For example:
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:
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!
-----------------------------------------------------------------------------------------------------------------------
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
Thanks for your reply. The watchdog is disabled and I'm not using any semihosting libraries as described. I am debug printf through UART.
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.
Memory settings of the target:
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.