Showing results for 
Search instead for 
Did you mean: 

how to read particular port memory

Associate III

hi I am working on keyboard project where i want to read B port"

KeyInputMemory[column_count] = (uint16_t) HAL_GPIO_ReadPin(rowport, GPIO_PIN_All);

iam taking rows as input... whenever key is pressed it should be read that pin.... how can i see whether particular address is stored or not in software

Senior III

Look at the source code of Hal_GPIO_ReadPin, and you will see why your approach is not correct:


  * @brief  Reads the specified input port pin.
  *   GPIOx where x can be (A..K) to select the GPIO peripheral for STM32F429X device or
  *                      x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices.
  *   GPIO_Pin specifies the port bit to read.
  *         This parameter can be GPIO_PIN_x where x can be (0..15).
  * @retval The input port pin value.
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  GPIO_PinState bitstatus;

  /* Check the parameters */

  if((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
    bitstatus = GPIO_PIN_SET;
    bitstatus = GPIO_PIN_RESET;
  return bitstatus;


You can also see that reading the IDR register directly as in the source code presented at line 16 can be an answer to your question.

This approach is done in the LL (alternative to hal) functions to read ports:

  * @brief  Return full input data register value for a dedicated port.
  * @rmtoll IDR          IDy           LL_GPIO_ReadInputPort
  * @PAram  GPIOx GPIO Port
  * @retval Input data register value of port
__STATIC_INLINE uint32_t LL_GPIO_ReadInputPort(GPIO_TypeDef *GPIOx)
  return (uint32_t)(READ_REG(GPIOx->IDR));

But therefore you need to enable in cubemx the LL functions for GPIO.



../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f730xx.h:985:31: error: expected declaration specifiers or '...' before '(' token

985 | #define AHB1PERIPH_BASE (PERIPH_BASE + 0x00020000UL)

| ^

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f730xx.h:1044:32: note: in expansion of macro 'AHB1PERIPH_BASE'

1044 | #define GPIOB_BASE (AHB1PERIPH_BASE + 0x0400UL)

| ^~~~~~~~~~~~~~~

../Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f730xx.h:1169:47: note: in expansion of macro 'GPIOB_BASE'

1169 | #define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)

| ^~~~~~~~~~

../Core/Src/main.c:363:50: note: in expansion of macro 'GPIOB'

363 | uint16_t HAL_GPIO_ReadPort(GPIO_TypeDef* GPIOB);

| ^~~~~ i have used above code as referrence but iam getting this error

Associate III


  KeyInputMemory[column_count] = (uint16_t)(GPIOB->IDR);

       uint16_t mask = 0x0FFF;

       KeyInputMemory[column_count] &= mask;


    if (KeyInputMemory[column_count] == StoredKeyInput[column_count]) {  //



        if (KeyInputCounter[column_count] > 5) {


            StoredKeyInput[column_count] = KeyInputMemory[column_count];


            // Reset the counter

          //KeyInputCounter[column_count] = 0;



    } else {

        // Store the current key input into the column stored key input

        StoredKeyInput[column_count] = KeyInputMemory[column_count];


        // Clear the key input count

        KeyInputCounter[column_count] = 0;




    } I have physical keyboard i have to read b port but not detecting is my logic is true or false....... whenever key is pressed not reading the values