GPIO too slow with CMSIS compiled with CodeRed

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

GPIO too slow with CMSIS compiled with CodeRed

1,310 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yoko on Tue Mar 15 19:16:24 MST 2011
Hi,

   I have been doing a test with GPIO.  Test is very simple.  Just an endless while loop toggling an I/O pin. Like bellow

while(1) {
     LPC_GPIO1->FIOSET = (1 << 31);
     LPC_GPIO1->FIOCLR = (1 << 31);
};


This code compile using mBed online compiler, I can achieve ~24MHz.  Meseaured with a scope on the pin.  Same code compiled with CodeRed CMSIS, with modified clock setting for 120MHz CPU.  I get only <11MHz.  With default CodeRed CMSIS settings, I only get about 2MHz.  The tests ran on same board of course.

Can any one explain why and how performance can be improved ?  There must be some kind of settings that are missing.
0 Kudos
Reply
6 Replies

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yoko on Wed Mar 16 07:10:49 MST 2011
I think I got it.  In the C++ project the project settings of the C portion wasn't set.  After putting the the same settings everything is fine.  So for C++ projects, both C & C++ setting has to be configured even though the code is .cpp (not .c).

Now I got I/O arround 30MHz :)
0 Kudos
Reply

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yoko on Wed Mar 16 06:52:40 MST 2011
I think i got some thing.  It's related to how the project was create.  I recreate a new C project and get good results. Same code copy & paste over.  The first test was created as C++ project.  I am going to try to find what is the different.
0 Kudos
Reply

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 16 06:37:19 MST 2011

Quote:

Have you actually measure it with a scope ?


Sure, my dog is too old to smell it :)

Quote:

...CodeRed CMSIS, with modified clock setting for 120MHz...


Have you measured it with a scope ?
0 Kudos
Reply

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yoko on Wed Mar 16 06:15:51 MST 2011
Optimization is -O3 compiled in release mode, with debug disable. No jtag.  Just flash it and let run free.


Quote:
Note: This sample is toggling with 25MHz (LPC1769 /100MHz/Optimization: Optimize Most(-O3)) .



Have you actually measure it with a scope ? I can't get that number compiled with CodeRed.  Ony comiple with mBed online compiler that I get 24MHz.

I know all about writing optimized C code.  I need to know what caused the slow down in CodRed but not with mBed online compiler.  It must be something in the startup of CMSIS.
0 Kudos
Reply

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Mar 16 04:12:41 MST 2011

Quote:
Test is very simple.


[INDENT]No.
[/INDENT]
Quote:
There must be some kind of settings that are missing.


[INDENT]Yes, as John mentioned before it's Optimization.


[/INDENT]Default setting in Debug Configuration is 'Optimization: None(-O0)'. So it's easier for you to use Disassembly view and 'Instruction Stepping Mode' (little 'i->' icon) to step through your code (and try to understand what's happening). Debugging is not possible in mbed and therefore no need to reduce optimization level while debugging.

In Disassembly view you can see how optimization works:
//LED
#define LED  (1 << 13)
#define LED_ON  LPC_GPIO2->FIOSET=LED
#define LED_OFF LPC_GPIO2->FIOCLR=LED
...
int main(void)
{
...
 LPC_GPIO2->FIODIR |= LED;   //set LED output
 while(1)
 {
  LED_ON;
  LED_OFF;
 }
 return 0;
}

Disassembly view Optimization: None(-O0):
[INDENT]LED_ON;
0x000001ca <main+70>: movw r3, #49216 ; 0xc040
0x000001ce <main+74>: movt r3, #8201 ; 0x2009
0x000001d2 <main+78>: mov.w r2, #8192 ; 0x2000
0x000001d6 <main+82>: str r2, [r3, #24]
LED_OFF;
0x000001d8 <main+84>: movw r3, #49216 ; 0xc040
0x000001dc <main+88>: movt r3, #8201 ; 0x2009
0x000001e0 <main+92>: mov.w r2, #8192 ; 0x2000
0x000001e4 <main+96>: str r2, [r3, #28]
0x000001e6 <main+98>: b.n 0x1ca <main+70>
[/INDENT]Disassembly view Optimization: Optimize Most(-O3):
[INDENT]LPC_GPIO2->FIODIR |= LED; //set LED output
0x00000184 <main>: movw r2, #49216 ; 0xc040
0x00000188 <main+4>: movt r2, #8201 ; 0x2009
0x0000018c <main+8>: ldr r3, [r2, #0]
0x0000018e <main+10>: orr.w r3, r3, #8192 ; 0x2000
0x00000192 <main+14>: str r3, [r2, #0]
LED_ON;
0x00000194 <main+16>: mov.w r3, #8192 ; 0x2000
0x00000198 <main+20>: str r3, [r2, #24]
LED_OFF;
0x0000019a <main+22>: str r3, [r2, #28]
0x0000019c <main+24>: b.n 0x198 <main+20>
[/INDENT]
Result:[LIST=1]
[*]Some values (like 1<<13) are loaded in registers, so less instructions in while loop makes your toggling faster.
[*]If this registers are needed for something more important, compiler will step back to load them and don't waste valuable registers.
[/LIST]Note: This sample is toggling with 25MHz (LPC1769 /100MHz/Optimization: Optimize Most(-O3)) .
0 Kudos
Reply

1,295 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Tue Mar 15 22:20:41 MST 2011
What optimization setting does each one use?
0 Kudos
Reply