cancel
Showing results for 
Search instead for 
Did you mean: 

Change the configuration of a GPIO pin in real time

RLein.1
Associate II

I'm working on a project using an STM32H753XI. The board is using a GT911 touch controller for the LCD. To configure the I2C address I have to control the interrupt pin during reset either high or low. This means I need to configure the MCU pin connected to the interrupt output of the GT911 as an output during a reset and then change it to an external interrupt input right after the reset.

I used CubeMX to configure the pin as an external interrupt and then copied this resulting code from the GPIO init code:

  /*Configure GPIO pin : PB8 */

  GPIO_InitStruct.Pin = GPIO_PIN_8;

  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

I then used CubeMX to configure the pin to an output.

My touch interface init code holds the reset pin low and holds the interrupt pin low to select the address. After this is complete, I then use the code copied above to change the MCU pin connect to the the GT911 interrupt pin to an external interrupt. (hope this makes sense)

Best I can tell, this is not working as the pin, after reset, looks like there is bus contention. Is the real-time code I'm using sufficient to change the configuration of the GPIO pin?

Thanks

7 REPLIES 7
JMala.3
Associate III

It may be easier to use "bare metal"programming rather then HAL.GPIO has a few simple registers to change he configuration after the initial setup (which can use HAL). To set PB8 to output, change the MODER register

   /* Set PB8 to output */
    Mode = GPIOA->MODER;
    Mode |= (1 << 8);
    Mode &= ~(1 << 9);
    GPIOA->MODER = Mode;

Then to change the output level

#define PB8_HIGH            (GPIOB->BSRR = GPIO_PIN_8)
#define PB8_LOW            (GPIOB->BRR = GPIO_PIN_8)

Hope this helps

S.Ma
Principal

I guess you mcu must control the display driver reset pin from a gpio, because the co fig pin level is probably sensed like stm32 boot pin, at rise edge of reset signal precisely.

Usually, pull up or pull down resistor on config pin males things hw proof. Or if reset and config is stm32 gpio, use internal pull up/down resistor to be safe from conflict.

And if you enable EXTI interrupt, make sure it auto disarm itself. Consider someone hacking the sw by injecting 40 Mhz clock to your IO interrupt. Ruggetize it.

You can also check, what does HAL_GPIO_Init() do with the GPIO registers. Cube is open source, you can and should debug it as you debug your own code.

> It may be easier to use "bare metal"programming rather then HAL.

Unless you want to stick to a few selected "typical" use of STM32, you better have never started with Cube/HAL at all.

JW

RLein.1
Associate II

Thanks for the responses. I need to clarify. I've gotten the touch interface to work just fine with the GPIO pin configured as an external interrupt configured from CubeMX. The problem I'm having is that it doesn't consistently work out of boot. Since the GT911 IC can be configured to use two different I2C addresses based on bootup, my theory is that it sometimes boots up with the opposite address than my code is using. If I call my touch init code and force a reset via the GPIO pin, it seldom works. That is why I'm trying to properly time the reset and interrupt pins so it will be reliable. But when I use the code I copied from the CubeMX generated init function to change the GPIO pin back to an external interrupt, it appears to not be working correctly. I was just hoping that someone might know if there needed to be additional initialization code.

S.Ma
Principal

Your HW seems to have a flaw at power up sequence. Sw patch option is to detect which slave address is responding after boot, and use it afterward.... or hw fix using a real pull up or down on the address selection line.

Good idea. I'll try it. If nothing else it may help determine the issue.

FThie.1
Associate II

When using chips that need specific inputs at startup, the best thing to do is to drive their reset pin by the MCU. This way, you can ensure that other pins are correct before driving the reset pin​.

Regarding the GT911, the datasheet recommends a 10k pull-up on /RSTB pin. Instead, I would use a 10k pull-down and drive it high with a GPIO after your INT pin configuration is done.​