2020-03-14 09:23 AM
Hi everyone,
I am trying to modify the demonstartion application in the NUCLEO-G47RE board. There is this comment in the main header file:
#define B1_Pin GPIO_PIN_13
I went to the Description of STM32G4 HAL and low-layer dirvers found in:
In pages 354 and 355, you can see the GPIO_Pins which can be called with GPIO_PIN_x where is x is between 0 to 15. But I do not understand why the the first pin is Pin 0 when in the datasheet the pinout starts from Pin 1. Also why is the last pin to be configured Pin 15 when 52 pins are GPIOs. Any help would be really appreciated.
P.D. My MCU is using the LQFP64 package. That's the pinout I'm referring to.
2020-03-14 10:05 AM
Ok . I found out that Pin0 to Pin15 refers to pins PA0-PA15 from a Youtube video (I don't know why the HAL guide doesn't explain this). But what about the PB and the PC pins ?
2020-03-14 10:08 AM
GPIO pins are grouped in ports. See the RM0440 STM32G4 Series advanced Arm®-based 32-bit MCU reference manual. Ports are named GPIOA, GPIOB, ...
Pins within each port are numbered 0..15. Think of bits in a 16-bit word. These numbers are not related to the chip package.
If you use STm32CubeMX or STM32CubeIDE you can graphically choose and configure pins.
2020-03-14 10:20 AM
Thanks for your reply @KnarfB but I am trying to understand how to configure any pin not belonging to the PA group, let's say PC9, using the HAL commands. Becasue it makes no sense that there is HAL code for the PA group but not for the PB and PC groups.
2020-03-14 10:27 AM
I think the easiest way is to let STM32CubeIDE generate HAL code for you and studying the results.
// green LED on PB3
#define LEDgn_Pin GPIO_PIN_3
#define LEDgn_GPIO_Port GPIOB
// init
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LEDgn_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LEDgn_GPIO_Port, &GPIO_InitStruct);
// LED on
HAL_GPIO_WritePin( LEDgn_GPIO_Port, LEDgn_Pin, GPIO_PIN_SET);