Skip to main content
Visitor II
July 19, 2019
Question

How can I use GPIOx_BSRR register?

  • July 19, 2019
  • 9 replies
  • 17407 views

Hi,

I use stm32h743zi nucleo board and I try to GPIOx_BSRR register .This register has two 16 bit registers "BSRRL" and "BSRRH".As I understand BSRRL is used to set bit and then BSRRH is used to reset bit.

GPIOB->BSRRL =(1<<0); to set the zero pin ,but there is an error: #136: struct "<unnamed>" has no field "BSRRL"

    This topic has been closed for replies.

    9 replies

    Graduate II
    July 19, 2019

    GPIOB->BSRR =(1<<0); // PB0 High

    GPIOB->BSRR =(1<<16); // PB0 Low

    Graduate II
    January 31, 2024

    What has priority?
    What if I set in one step GPIOB->BSRR =(1<<0) | (1<<16); ?

    Thank you.

    Visitor II
    July 19, 2019

    Hey, I think @Community member​ misunderstood you, I guess BSRRL is used to control the pins 0,1,2,3,4,5,6,7 and BSRRH is used to control pins 8,9,10,11,12,13,14,15. So these two registers works same but targets different I/Os. On the other hand, his answer represents how to use a 32 bit BSRR register.

    BSRR registers are operates in such way which is called as atomic operation(or something like that). This simply means that you just send a signal,i.e "1" ,to relevant bit, it understands you and responses then sets itself to "0" again.

    So you will use for example to control PB3;

    GPIOB.BSRRL |= 1<<3; // TO HIGH

    GPIOB.BSRRL |= (1<<3+8) ; //TO LOW

    You send a "1"(signal) to 3rd bit to say the MCU, "hey let us make pin 3 HIGH" it does it and then resets the 3rd bit. First half of bits are used to SET and the other half of the bits are used to RESET in BSRR registers(more correctly BSR registers).

    Visitor II
    July 19, 2019

    I now checked the reference manual for the stm32h743zi, but there is not any BSRRL and BSRRH registers, there is only one 32bit BSRR register and then all my answer based on there are 2 registers information is wrong. The answer above ( Clive's answer ) then represents how to correctly use a 32-bit BSRR. I will not delete my answer though, in case it may help.

    Graduate II
    July 19, 2019

    Different STM32 models describe this differently, some have the high/low registers in the structure, some just one 32-bit BSRR.

    In all cases, as I recall, the chip can take a 32-bit write, so one atomic write which can set/reset all pins into desired state.

    Visitor II
    July 19, 2019

    So if there were 2 registers named as BSRRL and BSRRH ( hypotethically and let them used as I wrote above) , then also in the defines part, are they defining a new BSRR even it wasn't in reference manual? But this time a 16 bit shift should not work because L register accesses only the pins up to 7. Or am i all wrong about this L and H registers. But I must have seen a kind of them in somewhere.

    BilgeAuthor
    Visitor II
    July 19, 2019

    @Community member​ GPIOB->BSRR =(1<<0); it worked that way, but The use of bsrr register looks like in the picture.There is not error in the program ,but it looks that way.0690X000009YvCXQA0.jpg0690X000009YvBtQAK.jpg

    BilgeAuthor
    Visitor II
    July 19, 2019

    @Imen DAHMEN​ first image is generated codes in the stm32cubemx 5.2.1 version ,other older version 0690X000009YvMNQA0.jpg0690X000009YvMrQAK.jpg

    Technical Moderator
    July 19, 2019

    Hello @Bilge​ ,

    Which Cube firmware package are you using ?

    In fact, in the last firmware package CubeH7 v1.4, we have replaced BSRRL and BSRRH registers (In device header file (ex. stm32h743xx.h) and in GPIO type def) by one 32 bit register BSRR as defined in Reference manual.

    Best Regards,

    Imen

    BilgeAuthor
    Visitor II
    July 19, 2019

    Thank you for your reply @Imen DAHMEN​ STM32CubeH7 Firmware Package V1.4.0 / 05-April-2019

    Graduate
    January 31, 2024

    This is clearly described in the Reference Manual, so please Read The Fine Docs.

    Graduate II
    January 31, 2024

    no it is not. I found only this but probably it is not answer for what I am asking for:

    JR2963_0-1706704958828.png

     

    Graduate
    January 31, 2024

    Well, that's exactly the answer you were looking for. Just read the last sentence.

    It would be clearer if "in" was replaced by "via". (Just a hint to ST docs editors. ;) )

    Graduate II
    January 31, 2024

    OK if there would be via, then it is answer for me