Skip to main content
SLA
Associate
Dec 4, 2019 1:18 PM UTC
Solved

COMP2 don't work with STM32G071KB (QFP32 pin package) with port pin PB4

I tested 2 sample with no connection of COMP2 with port pin PB4.

If I set INPSEL to 01=PB6 or 11=PA3 the comperator works!

 

(INMSEL 0011= Vrefint)

 

The ST Support told me that a Nucleo-64 board (LQFP64 package) would work.

For the QFP32 they dont' have a setup?! No answer from the support since weeks.

 

Have anyone a STM32G071KB to check this double?

 

There is also a second bug with COMP2 with port pin PB6 (INMSEL 0011= Vrefint). Interacted with TIM1 Channel "Input Capture direct mode from Remap -> COMP1_OUT"!

The COMP2 works only independet if I use INPSEL = 11 (PA3).

 

 

Regards

Stefan

This topic has been closed for replies.
SLA
SLABest answer
Associate
Jan 9, 2020 9:06 AM UTC

  1. Problem solved- a 2 pinout exist, and are diferenciated with an additional "N" for PD product version or GP general purpose version

6 replies

waclawek.jan
Super User
Dec 4, 2019 10:00 PM UTC

I don't have the mcu in question, but how are GPIO registers set for these pins, exactly (as read out from the registers in debugger)?

> port pin PB6 (INMSEL 0011= Vrefint). Interacted with TIM1 Channel "Input Capture direct mode from Remap -> COMP1_OUT"!

How interacted exactly? Which channel? How exactly are the GPIO and TIM registers set?

JW

SLA
SLAAuthor
Associate
Dec 5, 2019 8:16 AM UTC

Hi Jan,

I made a small COMP2 test program with the STM32CubeIDE with a rise/falling edge Interrupt. The breakpoint is set in the ADC1_COMP_IRQHandler.

Case two is much more complicated to describe, I come back to the topic when the first problem is confirmed.

BR Stefan

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file : main.c
 * @brief : Main program body
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 * opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */
/* 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 */
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
COMP_HandleTypeDef hcomp2;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_COMP2_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();
 MX_COMP2_Init();
 /* USER CODE BEGIN 2 */
 
 HAL_COMP_Start(&hcomp2);
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* 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 CPU, AHB and APB busses clocks 
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV2;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /** Initializes the CPU, AHB and APB busses clocks 
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
 {
 Error_Handler();
 }
}
 
/**
 * @brief COMP2 Initialization Function
 * @param None
 * @retval None
 */
static void MX_COMP2_Init(void)
{
 
 /* USER CODE BEGIN COMP2_Init 0 */
 
 /* USER CODE END COMP2_Init 0 */
 
 /* USER CODE BEGIN COMP2_Init 1 */
 
 /* USER CODE END COMP2_Init 1 */
 hcomp2.Instance = COMP2;
 hcomp2.Init.InputPlus = COMP_INPUT_PLUS_IO2;
 hcomp2.Init.InputMinus = COMP_INPUT_MINUS_3_4VREFINT;
 hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
 hcomp2.Init.WindowOutput = COMP_WINDOWOUTPUT_EACH_COMP;
 hcomp2.Init.Hysteresis = COMP_HYSTERESIS_NONE;
 hcomp2.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
 hcomp2.Init.Mode = COMP_POWERMODE_HIGHSPEED;
 hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
 hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING;
 if (HAL_COMP_Init(&hcomp2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN COMP2_Init 2 */
 
 /* USER CODE END COMP2_Init 2 */
 
}
 
/**
 * @brief GPIO Initialization Function
 * @param None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 
}
 
/* USER CODE BEGIN 4 */
 
/* 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 */
 /* User can add his own implementation to report the HAL error return state */
 
 /* 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 can add his own implementation to report the file name and line number,
 tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

waclawek.jan
Super User
Dec 5, 2019 9:07 AM UTC

Thanks.

As I've said, I don't have the chip, and I also don't use Cube, so can't try.

Did you read out and check the content of relevant GPIO and COMP registers?

JW

SLA
SLAAuthor
Associate
Dec 5, 2019 9:28 AM UTC

​The Cube set all register correct. I verfied this in the debugger. Only a change of the register INPSEL to 01=PB6 or 11=PA3 in the debugger mode makes it run. I get then a breakpoint if I stimulat the associated pin.

SLA
SLAAuthorBest answer
Associate
Jan 9, 2020 9:06 AM UTC

  1. Problem solved- a 2 pinout exist, and are diferenciated with an additional "N" for PD product version or GP general purpose version
waclawek.jan
Super User
Jan 9, 2020 9:13 AM UTC

Thanks for coming back with the solution. Please select your post as Best so that thread is marked as resolved.

JW