printf() on uart0 hard fault

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

printf() on uart0 hard fault

3,264 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Wed Aug 22 06:54:34 MST 2012
Hello,
I am working with Red Suite on a LPC1768. At the moment I have a problem with printf() on uart0. To be more precicely: If the debugger enter the printf() function. I get a Hard Fault!

If I create a new empty Semihost Project the printf() comand works!

Things to say:
- The code I use is taken from the uart_printf template from Code Red. (uart0.h, uart0.c, retarget.c)
- It is a semihost project

In the attachement is a desktop print of the core registers and the .c/.h files I use...


Does anybody nows how to fix this or nows how to find my mistake?
Thanks for your reply!
0 Kudos
Reply
16 Replies

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Fri Aug 24 01:03:32 MST 2012
Hey zero, it works well. Thanks for your help I lerned a lot!
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Aug 23 08:05:34 MST 2012
Since you can't execute your tests earlier it's worth a trial...
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 07:39:40 MST 2012
That means I have to execute the Ram and CPU register test in front of

Quote:

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Copy the data segment initializers from flash to SRAM.[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]


to get a running printf()?

In my opinion that would make sense! Am I right?
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Aug 23 07:23:33 MST 2012
There's a file cr_startup_lpc176x.c in your src folder

And at this point the fun is starting:
//*****************************************************************************
// [COLOR=Red]Reset entry point[/COLOR] for your code.
// Sets up a simple runtime environment and initializes the C/C++
// library.
//*****************************************************************************
__attribute__ ((section(".after_vectors")))
[COLOR=Red]void ResetISR(void) [/COLOR]
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 07:14:13 MST 2012
ok zero, shame on me! I am a bad bad guy....


Quote:

#1 You are changing half of an old CMSIS version instead just adding your struct in an own header?


I will change to the standart cmsis at some time.


Quote:

#2 You're writing to RAM after cr_startup_lpc... is executed?


Yes, you are right I am writing after main to Ram... Please tell me when I should do that? Our tell me were I can get informations about the startup skript! I am relative new in µCs (maybe 5 month) so I don't know exactly what it does!

kind regards and thanks for your patience :o
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Aug 23 06:21:52 MST 2012

Quote:

I know that the printf() command works without my syst stuff.

So the issue of this thread is: I've added something somehow and now I get a hard fault ;)


Quote:

If you do, you have to change to my CMSIS Version to get a running version without compiler errors!

Come on. I'm too old to fall into this trap :eek:

#1 You are changing half of an old CMSIS version instead just adding your struct in an own header?

#2 You're writing to RAM after cr_startup_lpc... is executed?

AN is warning you:

Quote:

[B][SIZE=6][COLOR=Red]Preferably execute this test prior to branch to main.[/COLOR][/SIZE][/B]

#3 After that you are surprised that you get a hard fault while using printf?

Shame on you :rolleyes:
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 05:08:46 MST 2012
I know that the printf() command works without my syst stuff. But I have to execute a Ram test on every start of my system! Please include the the [SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
[COLOR=black]IEC60335_RAMtest_POST()- function and you will see the problem.  If you do, you have to change to my CMSIS Version to get a running version without compiler errors![/COLOR]
[COLOR=#000000][/COLOR]
[COLOR=#000000]sorry for my ambiguous description! :confused:[/COLOR]

[/COLOR][/SIZE][/COLOR][/SIZE]
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Aug 23 04:56:12 MST 2012
I've not used your syst stuff, just used printf as I'm used to :)

No problems with my LPCXpresso without retargeting and no problems with retargeting to UART.

My UART->USB converter is receiving without problems after adding a delay.

I'm using CMSIS2.0 because I refuse to test code with old CMSIS versions :rolleyes:
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 04:44:09 MST 2012
Hey zero, thanks for the quick response! The RAM test and printf() works? No Hard fault? Why you switch to CMSIS2?
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Aug 23 04:30:24 MST 2012
After switching your project to CMSIS2.0, throwing out syst folder stuff and adding a delay

   for(i=0;i<1E5;i++);  //no delay, no fun
   printf("printf test\r\n");
your project is uarting fine here :mad:

So what was the problem :confused:
0 Kudos
Reply

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 04:15:04 MST 2012
I forgot to post the user manual for the IEC60335 from nxp!

http://www.nxp.com/documents/application_note/AN10918.pdf

kind regards!
0 Kudos
Reply

3,081 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 04:07:33 MST 2012

Quote:

You've damaged or mutilated your project, so what are you expecting without showing this project ;)



Hey kayoda, I have already created a poject which I can upload. Now I hope we can switch from a monologue to a dialog! :D

In the attached project you can see that the printf() command works, if the RAMtest_POST() function (in main) is commented out. What's the reason for this behavior? The project is for an lpc1768 written and please use the attaches cmsis library...
0 Kudos
Reply

3,081 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Thu Aug 23 01:38:59 MST 2012
I don't know what you are trying to do and what you are expecting here :confused:

You've damaged or mutilated your project, so what are you expecting without showing this project  ;)

Right now, you've started a monologue :)
0 Kudos
Reply

3,081 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Thu Aug 23 01:22:57 MST 2012
I am a littel bit further. The hard fault is based on my RAM pattern test at the begining of my main loop. Herefor I use the NXP "Cortex-M3 IEC60335 Class B library". This storage test leaves in all RAM registers a 0x55555555. That means all of my Ram content is gone...

Is there any relation between Ram content and printf() Funktion?

Thanks in advance!
0 Kudos
Reply

3,081 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xpresso_1769 on Wed Aug 22 07:24:45 MST 2012
Oh, your right. Hier the new zip-File!
0 Kudos
Reply

3,081 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Aug 22 07:18:16 MST 2012

Quote: xpresso_1769
Does anybody nows how to fix this or nows how to find my mistake?



Post your project, it's easier to import your project with all settings than guessing and creating new projects with your files :)

BTW: Your zip file seems to be damaged :eek:
0 Kudos
Reply