Skip to main content
shafeeshad
Visitor II
October 13, 2016
Question

How to lock pin by GPIOx_LCKR register

  • October 13, 2016
  • 1 reply
  • 773 views
Posted on October 13, 2016 at 12:24

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.
    This topic has been closed for replies.

    1 reply

    Amel NASRI
    Technical Moderator
    October 31, 2016
    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.