AnsweredAssumed Answered

How to lock pin by GPIOx_LCKR register

Question asked by shafeeshad.mehdi on Oct 13, 2016
Latest reply on Oct 31, 2016 by Amel N
Hi everybody
I have read something about GPIOx_LCKR register in RM0008 page 173-174.
Those pages are about pin lock configuration in STM32f0xx.
As you know when we lock a pin, it's state should not be changed by configuring as high or low in pushpull. but my codes can't achieve that goal. Can you tell me what the problem is?


int main(void)
{
HAL_GPIO_LockPin(GPIOD,GPIO_PIN_7);
  while (1)
  {
     HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_7);
     HAL_Delay(200);
  }
}
 /////////////////////////////////////////////////////


int main()
{
    uint32_t tmp = 0x00010000;
    
    tmp |= 0x00000080;
  // Set LCKK bit
  GPIOD->LCKR = tmp;
  // Reset LCKK bit
  GPIOD->LCKR = 0x00000080;
  // Set LCKK bit
  GPIOD->LCKR = tmp;
  // Read LCKK bit
  tmp = GPIOD->LCKR;
  // Read LCKK bit
  tmp = GPIOD->LCKR;

while(1)
    {
      GPIOD->BSRR   &= ~0x00000080;
      GPIOD->BSRR   |=  0x00000080;
       delay(1000000);
      GPIOD->BSRR   &= ~0x00800000;
      GPIOD->BSRR   |=  0x00800000;
       delay(1000000);
    }
}

//////////////////////////////////////////////////
at above codes LED PD.7 keeps blinking.

Outcomes