Question
Problems with using GPIOs
Hello ST Community
I'm currently trying to understand Cortex MCUs and thought about going to LL instead o fusing the HAL.
Since I've just started with the STM32G071RB, I'm having trouble configuring the Pin A5 as an output and setting it high.
My code looks like this:
#include "stm32g071xx.h"
#define RCC_CFGR_SW_PLLR (0x05)
#define RCC_PLLCFGR_PLLN_VAL8 (0x08 << RCC_PLLCFGR_PLLN_Pos)
#define RCC_PLLCFGR_PLLR_VAL4 (0x03 << RCC_PLLCFGR_PLLR_Pos)
#define RCC_PLLCFGR_PLLM_VAL1 (0x00 << RCC_PLLCFGR_PLLM_Pos)
int main(void)
{
// * wait for HSI16 to be ready
while((RCC->CR & RCC_CR_HSIRDY) == 0);
// * Enable PLL clock
RCC->CR |= (RCC_CR_PLLON);
// * Set PLL source to HSI16
RCC->PLLCFGR |= (RCC_PLLCFGR_PLLSRC_HSI);
// * Configure Prescaler & Multiplier of PLL
// M = 1 ; N = 8 ; R = 4 --> PLLRCLK = 32 MHz
RCC->PLLCFGR |= (RCC_PLLCFGR_PLLN_VAL8) |
(RCC_PLLCFGR_PLLM_VAL1) |
(RCC_PLLCFGR_PLLR_VAL4) |
(RCC_PLLCFGR_PLLREN);
// * Switch SYSCLK from the default HSISYS (HSI16 + prescaler) to PLL clock
RCC->CFGR = (RCC_CFGR_SW_PLLR);
// * configure PA5 as output
GPIOA->MODER &= 0xC00;
GPIOA->MODER |= 0x400;
GPIOA->ODR |= 0x20;
while(1)
{
}
}I hope someone can help me.
- Joel
