cancel
Showing results for 
Search instead for 
Did you mean: 

How to lock pin by GPIOx_LCKR register

shafeeshad
Associate
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.
1 REPLY 1
Amel NASRI
ST Employee
Posted on October 31, 2016 at 14:01

Hi shafeeshad.mehdi,

Based on 

http://www.st.com/content/ccc/resource/technical/document/reference_manual/c2/f8/8a/f2/18/e6/43/96/DM00031936.pdf/files/DM00031936.pdf/jcr:content/translations/en.DM00031936.pdf

 and 

http://www.st.com/content/ccc/resource/technical/document/reference_manual/cf/10/a8/c4/29/fb/4c/42/DM00091010.pdf/files/DM00091010.pdf/jcr:content/translations/en.DM00091010.pdf

 (STM32F0 reference manuals), the locking mechanism is available only for ports A and B (not port D).

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.