1
\$\begingroup\$

I'm trying to modify stm32f103 2x16 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;

\$\endgroup\$
  • \$\begingroup\$ Actually there are. Check the programers manual. \$\endgroup\$ – Chris Stratton Mar 25 at 14:15
  • \$\begingroup\$ There are BSRRH (set/reset high register) and BSSRL (set/reset low register) for BSRR (set/reset register) register but which one i have to use and there are not register like BRR(reset register) in GPIO_TypeDef \$\endgroup\$ – 7navy4 Mar 25 at 14:39
  • 1
    \$\begingroup\$ Again, see the programmers manual. Once you understand what they do, you will understand which to use. \$\endgroup\$ – Chris Stratton Mar 25 at 14:40
  • \$\begingroup\$ @ChrisStratton unfortunately the situation is more complicated, with some headers incompatible with the description in the reference manual, low register used to set pins high... \$\endgroup\$ – berendi Mar 26 at 8:08
  • 1
    \$\begingroup\$ @ChrisStratton STM32 microcontroller documentation is split into 3 parts. The Programming Manual describes the ARM core, instruction set and core peripherals like NVIC, SCB. It does not mention GPIO at all. The Reference Manual describes the peripherals outside the ARM core, including GPIO registers. Finally, the Datasheet describes the hardware, pinouts, electrical characteristics, package dimensions. \$\endgroup\$ – berendi Mar 26 at 10:35
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.