Hello Mahmoud
You can't achieve high GPIO toggle speed by using library functions like Chip_GPIO_SetPinState. Those functions always have overhead that slows you down. You need to toggle by writing directly to GPIO registers, like so:
LPC_GPIO_T *gp; //make a pointer of type GPIO structure
gp = LPC_GPIO; //point to base address of GPIO registers in memory space
gp->DIR[2]=0xFFFFFFFF; // set all port 2 pins as output
gp->SET[2]=1<<17; // set pin 17 of port 2
gp->CLR[2]=1<<17;// clear pin 17 of port 2
Then, also realize that the while(1) {} loop also slows you down, because you have a conditional check and a jump in each cycle. If you want to see real toggling speed, you need to set and clear in a long unrolled loop:
while (1) {
gp->SET[2]=1<<17; // set pin 17 of port 2
gp->CLR[2]=1<<17;// clear pin 17 of port 2
gp->SET[2]=1<<17; // set pin 17 of port 2
gp->SET[2]=1<<17; // set pin 17 of port 2
gp->CLR[2]=1<<17;// clear pin 17 of port 2
gp->CLR[2]=1<<17;// clear pin 17 of port 2
...
}
Please notice that how you do this (writing to GPIO register structure) is dependent on the model of the MCU. This code is intended to show you the idea, it does not necessarily work on LPC812