cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with using GPIOs

joel.vonrotz
Associate II

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

2 REPLIES 2

You have to enable the GPIOA clock in RCC->IOPENR before you start writing into GPIOA registers.

Also, for initial experiments, you maybe don't want to mess with the system clock. You need to change the FLASH prescaler latency before you switch to higher clock, read FLASH read access latency chapter in RM.

JW

You can just cram down settings in the PLL and clock selection, need to wait for them to come up properly.

Try just running off HSI which system starts with.

GPIOA clock needs enabling before configuration.

Check Flash wait states required for higher speeds.

Use the debugger, check the register content as code proceeds, ie RCC, GPIO, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..