cancel
Showing results for 
Search instead for 
Did you mean: 

Noob question on ports

arm_dude
Associate II
Posted on October 04, 2015 at 15:19

Hi all,

Just plunging in again to learn STM32/ARM coding, and have a GPIO issue (on a STM32L100C discovery board): Why does this work...

GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0) ;
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9) ;
GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8|GPIO_OSPEEDER_OSPEEDR9);
GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8|GPIO_PUPDR_PUPDR9);
while
(1)
{
GPIOC->ODR = 0x0300;
delay(10000);
GPIOC->ODR = 0x0300;
delay(10000);
}

But not this?...

GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0) ;
GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9) ;
GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8|GPIO_OSPEEDER_OSPEEDR9);
GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8|GPIO_PUPDR_PUPDR9);
while
(1)
{
GPIOC->BSRR = 0x0300;
delay(10000);
// GPIOC->BSRR = 0x0300; // This also did not work
GPIOC->BRR = 0x0300;
delay(10000);
}

#keyhole-debugging
6 REPLIES 6
Posted on October 04, 2015 at 15:30

What does ''works'' mean, because the result should be different between the two. The first example would seem to write the same value twice, so it's not as if the LEDs / GPIO state would change.

Check the GPIO configuration, and make sure all the bits you want set/clear actually get into the final state you want/expect, especially where there are multiple bits involved, and the initial state is unknown/unexpected. Use a debugger, review the registers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arm_dude
Associate II
Posted on October 04, 2015 at 18:01

''Works'' means the LEDs (on PC8 and PC9) blink.  My understanding is that BSRR will set specific bits, and BRR should clear them.  I also found that I an clear the bits by using BSRR, but shifting the specific bits 16 over to the left, so ''GPIOC->BSRR = 0x03000000;'' will turn the LEDs off.  But if I use BRR I should not need to shift the bits over 16 to the left.  So why doesn't BRR work to turn the LEDs off as I have it?

mikael239955_stm1_st
Associate III
Posted on October 04, 2015 at 20:51

..

Posted on October 05, 2015 at 17:19

Seem to be missing a lot of context here, the SPL uses BSRRL, and BSRRH to differentiate the two halves of the 32-bit register, so you're clearly not using that.

Maybe you should be looking more carefully at the tools/library you are using, and how the structure for the GPIO is defined.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Niket Naidu
Associate
Posted on March 31, 2018 at 19:52

//This works

GPIOC ->BSRRL |= GPIO_BSRR_BS_8;

//BRR Register will NOT work (in the STM32L100 this register does not work)

GPIOC ->BRR |= (1 << 8);

//You have to write to the High register to reset the pin (Since you cannot use BRR Reg)

GPIOC ->BSRRH |= (1<<8);

Note: BSRR Register is used for Atomic write while ODR register is not atomic (i.e between interrupts or multi-tasking context switching can happen midway)

Posted on April 01, 2018 at 01:09

You're posting to a 2+ year old thread! Please don't do that unless there is some compelling reason.

You can write the 32-bit word if you use the appropriate cast.

>>BRR Register will NOT work (in the STM32L100 this register does not work)

Is there an errata for this?

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