Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

compiler optimization level nrf api going wrong

sdk 17.0.2

IDE - segger embedded studio 

For the below given code, "pin" is not updating when GPIO goes high when optimization level is kept  "Level 3 for more speed". upto "level 2" , "pin" is updating properly.

Could you please let me know why the update is not happening for Level3 optimization ? I added "volatile" qualifier for variable "pin", but still not working

bool pin;

nrf_gpio_cfg_watcher(PIN12);

pin= nrf_gpio_pin_read(PIN12);

Parents
  • Hi,

     

    I believe the problem is that you are writing and reading the register within a few cpu cycles, where the peripheral clock has not been able to execute in between. This is due to CPU running on 64M and the peripheral clock tree running on 16M. 

    Try adding a dummy "peripheral clock wait" and see if this helps:

    (void)NRF_TIMER1->EVENTS_COMPARE[0];

     

    This will generate a 1 cycle (on the 16M PCLK) between the two calls.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    I believe the problem is that you are writing and reading the register within a few cpu cycles, where the peripheral clock has not been able to execute in between. This is due to CPU running on 64M and the peripheral clock tree running on 16M. 

    Try adding a dummy "peripheral clock wait" and see if this helps:

    (void)NRF_TIMER1->EVENTS_COMPARE[0];

     

    This will generate a 1 cycle (on the 16M PCLK) between the two calls.

     

    Kind regards,

    Håkon

Children
Related