KW41Z printf on startup file resets program

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

KW41Z printf on startup file resets program

Jump to solution
877 Views
satsok_n
Contributor III

I am trying to run some code in file startup_mkw41z4.c following this post https://mcuoneclipse.com/2019/02/17/debugging-the-startup-code-with-eclipse-and-gdb/.When I try to run some code in this file I manage to run first part and when I use printf it resets the program. If I remove printf the code runs normaly. Any suggestions? 

0 Kudos
1 Solution
859 Views
ErichStyger
Senior Contributor V

a good way is to use SEGGER RTT (see https://mcuoneclipse.com/2015/07/07/using-segger-real-time-terminal-rtt-with-eclipse/) which is fast and you can easily export lots of data.

Another way is to export memory directly, see https://mcuoneclipse.com/2012/05/04/dump-my-device-memory/

Or if you want to do this for individual variables, you easily can do this with gdb and you can script it, see https://mcuoneclipse.com/2020/04/13/dumping-variables-and-arrays-with-gdb-in-eclipse/

 

I hope this helps,

Erich

View solution in original post

0 Kudos
5 Replies
865 Views
ErichStyger
Senior Contributor V

Hi @satsok_n ,

it really depends what you are using for the printf: UART? semihosting?

In both cases you will need to have the drivers behind it intialized and working. For example  you cannot access/use the UART if the peripheral is not clocked and pins are not muxed (done in main, not in the startup code).

If using semihosting you need to initialize the standard library (done at the end of the startup code).

So while you could use printf, it is really not good to use it, see https://mcuoneclipse.com/2013/04/19/why-i-dont-like-printf/ because it uses lots of stack space and memory.

I hope this helps,

Erich

0 Kudos
862 Views
satsok_n
Contributor III

I used printf in order to export some variables to console and copy paste them in a text file. Can you suggest any other way to export data?

0 Kudos
860 Views
ErichStyger
Senior Contributor V

a good way is to use SEGGER RTT (see https://mcuoneclipse.com/2015/07/07/using-segger-real-time-terminal-rtt-with-eclipse/) which is fast and you can easily export lots of data.

Another way is to export memory directly, see https://mcuoneclipse.com/2012/05/04/dump-my-device-memory/

Or if you want to do this for individual variables, you easily can do this with gdb and you can script it, see https://mcuoneclipse.com/2020/04/13/dumping-variables-and-arrays-with-gdb-in-eclipse/

 

I hope this helps,

Erich

0 Kudos
848 Views
satsok_n
Contributor III

Thanks a lot. This has been very helpful. 

0 Kudos
872 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Before you use printf function, you should make sure you have initialized the uart. 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos