Electronic – How to modify BRR and BRSS registers to stm32f4 from stm32f103

registerstm32f10xstm32f4

I'm trying to modify stm32f103 2×16 lcd library to stm32f4. There are BRR and BSRR register on stm32f103 but there aren't similar register in GPIO_TypeDef structure on stm32f4 so i don't know how to modify these codes.

LCD16X2_GPIO_D5->BSRR = LCD16X2_PIN_D5;

LCD16X2_GPIO_D4->BRR = LCD16X2_PIN_D4;

Best Answer

There are two different versions of STM32F4 headers released by ST, with some incompatibilities. The one that comes with the StdPeriph library defines 16 bit BSRRL and BSRRH, that is the one you have. The other one that comes with the STM32CubeF4 library has a single 32 bit BSRR definition, which corresponds to the reference manual.

Now check the definition in your headers

__IO uint16_t BSRRL;    /*!< GPIO port bit set/reset low register,  Address offset: 0x18      */
__IO uint16_t BSRRH;    /*!< GPIO port bit set/reset high register, Address offset: 0x1A      */

BSRRL corresponds to the low half, bits 0-15 of the BSRR register as described in the reference manual, which sets the corresponding output bit to 1 (high). BSRRH corresponds to the high half, bits 16-31 of the BSRR register, which sets the corresponding output bit to 0 (low).

You can use BSRRL instead of BSRR to turn a pin on, but keep in mind that the definition is only 16 bits, so you can't turn some bits on and some other pins off in a single operation using this definition, because the writes are truncated to 16 bits by the compiler.

BSRRL has the same function of BRR, the only difference is that the write is truncated to 16 bits by the compiler, nothing that you have to worry about unless you must count the cycles to get some timing right.