Skip to main content
John Hite
Associate III
January 11, 2017
Solved

Unable to clear GPIO bits

  • January 11, 2017
  • 2 replies
  • 1526 views
Posted on January 12, 2017 at 00:31

On GPIOG, bits 0 and 1 control a pair of LEDs through external drivers. GPIO_ToggleBits() will set or clear the bits and GPIO_SetBits() will set the bits. However, GPIO_ResetBits() will not clear the bits, nor will GPIO_WriteBit(). GPIO_ReadOutputData verifies what I see on the LEDs.

Any thoughts?

Thanks,

jh

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on January 12, 2017 at 17:28

    *((uint32_t *)&GPIOG->BSRRL) = 0x00020001; // One could cast it to a 32-bit write

    *((uint32_t *)&GPIO

    G

    ->BSRRL) = 0x00010002;

    2 replies

    Tesla DeLorean
    Guru
    January 11, 2017
    Posted on January 12, 2017 at 00:45

    Very odd, you have anything else on the pins? LED wired with series resistor?

    Show complete code.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    stm322399
    Senior
    January 12, 2017
    Posted on January 12, 2017 at 09:49

    Could it be that there is something wrong about the use of GPIOx->BSRRH ?

    This register is used by GPIO_ResetBits and GPIO_WriteBit.

    Does GPIO_WriteBit successfully set a bit (you only spotted unability to reset) ?

    Could it be some weird compiler issue ?

    Ultimately, checking the generated code will make us sure of any compilation issue.

    John Hite
    John HiteAuthor
    Associate III
    January 12, 2017
    Posted on January 12, 2017 at 16:57

    The LEDs are driven by an inverter, the STM32 output type is push-pull and since there are cases where the LEDs will extinquish or illuminate (this design has been in use here for years) a hardware problem is unlikely.

    GPIO_WriteBit will set the bits.

    I think Laurent is on to something with a compiler issue or GPIO->BSRRH. The old code made reference to BSRRL and BSRRH in stm32f4xx_gpio.c but to get it to compile in IAR I had to strip off the H and Ls so that each became BSRR. I assumed this was due to ST code updates.

    Tesla DeLorean
    Guru
    January 12, 2017
    Posted on January 12, 2017 at 17:26

    You really shouldn't have to modify the ST code for it to compile, that's more indicative of broken Include paths and it not using contemporaneous source vs includes.

    The structure of BSRR has changed over library releases, and across STM32F families, some where it can only be written as a 32-bit register, and others where it can be split to two 16-bit writes, the former having the benefit of being atomic.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..