cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to clear GPIO bits

John Hite
Associate III
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

1 ACCEPTED SOLUTION

Accepted Solutions
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;

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

View solution in original post

7 REPLIES 7
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
Up vote any posts that you find helpful, it shows what's working..
stm322399
Senior
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.

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.

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
Up vote any posts that you find helpful, it shows what's working..
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;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 12, 2017 at 20:35

My stm32f4xx_gpio.c&h are both from lib version 1.8.0. They reference GPIO_TypeDef which is in file stm32f437.h and the version I have does not have a BSRRH or L field. This file does not appear in the std peripheral library.  Where are processor specific files like these located?

BTW, each time I have tried to reply today it sometimes took minutes for the form to load. I wonder if it is just our system or if it is an ST forum problem.

Thanks,

jh

Posted on January 12, 2017 at 20:42

Seems rapid enough on Chrome for me...

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