cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0: cannot activate GPIOB AND GPIOD

kuda1311
Associate II

I have an other issue at the moment. I cant use the GPIOD, VSSI02 is on 3.3V. Im using stm32g0b1kb. It wont toggle it wont read, it does nothing. I have created a small application far away from my main app just to test the GPIO functions.

Hi, I a already Figured it out. But Thank you for the response. I have an other issue at the moment. I cant use the GPIOD, VSSI02 is on 3.3V. Im using stm32g0b1kb. It wont toggle it wont read, it does nothing. What am I missing.

I cant toggle, read or write them? PB9 PB6, and PD1 to PD3

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
void Check_VDDIO2_Status(void);
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
uint8_t rd10_switch_ready = 0;
volatile uint32_t current_time = 0;
volatile uint32_t previous_time = 0;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* PWR-Clock sicherstellen (falls nicht schon in SystemClock_Config getan) */
  __HAL_RCC_PWR_CLK_ENABLE();

  /* VDDIO2 einmal definierte Reihenfolge: erst aus, dann an */
  HAL_PWREx_DisableVddIO2();
  HAL_Delay(10);

  HAL_PWREx_EnableVddIO2(); // aktiviert die Domäne per Software
  HAL_Delay(10);            // etwas Wartezeit
  Check_VDDIO2_Status();    // prüft das Status-Register
  HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD2_STROBE);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

          HAL_GPIO_TogglePin(iBIT1_GPIO_Port, iBIT1_Pin);
//      GPIO_PinState p2 = HAL_GPIO_ReadPin(iBIT2_GPIO_Port, iBIT2_Pin);
//      GPIO_PinState p3 = HAL_GPIO_ReadPin(iBIT3_GPIO_Port, iBIT3_Pin);
//      GPIO_PinState p4 = HAL_GPIO_ReadPin(iBIT4_GPIO_Port, iBIT4_Pin);

      /* Hier Breakpoint setzen und p1–p4 beobachten */
      HAL_Delay(100);

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief GPIO Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* USER CODE BEGIN MX_GPIO_Init_1 */
  /* Ports aktivieren: hier minimal die Ports, auf denen deine iBIT-Pins liegen */
  /* Wenn z.B. iBIT1 auf GPIOB, iBIT4 auf GPIOD liegt, musst du beide aktivieren. */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  /* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin : iBIT1_Pin */
  GPIO_InitStruct.Pin = iBIT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(iBIT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : iBIT2_Pin iBIT3_Pin */
  GPIO_InitStruct.Pin = iBIT2_Pin|iBIT3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pin : iBIT4_Pin */
  GPIO_InitStruct.Pin = iBIT4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(iBIT4_GPIO_Port, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

  /* USER CODE BEGIN MX_GPIO_Init_2 */
  /* iBIT1: Interrupt-Eingang (Rising) */
  GPIO_InitStruct.Pin = iBIT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(iBIT1_GPIO_Port, &GPIO_InitStruct);

  /* iBIT2: normaler digitaler Eingang */
  GPIO_InitStruct.Pin = iBIT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(iBIT2_GPIO_Port, &GPIO_InitStruct);

  /* iBIT3: normaler digitaler Eingang (nicht analog, wenn du ihn lesen willst) */
  GPIO_InitStruct.Pin = iBIT3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(iBIT3_GPIO_Port, &GPIO_InitStruct);

  /* iBIT4: normaler digitaler Eingang */
  GPIO_InitStruct.Pin = iBIT4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(iBIT4_GPIO_Port, &GPIO_InitStruct);

  /* EXTI interrupt init – nur nötig, wenn iBIT1 auch wirklich an EXTI0_1 hängt */
  HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
  /* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

void Check_VDDIO2_Status(void)
{
    uint32_t sr2 = PWR->SR2;

    /* Hier könntest du gezielt auf ein bestimmtes Bit prüfen, z.B.:
       if (sr2 & PWR_SR2_PVMO2) { ... } */

    if (sr2)
    {
        uint8_t a = 0;
        (void)a;
    }
    else
    {
        uint8_t a = 1;
        (void)a;
    }
}

/**
  * @brief  EXTI line rising detection callback.
  * @PAram  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
    current_time = HAL_GetTick();

    if ((GPIO_Pin == iBIT1_Pin) && ((current_time - previous_time) > 100))
    {
        rd10_switch_ready = 1;
        previous_time = current_time;
    }
    else
    {
        rd10_switch_ready = 0;
    }
}

/**
  * @brief  EXTI line falling detection callback.
  * @PAram  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
{
    current_time = HAL_GetTick();

    if ((GPIO_Pin == iBIT1_Pin) && ((current_time - previous_time) > 100))
    {
        rd10_switch_ready = 1;
        previous_time = current_time;
    }
    else
    {
        rd10_switch_ready = 0;
    }
}

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

Edited to apply source code formatting - please see How to insert source code for future reference.

11 REPLIES 11
TDK
Super User

> I cant use the GPIOD, VSSI02 is on 3.3V. Im using stm32g0b1kb

The stm32g0b1kb doesn't have PD1, PD2 or PD3 pins, or any pins on GPIOD. Pins that do not exist cannot be used and will not function as expected.

TDK_0-1764857427871.png

 

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Super User

It looks like there are several chips that start with STM32G0B1KB and some of them have VDDIO2, some not. Probably you are using the wrong one.


What is the full part number of the chip you are using? What is printed on the chip itself?

If you feel a post has answered your question, please click "Accept as Solution".

Thank you very much for your help. It is realy urgent and I really dont know what to do. Otherwise I have to redraw the IOs
The exact Part Number is:
STM32G0B1KBU6N
As in the datasheet, there is a GPIOD and in the chip config you can clearly select the GPIOD

kuda1311_0-1764931018220.png

 

Hi,

these are the versions:

AScha3_0-1764942868761.png

+

You can use the GPIOD pins.

But now you set them as inputs , so "toggle" has no effect.

Set them as outputs, for toggle test. Then again as inputs...if you need inputs here.

:)

 

If you feel a post has answered your question, please click "Accept as Solution".

Hi, I have tesed all of configurations. I need them as Inputs and iBIT1 and EXTI, but they dont read in any state. There is a voltage measured on all fo the but nothing is read in. The value is always PIN_RESET. The Interrupt is not triggered also. 

The toggle was just for testing if there was any activity. :) 

Maybe your chip is not what you think it is. Maybe it's the other version. Can you show a clear in-focus picture?

Shouldn't be hard to get pins to be able to read. Does pin PC6 show up as logic high? Would indicate the incorrect chip.

If you feel a post has answered your question, please click "Accept as Solution".

Waht is the difference between KBU6 and KBU6N? 

kuda1311_0-1764956227786.jpeg

 

 

TDK
Super User

Looks like a STM32G0B1KBU6 to me, not a STM32G0B1KBU6N. That exactly explains your problems.

 

The different between the two is the pinout. The chip you have has no PD1-PD3 pins as shown in the first reply. @AScha.3 also shows the two pinouts in the reply above.

TDK_1-1764956869118.png

 

If you feel a post has answered your question, please click "Accept as Solution".

Thank you very much for the information.
So I have the GP Version? 
Does this Version Support Power Delivery with the TCPP01-M12 Chip? 

Is there a possibility to change the chip within the STM IDE without setting up a new project.

I checked the BOM, its says KBU6N, so somewhere in the process the manufacturerer missed the N....