Can't use printf

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Can't use printf

2,692件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Fri Dec 02 13:29:28 MST 2011
I followed the tutorial and I can't seem to get this working. 

I'm using LPCXpresso 4.1.0 and Redlib(semihost) under mcu linker.  If I call _main() from my main program I get an error saying that I have an undefined reference to _main()

Can someone please help?

Thanks,
0 件の賞賛
返信
11 返答(返信)

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Sun Dec 04 12:52:36 MST 2011
[B]I replaced the cr_startup file with one generated from a semihost project(wizard) and it works[/B]
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sun Dec 04 06:33:17 MST 2011

Quote: Mike45

I attached the map file with an appended .txt



You map file seems to be missing most of its contents? Have you edited the file below posting. If so, then please post the original!

The other thing to check out is the startup code. LPCXpresso 4 requires slight tweaks to the startup code compared to very early versions of LPCXpresso 3, which can prevent semihosting taking place if not incorporated. It is possible that the example you are using does not have these changes if it is one of the older NXP created ones.

More information on this at:

http://support.code-red-tech.com/CodeRedWiki/redlib_v2_notes

It might be worth simply creating a new project using the project wizard, then copying the startup code across to the project where you can't get semihosting working.

Regards,
CodeRedSupport
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Sun Dec 04 01:38:41 MST 2011
This is so frustrating.  I don't know why it's not working.
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Sat Dec 03 14:04:26 MST 2011
Thanks guys for the help.  inserting a newline doesn't work.

I attached the map file with an appended .txt
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Dec 03 13:35:46 MST 2011
Try putting a newline at the end of your printf statement - the buffer used for the transfer may not get flushed without this.

If that doesn't work, I suggest that you post the map file generated by the linker when you build your project. This should normally get generated in the Debug/Release subdirectory of your project when you do a build.

Regards,
CodeRedSupport
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Sat Dec 03 12:54:12 MST 2011
removing the __main call makes the program run, but there is no output.

The mac/parallels thing works, but i don't like it.  The feel of switching between osx and windows doesn't feel right.  It's distracting when you have to switch back and forth from two different environments.

I plan on building a windows or linux machine sometime.
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Dec 02 22:32:04 MST 2011
Was the call to _main() there before you tried to switch to semihosting?
What happens when you switch back to "Redlib (nohost)" as a library?


Quote:
The only reason i included _main();  inside of my main program is  because the tutorial said that this function should be called if I used  the Redlib    

No, you don't need to call _main(). I'm not sure where you read this. It is not being called from the original sample that is delivered with LPCXpresso.
As soon as I include the same _main() statement in my code I get the same error - but everything just runs without it.

Maybe I should have mentioned this ... start with the examples that come with LPCXpresso (the ones in the LPC/LPC1000/... directory that opens when you click on "import projects" in the "Start here" tab.
These examples already use Redlib and these examples sometimes have bugs fixed or bogus removed.

When using Redlib there is an __main() (with 2 '_') that resides inside the Redlib library, that one then calls your main().

A totally different question:
Are you happy with the tools running under the parallels desktop?
I am saving for a Macbook Air and was wondering if this really works - including debugging.

Rob
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Fri Dec 02 14:33:36 MST 2011
I am certain I am using Relib(semihosting)

These are the errors I get :

[IMG]http://i40.tinypic.com/33f6d94.png[/IMG]


/*****************************************************************************
 *   blinky.c:  LED blinky C file for NXP LPC13xx Family Microprocessors
 *
 *   Copyright(C) 2008, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2008.08.20  ver 1.00    Preliminary version, first Release
 *
******************************************************************************/

#include "LPC13xx.h"                        /* LPC13xx definitions */
#include "clkconfig.h"
#include "gpio.h"
#include "config.h"
#include "timer32.h"
#include <stdio.h>

/* Main Program */
int main (void) {
  /* Basic chip initialization is taken care of in SystemInit() called
   * from the startup code. SystemInit() and chip settings are defined
   * in the CMSIS system_<part family>.c file.
   */

  /* Initialize 32-bit timer 0. TIME_INTERVAL is defined as 10mS */
  /* You may also want to use the Cortex SysTick timer to do this */
  init_timer32(0, TIME_INTERVAL);
  /* Enable timer 0. Our interrupt handler will begin incrementing
   * the TimeTick global each time timer 0 matches and resets.
   */
  enable_timer32(0);

  /* Initialize GPIO (sets up clock) */
  GPIOInit();
  /* Set LED port pin to output */
  GPIOSetDir( LED_PORT, LED_BIT, 1 );

  _main();
  int a = 5;
  printf("%i", a);

  while (1)                                /* Loop forever */
  {
/* Each time we wake up... */
/* Check TimeTick to see whether to set or clear the LED I/O pin */
if ( (timer32_0_counter%LED_TOGGLE_TICKS) < (LED_TOGGLE_TICKS/2) )
{
  GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
} else
{
  GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
}
    /* Go to sleep to save power between timer interrupts */
    __WFI();
  }
}
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Dec 02 14:01:46 MST 2011
Ah, I found something.
I am almost certain you are trying to use newlib instead of redlib.

redlib contains some initialization that is being performed by a function called __main() in the lib, that function then calls main() - defined in blinky.c

If you look at where the error is located (double click on the error message in the Problems tab in the bottom pane of you window, you will see this is in cr_startup_lpc13.c.
And what do we see there:

#if defined (__REDLIB__)
    // Call the Redlib library, which in turn calls main()
    __main() ;
#else
    main();
#endif

With the second part being grayed out: meaning that the __REDLIB__ label is defined.

Now either change your library settings to redlib(semihost) or undefine the __REDLIB__ label in your project settings (defined in the MCU C compiler -> Symbols tab within the C/C++ Build -> Settings

Rob
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Fri Dec 02 13:47:01 MST 2011
I'm modifying the blinky program.  All i am trying to do is print an integer to the console, like this which is included in my main program.

int a = 5;
printf("%i", a);

The only reason i included _main();  inside of my main program is because the tutorial said that this function should be called if I used the Redlib
0 件の賞賛
返信

2,626件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Dec 02 13:39:41 MST 2011
What are you trying to do?
the function main() is the function that is being called by the startup code - it contains the start of your program.

No idea what you are trying to do - no idea what this has to do with printf() ???
Please explain, also tell us which sample you are trying to run/change and post relevant bits of your code.

The only guess I have from your current report is that you forgot to define a function that is being called _main.

Rob
0 件の賞賛
返信