2025-01-28 09:48 AM
Hi, i just started with STM32G031J6 using STM32G0316-DISCO board.
Using CubeIDE i have configured my second LED LD1 on pin PA11
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 ?
Solved! Go to Solution.
2025-01-29 01:20 AM
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.
2025-01-28 10:40 AM
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:
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.
2025-01-28 10:58 AM
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.
2025-01-28 12:13 PM
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.
2025-01-28 01:18 PM
Check the definition of LD1_Pin in main.h.
2025-01-28 01:46 PM
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);
}
2025-01-28 01:50 PM
I belive that my problem is connected with multi-bonding, but i do not know how to configure.
2025-01-29 01:20 AM
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.
2025-01-29 01:36 AM
Hi, whole project (with LD2 and my new led) has been generated in STM32CubeMx,
LD2 is blinking correctly.
2025-01-29 01:38 AM - edited 2025-01-29 01:39 AM
@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?