How to lock the GPIO pin using LCKR register in stm32f10x series?
It does not work because doing a read-modify-write operations on the register breaks the required sequence for locking.
Besides when the lock is already set, there is no way to unlock it without reset, so the unlock code will not work, and you can't unlock or lock any other pins if you already have set the lock.