cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 AzureRTOS GPIO some inputs do not work

IgorBecker
Associate

Hello everyone, thanks for your help.

I have a problem regarding the states of inputs that were set exactly the same way.

After powering all 10 inputs simultaneously, inputs IN4, IN5, IN6 and IN7 are not in SET, the others are in SET.

 

Relevant data:
Using STM32U535RCT6Q, Azure RTOS, IAR

/* Private defines -----------------------------------------------------------*/
#define IN1_Pin GPIO_PIN_0
#define IN1_GPIO_Port GPIOB
#define IN2_Pin GPIO_PIN_1
#define IN2_GPIO_Port GPIOB
#define IN3_Pin GPIO_PIN_2
#define IN3_GPIO_Port GPIOB
#define IN4_Pin GPIO_PIN_10
#define IN4_GPIO_Port GPIOB
#define IN5_Pin GPIO_PIN_13
#define IN5_GPIO_Port GPIOB
#define IN6_Pin GPIO_PIN_14
#define IN6_GPIO_Port GPIOB
#define IN7_Pin GPIO_PIN_15
#define IN7_GPIO_Port GPIOB
#define IN8_Pin GPIO_PIN_6
#define IN8_GPIO_Port GPIOC
#define IN9_Pin GPIO_PIN_7
#define IN9_GPIO_Port GPIOC
#define IN10_Pin GPIO_PIN_8
#define IN10_GPIO_Port GPIOC

Summary code for reading the pins used:

 

typedef struct
{
   GPIO_TypeDef* Port;
   uint16_t Pin;
}GPIO_Input;

#define NUM_INPUTS 10

GPIO_Input inputs[NUM_INPUTS] =
{
{IN1_GPIO_Port, IN1_Pin},
{IN2_GPIO_Port, IN2_Pin},
{IN3_GPIO_Port, IN3_Pin},
{IN4_GPIO_Port, IN4_Pin},
{IN5_GPIO_Port, IN5_Pin},
{IN6_GPIO_Port, IN6_Pin},
{IN7_GPIO_Port, IN7_Pin},
{IN8_GPIO_Port, IN8_Pin},
{IN9_GPIO_Port, IN9_Pin},
{IN10_GPIO_Port, IN10_Pin}
};

void inputsThread(ULONG initial_input)
{
GPIO_PinState dataInputs[NUM_INPUTS];
while (1)
{
for (uint8_t i = 0; i < sizeof(dataInputs); i++)
{
dataInputs[i] = HAL_GPIO_ReadPin(inputs[i].Port, inputs[i].Pin);
}
tx_thread_sleep(1);
}
}

It was verified that the problem pins have values ​​in the most significant byte in the stm32u5xx_hal_gpio.h file:

#define GPIO_PIN_0 ((uint16_t)0x0001)
#define GPIO_PIN_1 ((uint16_t)0x0002)
#define GPIO_PIN_2 ((uint16_t)0x0004)
#define GPIO_PIN_3 ((uint16_t)0x0008)
#define GPIO_PIN_4 ((uint16_t)0x0010)
#define GPIO_PIN_5 ((uint16_t)0x0020)
#define GPIO_PIN_6 ((uint16_t)0x0040)
#define GPIO_PIN_7 ((uint16_t)0x0080)
#define GPIO_PIN_8 ((uint16_t)0x0100)
#define GPIO_PIN_9 ((uint16_t)0x0200)
#define GPIO_PIN_10 ((uint16_t)0x0400)
#define GPIO_PIN_11 ((uint16_t)0x0800)
#define GPIO_PIN_12 ((uint16_t)0x1000)
#define GPIO_PIN_13 ((uint16_t)0x2000)
#define GPIO_PIN_14 ((uint16_t)0x4000)
#define GPIO_PIN_15 ((uint16_t)0x8000)
#define GPIO_PIN_ALL ((uint16_t)0xFFFF)

 

 

 

 

 

2 REPLIES 2

Please see the tips for posting:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

In particular, how to properly post source code.

Also, please provide full details of the board you are using

nouirakh
ST Employee

Hello @IgorBecker ,

It looks like you are experiencing an issue where some of your GPIO inputs are not being read correctly. This could be due to several reasons, including hardware configuration, software initialization, or timing issues:
Ensure that the hardware connections for IN4, IN5, IN6, and IN7 are correct and that there are no loose connections or shorts. Verify that the pins are properly powered and grounded. 
Make sure that the GPIO pins are correctly initialized as input pins. Here’s an example of how you might initialize the GPIO pins in your main function or a dedicated initialization function:
Code example:

void GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    // Enable GPIO clocks
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();

    // Configure GPIO pins as input
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;

    // Initialize GPIO pins for Port B
    GPIO_InitStruct.Pin = IN1_Pin | IN2_Pin | IN3_Pin | IN4_Pin | IN5_Pin | IN6_Pin | IN7_Pin;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    // Initialize GPIO pins for Port C
    GPIO_InitStruct.Pin = IN8_Pin | IN9_Pin | IN10_Pin;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}

Ensure that the pin configuration in your stm32u5xx_hal_gpio.h file matches the actual pinout of your microcontroller. Double-check the datasheet and reference manual for the correct pin assignments.
Finally, Verify that there are no conflicting configurations for the GPIO pins. Ensure that the pins are not being used for other purposes (alternate functions) that might interfere with their operation as inputs.