2025-12-04 3:32 PM
Dear community,
first of all: I'm new to using STM32 controllers.
I did some quite complex project using Arduino (consisting of Arduino Nano Every (ATMega4809) and a custom board using ATMega328P), but for my next project I consider switching to STM32 due to higher need for SRAM. So, I begin with simple blink-application to learn.
Board used: Nucleo-L432KC
IDE: STM32CubeIDE, STM32CubeMX
OS: Win 11
LED that shall blink: LD3 (the green one)
So far, code is working, but with unexpected GPIO_PIN_3.
I did some search here in the forum related to my question, but no sucess. Consulting documentation was also not helping at the end:
With reference to User Manual UM1956 Rev 6, Table 16 on page 30, and schematic on page 33 (of Rev 5!, Rev 6 does not show the schematic), the green LED LD3 is connected to pin PB3 of STM32L432KC. In Table 16 of UM1956 the pin number is given for PB3 as 15.
So, I would have expected to toggle the pin by using:
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_15);but instead I have to use
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);which matches the define given in main.h to
#define LD3_Pin GPIO_PIN_3that also matches corresponding lines in MX_GPIO_Init below (created by STM32CubeMX)
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PA8 */
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : LD3_Pin */
GPIO_InitStruct.Pin = LD3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}Why is that? The Manual UM1956 is not giving any hint that LD3 is connected to GPIO_PIN_3 but to Pin 15.
Unfortunately I was not sucessful in finding a table on how the various Pins PA0, PA1, ... etc are mapped on GPIO_PIN_x with x = 0..15. So my question is: where can I find such a table? Am I reading the manual UM1956 in the wrong way?
Your support is appreciated.
Regards
Sebastian