STM32F051 bricked after low level programming of GPIO pins
I am using STM32F051R8T6 controller. I was initially using the standard peripheral library's inbuilt functions and structures to initialize the peripherals for eg. GPIO. Now, I want to optimize my code(size) by trying to directly write into the register for initializing my GPIO pins. But, to my surprise, after downloading the flash to the controller, it stopped working, as in the IDE could not communicate with the controller( unable to erase, or flash) any further. I tried using STLink Utility as well. Did I accidentally change any pin config that is supposed to be untouched for the normal operation of the controller? Is the device bricked? How can it be recovered?
Please find the initialization code below:
void Init_Gpio(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
GPIOA -> MODER |= 0x000AF88B;
GPIOB -> MODER |= 0xAAAA58AA;
GPIOC -> MODER |= 0x0AAAAA00;
GPIOF -> MODER |= 0x0000A100;
GPIOA -> OTYPER |= 0;
GPIOB -> OTYPER |= 0;
GPIOC -> OTYPER |= 0;
GPIOF -> OTYPER |= 0;
GPIOA -> OSPEEDR |= 0x00200000;
GPIOB -> OSPEEDR |= 0 ;
GPIOC -> OSPEEDR |= 0 ;
GPIOF -> OSPEEDR |= 0 ;
GPIOA -> PUPDR |= 0x008A0440;
GPIOB -> PUPDR |= 0x0000A415;
GPIOC -> PUPDR |= 0x0AAAAA00;
GPIOF -> PUPDR |= 0x00000400;
GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_1);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_1);
}