cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0316-DISCO GPIO Output configuration.

Mario3
Associate

Hi, i just started with STM32G031J6 using STM32G0316-DISCO board. 

Using CubeIDE i have configured my second LED LD1 on pin PA11

Mario3_0-1738085179315.png

After generated the code by IDE, I added sections for flashing these LEDs. LD2 works perfectly, but there is  a problem with LD1 on the PA11 pin (I tried to change it to another possible one on this pin, but it's still the same) looks liek GPIO is not reconfigured to GPIO_Output.

Here is the generated code: 

 

#include "main.h"

void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  while (1)
  {
	  HAL_GPIO_TogglePin(GPIOA, LD2_Pin);
	  HAL_GPIO_TogglePin(GPIOA, LD1_Pin);
	  HAL_Delay(1500);
  }
}

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_NONE;
  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_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();
  }
}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  __HAL_RCC_GPIOA_CLK_ENABLE();

  HAL_GPIO_WritePin(GPIOA, LD2_Pin|LD1_Pin, GPIO_PIN_RESET);

  GPIO_InitStruct.Pin = LD2_Pin|LD1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

 

Do I miss something to configure ? 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

At this level, I suggest you to use STM32CubeMx configurator tool.

Attached a project where PA11 is toggling well along with with LD2 on STM32G0316-DISCO.

If you don't see PA11 toggling I'm pretty sure it's a hardware issue.

Hope that helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

View solution in original post

10 REPLIES 10
STTwo-32
ST Employee

Hello @Mario3 @and welcome to the ST Community.

In fact, the STM32G0316-DISCO has only one user LED that is LD2. For the LD1, it is related (connected) to the  STM32F103 of the embrases ST-LINK and you can’t control it as a user LED:

STTwo32_0-1738089533526.png

Best Regards. 
STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Mario3
Associate

Hi, thx for the answer. I know that i can't control LD1 (i make mistake named my LED the same as this one). My problem is that i connected new LED to STM32G031J6-PIN5 and trying this pin configured as digital output to control my new LED, but for some reason it is not working.

Could you try to set PA8 to digital output and use it for your LED.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

gbm
Lead III

Check the definition of LD1_Pin in main.h.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Mario3
Associate

changet pin 5 to PA8, still the same, definition looks ok. 

#include "main.h"

#define MY_LED_Pin GPIO_PIN_8
#define MY_LED_GPIO_Port GPIOA
#define LD2_Pin GPIO_PIN_12
#define LD2_GPIO_Port GPIOA

void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  while (1)
  {
	  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_12);
	  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8);
	  HAL_Delay(1500);
  }
}

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  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_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  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();
  }
}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  __HAL_RCC_GPIOA_CLK_ENABLE();

  HAL_GPIO_WritePin(GPIOA, MY_LED_Pin|LD2_Pin, GPIO_PIN_RESET);

  GPIO_InitStruct.Pin = MY_LED_Pin|LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

 

Mario3
Associate

I belive that my problem is connected with multi-bonding, but i do not know how to configure. 

Mario3_0-1738101001553.png

 

Hello,

At this level, I suggest you to use STM32CubeMx configurator tool.

Attached a project where PA11 is toggling well along with with LD2 on STM32G0316-DISCO.

If you don't see PA11 toggling I'm pretty sure it's a hardware issue.

Hope that helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.
Mario3
Associate

Hi, whole project (with LD2 and my new led)  has been generated in STM32CubeMx,

LD2 is blinking correctly.


@Mario3 wrote:

Hi, whole project (with LD2 and my new led)  has been generated in STM32CubeMx,


I'm not seeing a sign of that in the code you shared: no User Code Begin/End.

And what about PA11 with the project I shared with you?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.