Question
LED Blinking on STM32 via Register programming problem
Hi, I am trying to learn register programming, so I am trying to write a code for STM32G071rb for blinking LD4 which is connected to Pin PA5 using Registers. But unfortunately not only the LED is not blinking, but also the code stocks in line 43 during debugging:
Below you can see the code:
I would appreciate it if you could guide me through this.
// Xtal is set to 64
// Clk is set to 10 MHz
#include "stm32g071xx.h"
void SysClockConfig(void);
void GPIO_Config (void);
void delay (uint32_t time);
int main (void)
{
SysClockConfig ();
GPIO_Config ();
while (1)
{
GPIOA->BSRR |= (1<<5); // Set the pin PA5
delay (2000);
GPIOA->BSRR |= ((1<<5) <<16); // Reset pin PA5
delay (2000);
}
}
void SysClockConfig(void)
{
/*************>>>>>>> STEPS FOLLOWED <<<<<<<<************
1. ENABLE HSE and wait for the HSE to become Ready
2. Set the POWER ENABLE CLOCK and VOLTAGE REGULATOR
3. Configure the FLASH PREFETCH and the LATENCY Related Settings
4. Configure the PRESCALARS HCLK, PCLK
5. Configure the MAIN PLL
6. Enable the PLL and wait for it to become ready
7. Select the Clock Source and wait for it to be set
********************************************************/
//converted value
#define PLL_M 0 //1
#define PLL_N 16 //16
#define PLL_R 1 //2
// 1. ENABLE HSE and wait for the HSE to become Ready
RCC->CR |= RCC_CR_HSEON;
while (!(RCC->CR & RCC_CR_HSERDY));
// 2. Set the POWER ENABLE CLOCK and VOLTAGE REGULATOR
RCC->APBENR1 |= RCC_APBENR1_PWREN;
PWR->CR1 |= PWR_CR1_VOS;
// 3. Configure the FLASH PREFETCH and the LATENCY Related Settings
FLASH->ACR = FLASH_ACR_ICEN | FLASH_ACR_PRFTEN | FLASH_ACR_LATENCY_2;
// 4. Configure the PRESCALARS HCLK, PCLK
// AHB PR
RCC->CFGR |= RCC_CFGR_HPRE_0; // RCC->CFGR &= ~(1<<4);
// 5. Configure the MAIN PLL
RCC->PLLCFGR = (PLL_M <<4) | (PLL_N << 8) | (PLL_R <<29) | (RCC_PLLCFGR_PLLSRC_HSE);
// 6. Enable the PLL and wait for it to become ready
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR & RCC_CR_PLLRDY));
// 7. Select the Clock Source and wait for it to be set
RCC->CFGR |= RCC_CFGR_SW ;
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);
}
void GPIO_Config (void)
{
/************ STEPS FOLLOWED ***********
1. Enable the GPIO CLOCK
2. Set the Pin as OUTPUT
3. Configure the OUTPUT MODE
***************************************/
// 1. Enable the GPIO CLOCK
RCC->IOPENR |= (1<<0);
// 2. Set the Pin as OUTPUT
GPIOA->MODER |= (1<<10);
// 3. Configure the OUTPUT MODE
GPIOA->OTYPER = 0;
GPIOA->OSPEEDR = 0;
}
void delay (uint32_t time)
{
while (time--);
}