Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

My LPC2106 won't return from function calls

My LPC2106 won't return from function calls

2005-03-04 by ooggie01

I'm trying to learn how to write C programs for my LPC-MT-2106 board 
from Olimex.  I'm using the GNU toolchain for compiling/linking and 
CrossWorks for programming the board.  I successfully got the LED to 
blink; however, as soon as I introduced a function call, my code 
won't work.  It still compiles/links/programs just fine, but the LED 
won't change.  It seems like the processor never returns from any 
function calls.  Any ideas why this may be?

I've included my code and makefile below.  The first program works 
and the second one doesn't.

Thanks in advance!

Thomas



// led.c without function calls

/* General Purpose Input/Output (GPIO) */
#define IOPIN	(*((volatile unsigned long *) 0xE0028000))
#define IOSET	(*((volatile unsigned long *) 0xE0028004))
#define IODIR	(*((volatile unsigned long *) 0xE0028008))	// 0-
INPUT 1-OUTPUT
#define IOCLR	(*((volatile unsigned long *) 0xE002800C))

#define LEDMASK 0x00001000	// LED	P0.12

unsigned int i;

int main()
{
	IODIR = IODIR | LEDMASK;
	while(1)
	{
		IOCLR = IOCLR | LEDMASK;
		for( i = 0; i < 50000; i++ )
		{
		}
		IOSET = IOSET | LEDMASK;
		for( i = 0; i < 50000; i++ )
		{
		}
	}
	return 0;
}
// EOF


// led.c with a function call

/* General Purpose Input/Output (GPIO) */
#define IOPIN	(*((volatile unsigned long *) 0xE0028000))
#define IOSET	(*((volatile unsigned long *) 0xE0028004))
#define IODIR	(*((volatile unsigned long *) 0xE0028008))	// 0-
INPUT 1-OUTPUT
#define IOCLR	(*((volatile unsigned long *) 0xE002800C))


#define LEDMASK 0x00001000	// LED	P0.12

void delay( unsigned int i )
{
	for( i = 0; i < 50000; i++ )
	{
	}
}

int main()
{
	IODIR = IODIR | LEDMASK;
	while(1)
	{
		IOCLR = IOCLR | LEDMASK;
		delay( 50000 );
		IOSET = IOSET | LEDMASK;
		delay( 50000 );
	}
	return 0;
}
// EOF


// makefile

arm-elf-gcc -c led.c -o led.o
arm-elf-gcc -TLPCH40MB.LD -nostartfiles -o led.elf led.o

Re: My LPC2106 won't return from function calls

2005-03-04 by charlesgrenz

Wheres the stack point to?

regards,
Charles


--- In lpc2000@yahoogroups.com, "ooggie01" <ooggie01@y...> wrote:
Show quoted textHide quoted text
> 
> I'm trying to learn how to write C programs for my LPC-MT-2106 board 
> from Olimex.  I'm using the GNU toolchain for compiling/linking and 
> CrossWorks for programming the board.  I successfully got the LED to 
> blink; however, as soon as I introduced a function call, my code 
> won't work.  It still compiles/links/programs just fine, but the LED 
> won't change.  It seems like the processor never returns from any 
> function calls.  Any ideas why this may be?
> 
> I've included my code and makefile below.  The first program works 
> and the second one doesn't.
> 
> Thanks in advance!
> 
> Thomas
> 
> 
> 
> // led.c without function calls
> 
> /* General Purpose Input/Output (GPIO) */
> #define IOPIN	(*((volatile unsigned long *) 0xE0028000))
> #define IOSET	(*((volatile unsigned long *) 0xE0028004))
> #define IODIR	(*((volatile unsigned long *) 0xE0028008))	// 0-
> INPUT 1-OUTPUT
> #define IOCLR	(*((volatile unsigned long *) 0xE002800C))
> 
> #define LEDMASK 0x00001000	// LED	P0.12
> 
> unsigned int i;
> 
> int main()
> {
> 	IODIR = IODIR | LEDMASK;
> 	while(1)
> 	{
> 		IOCLR = IOCLR | LEDMASK;
> 		for( i = 0; i < 50000; i++ )
> 		{
> 		}
> 		IOSET = IOSET | LEDMASK;
> 		for( i = 0; i < 50000; i++ )
> 		{
> 		}
> 	}
> 	return 0;
> }
> // EOF
> 
> 
> // led.c with a function call
> 
> /* General Purpose Input/Output (GPIO) */
> #define IOPIN	(*((volatile unsigned long *) 0xE0028000))
> #define IOSET	(*((volatile unsigned long *) 0xE0028004))
> #define IODIR	(*((volatile unsigned long *) 0xE0028008))	// 0-
> INPUT 1-OUTPUT
> #define IOCLR	(*((volatile unsigned long *) 0xE002800C))
> 
> 
> #define LEDMASK 0x00001000	// LED	P0.12
> 
> void delay( unsigned int i )
> {
> 	for( i = 0; i < 50000; i++ )
> 	{
> 	}
> }
> 
> int main()
> {
> 	IODIR = IODIR | LEDMASK;
> 	while(1)
> 	{
> 		IOCLR = IOCLR | LEDMASK;
> 		delay( 50000 );
> 		IOSET = IOSET | LEDMASK;
> 		delay( 50000 );
> 	}
> 	return 0;
> }
> // EOF
> 
> 
> // makefile
> 
> arm-elf-gcc -c led.c -o led.o
> arm-elf-gcc -TLPCH40MB.LD -nostartfiles -o led.elf led.o

Re: [lpc2000] Re: My LPC2106 won't return from function calls

2005-03-04 by Robert Adsett

At 11:03 PM 3/4/05 +0000, charlesgrenz wrote:
>Wheres the stack point to?

Actually if I read the code correctly he doesn't have any startup code at 
all.  He could get away with that as long as there were no interrupts set 
up and he made no function calls.  As soon as a function call is added or a 
significant number of local variables. boom...

The first thing he needs to do is add that a startup.  There are a few in 
the files section I believe.  There is also a startup file with the 
newlib-lpc stuff.  It should useable even without the rest of the library 
support http://www.aeolusdevelopment.com

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: [lpc2000] My LPC2106 won't return from function calls

2005-03-05 by Michael Anburaj

Hi Thomas,

Give this a try. You need to setup the SVC stack
before you can call functions from the entry point.
The simple application attached along with this should
run from both Flash & RAM (use tmon -- packaged along
with ucos_arm at my site).

http://geocities.com/michaelanburaj/controller.html

Cheers,
-Mike.

--- ooggie01 <ooggie01@...> wrote:
> 
> I'm trying to learn how to write C programs for my
> LPC-MT-2106 board 
> from Olimex.  I'm using the GNU toolchain for
> compiling/linking and 
> CrossWorks for programming the board.  I
> successfully got the LED to 
> blink; however, as soon as I introduced a function
> call, my code 
> won't work.  It still compiles/links/programs just
> fine, but the LED 
> won't change.  It seems like the processor never
> returns from any 
> function calls.  Any ideas why this may be?
> 
> I've included my code and makefile below.  The first
> program works 
> and the second one doesn't.
> 
> Thanks in advance!
> 
> Thomas
> 
> 
> 
> // led.c without function calls
> 
> /* General Purpose Input/Output (GPIO) */
> #define IOPIN	(*((volatile unsigned long *)
> 0xE0028000))
> #define IOSET	(*((volatile unsigned long *)
> 0xE0028004))
> #define IODIR	(*((volatile unsigned long *)
> 0xE0028008))	// 0-
> INPUT 1-OUTPUT
> #define IOCLR	(*((volatile unsigned long *)
> 0xE002800C))
> 
> #define LEDMASK 0x00001000	// LED	P0.12
> 
> unsigned int i;
> 
> int main()
> {
> 	IODIR = IODIR | LEDMASK;
> 	while(1)
> 	{
> 		IOCLR = IOCLR | LEDMASK;
> 		for( i = 0; i < 50000; i++ )
> 		{
> 		}
> 		IOSET = IOSET | LEDMASK;
> 		for( i = 0; i < 50000; i++ )
> 		{
> 		}
> 	}
> 	return 0;
> }
> // EOF
> 
> 
> // led.c with a function call
> 
> /* General Purpose Input/Output (GPIO) */
> #define IOPIN	(*((volatile unsigned long *)
> 0xE0028000))
> #define IOSET	(*((volatile unsigned long *)
> 0xE0028004))
> #define IODIR	(*((volatile unsigned long *)
> 0xE0028008))	// 0-
> INPUT 1-OUTPUT
> #define IOCLR	(*((volatile unsigned long *)
> 0xE002800C))
> 
> 
> #define LEDMASK 0x00001000	// LED	P0.12
> 
> void delay( unsigned int i )
> {
> 	for( i = 0; i < 50000; i++ )
> 	{
> 	}
> }
> 
> int main()
> {
> 	IODIR = IODIR | LEDMASK;
> 	while(1)
> 	{
> 		IOCLR = IOCLR | LEDMASK;
> 		delay( 50000 );
> 		IOSET = IOSET | LEDMASK;
> 		delay( 50000 );
> 	}
> 	return 0;
> }
> // EOF
> 
> 
> // makefile
> 
> arm-elf-gcc -c led.c -o led.o
> arm-elf-gcc -TLPCH40MB.LD -nostartfiles -o led.elf
> led.o
> 
> 
> 
> 
> 


	
		
__________________________________ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/

[Non-text portions of this message have been removed]

Re: [lpc2000] My LPC2106 won't return from function calls

2005-03-05 by Michael Johnson

If you use CrossWorks to build the program then the startup code will be 
included....

Regards
Michael
Show quoted textHide quoted text
>Hi Thomas,
>
>Give this a try. You need to setup the SVC stack
>before you can call functions from the entry point.
>The simple application attached along with this should
>run from both Flash & RAM (use tmon -- packaged along
>with ucos_arm at my site).
>
>http://geocities.com/michaelanburaj/controller.html
>
>Cheers,
>-Mike.
>
>--- ooggie01 <ooggie01@...> wrote:
>  
>
>>I'm trying to learn how to write C programs for my
>>LPC-MT-2106 board 
>>from Olimex.  I'm using the GNU toolchain for
>>compiling/linking and 
>>CrossWorks for programming the board.  I
>>successfully got the LED to 
>>blink; however, as soon as I introduced a function
>>call, my code 
>>won't work.  It still compiles/links/programs just
>>fine, but the LED 
>>won't change.  It seems like the processor never
>>returns from any 
>>function calls.  Any ideas why this may be?
>>
>>I've included my code and makefile below.  The first
>>program works 
>>and the second one doesn't.
>>
>>Thanks in advance!
>>
>>Thomas
>>
>>
>>
>>// led.c without function calls
>>
>>/* General Purpose Input/Output (GPIO) */
>>#define IOPIN	(*((volatile unsigned long *)
>>0xE0028000))
>>#define IOSET	(*((volatile unsigned long *)
>>0xE0028004))
>>#define IODIR	(*((volatile unsigned long *)
>>0xE0028008))	// 0-
>>INPUT 1-OUTPUT
>>#define IOCLR	(*((volatile unsigned long *)
>>0xE002800C))
>>
>>#define LEDMASK 0x00001000	// LED	P0.12
>>
>>unsigned int i;
>>
>>int main()
>>{
>>	IODIR = IODIR | LEDMASK;
>>	while(1)
>>	{
>>		IOCLR = IOCLR | LEDMASK;
>>		for( i = 0; i < 50000; i++ )
>>		{
>>		}
>>		IOSET = IOSET | LEDMASK;
>>		for( i = 0; i < 50000; i++ )
>>		{
>>		}
>>	}
>>	return 0;
>>}
>>// EOF
>>
>>
>>// led.c with a function call
>>
>>/* General Purpose Input/Output (GPIO) */
>>#define IOPIN	(*((volatile unsigned long *)
>>0xE0028000))
>>#define IOSET	(*((volatile unsigned long *)
>>0xE0028004))
>>#define IODIR	(*((volatile unsigned long *)
>>0xE0028008))	// 0-
>>INPUT 1-OUTPUT
>>#define IOCLR	(*((volatile unsigned long *)
>>0xE002800C))
>>
>>
>>#define LEDMASK 0x00001000	// LED	P0.12
>>
>>void delay( unsigned int i )
>>{
>>	for( i = 0; i < 50000; i++ )
>>	{
>>	}
>>}
>>
>>int main()
>>{
>>	IODIR = IODIR | LEDMASK;
>>	while(1)
>>	{
>>		IOCLR = IOCLR | LEDMASK;
>>		delay( 50000 );
>>		IOSET = IOSET | LEDMASK;
>>		delay( 50000 );
>>	}
>>	return 0;
>>}
>>// EOF
>>
>>
>>// makefile
>>
>>arm-elf-gcc -c led.c -o led.o
>>arm-elf-gcc -TLPCH40MB.LD -nostartfiles -o led.elf
>>led.o
>>
>>
>>
>>
>>
>>    
>>
>
>
>	
>		
>__________________________________ 
>Celebrate Yahoo!'s 10th Birthday! 
>Yahoo! Netrospective: 100 Moments of the Web 
>http://birthday.yahoo.com/netrospective/
>
>[Non-text portions of this message have been removed]
>
>
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>  
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.