This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using Optimisation in nrf51 Keil

Hi, I have the following piece of code.

nrf_gpio_cfg_output(PIN_EN_BSTR);

for(int i=0;i<300;i++)

{

	nrf_gpio_pin_clear(PIN_EN_BSTR);

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();	

	nrf_gpio_pin_set(PIN_EN_BSTR);

	nrf_delay_us(100);

}

nrf_gpio_pin_clear(PIN_EN_BSTR);

With Optimisation level O0, the off time is 2usec and with O3, the off time is 1.4usec. Will __NOPs have different cycle time for different optimisation levels? I thought they should be the same? Thanks.

Parents
  • Hi Aryan, Thanks for your reply. With O0, even without adding any nops(whether inline or not), there is a delay of 1usec between nrf_gpio_pin_clear and nrf_gpio_pin_set. With O3, there is 320nsec between nrf_gpio_pin_clear and nrf_gpio_pin_set. So, if I add nops(inline or not), this is further going to add delay in the O0. I want the delay to be the same irrespective whether it is O0 or O3. Is it possible? Thanks. THis is my code:

    nrf_gpio_cfg_output(PIN_EN_BSTR);
    
    for(int i=0;i<300;i++)
    
    {
    
    	nrf_gpio_pin_clear(PIN_EN_BSTR);
    
    
    	nrf_gpio_pin_set(PIN_EN_BSTR);
    
    	nrf_delay_us(100);
    
    }
    
    nrf_gpio_pin_clear(PIN_EN_BSTR);
    
Reply
  • Hi Aryan, Thanks for your reply. With O0, even without adding any nops(whether inline or not), there is a delay of 1usec between nrf_gpio_pin_clear and nrf_gpio_pin_set. With O3, there is 320nsec between nrf_gpio_pin_clear and nrf_gpio_pin_set. So, if I add nops(inline or not), this is further going to add delay in the O0. I want the delay to be the same irrespective whether it is O0 or O3. Is it possible? Thanks. THis is my code:

    nrf_gpio_cfg_output(PIN_EN_BSTR);
    
    for(int i=0;i<300;i++)
    
    {
    
    	nrf_gpio_pin_clear(PIN_EN_BSTR);
    
    
    	nrf_gpio_pin_set(PIN_EN_BSTR);
    
    	nrf_delay_us(100);
    
    }
    
    nrf_gpio_pin_clear(PIN_EN_BSTR);
    
Children
No Data