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

Improvement to nRF51x22 OUTINIT anomoly workaround

In nrf_gpiote.h:

The workaround code for PAN_028 OUTINIT anomaly (#9) will cause the GPIO to glitch to the undesired state if it is already assigned to a GPIOTE and in the desired state but the GPIO output buffer contains the opposite state. To avoid this add the PREP lines above the high and low 'desired state workaround' code to prep the output buffer as it controls the pin briefly between the workaround pre-init and actual init code.

NRF_GPIO->OUTCLR = (1 << pin_number); // PREP GPIO out buffer for control between pre/actual init
NRF_GPIOTE->CONFIG[channel_number] = 
  (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) |
  (31UL << GPIOTE_CONFIG_PSEL_Pos) |
  (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos);                                    

NRF_GPIO->OUTSET = (1 << pin_number); // PREP GPIO out buffer for control between pre/actual init
NRF_GPIOTE->CONFIG[channel_number] = 
  (GPIOTE_CONFIG_MODE_Task <<  GPIOTE_CONFIG_MODE_Pos) |
  (31UL << GPIOTE_CONFIG_PSEL_Pos) |
  (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos);
Related