# produce timer counter with 10 nanosecend duration in stm32F7

I want to set timer counetr every 10 nanosecend and finaly use that as delay to toggle GPIO in stm 32f7. I use external clock and use pll to produce 200 mhz clock to TIM1. this timer counter set to every 10 nanosecend. the delay function is:

void delay (uint16_t delay)
{
htim1.Instance->CNT=0;
while(htim1.Instance->CNT<delay);
}


and in while :

  while (1)
{
GPIOA->ODR=0x40;
delay(1);
GPIOA->ODR=0x0;
delay(1);
}


in times over 1 microsecend, time of toggle pin is ok, but when timer set to 100 or 10 nano secend , the instructions in delay take time about 300 ns and, the time of toggle can't be lower than 300 ns. when i delete these instructions in delay function, the GPIO, toggle with 108 mhz. these two line destroy time of code and i cant find the reson of that. please help me. I use nulceo-f746zg.

• At 200 MHz, 10 ns is 2 clock cycles; it might be possible to do this in assembly code (but maybe not). You need to understand that the timer setup and test takes clock cycles as well. Take a look at the assembly output. – Peter Smith Jan 19 at 15:08
• @PeterSmith - You should turn your comment into an answer and elaborate a bit more on why what the OP is asking is not feasible at the 10ns or probably not even the 100ns timing span. – Michael Karas Jan 19 at 15:43
• even just calling the function I'm sure devastates that timing because of compiler generated preamble and epilog code :-) – vicatcu Jan 19 at 15:55