Skip to main content
Visitor II
January 8, 2024
Question

Configure GPIO through registers

  • January 8, 2024
  • 1 reply
  • 957 views

Hi i m learning to configure GPIO using registers, and come across the following code, can anyone kindly help to advise the following? what does the whole sentence do? what does the (volatile....) means, what does GPIO_OUT_DATA(0) does and what does  + SOC_GPIO_0_REGS means? 

 

#define GPIOSR_ADDR      (*(volatile unsigned int *)(GPIO_OUT_DATA(0) + SOC_GPIO_0_REGS))

    This topic has been closed for replies.

    1 reply

    ST Employee
    January 8, 2024

    Hello @StanCosgrove

    'volatile' tells the compiler that the memory location can change unexpectedly, so it prevents it from optimizing the code related to this memory access.

    GPIO_OUT_DATA(0): this macro likely returns the base address of the GPIO output data register port 0 

    SOC_GPIO_0_REGS: this likely adds the offset of the GPIO base address to get the final memory address 

    Overall, this code defines a mem address that can be used for read/write data from GPIO 

    Please refer to the GPIO functional description (paragraph 4) in AN4899