Before using GPIO module you must do the following:
- Reset the GPIO registers:
- RCC module, register
AHBRSTR
, bitGPIOBRST
set to 1 - rst high - RCC module, register
AHBRSTR
, bitGPIOBRST
set to 0 - rst low
- RCC module, register
- Enable GPIO registers clock:
- RCC module, register
AHBENR
, bitGPIOBEN
set to 1 - Enable clock
- RCC module, register
After that you can start using GPIO registers
- GPIO module, register
GPIOB_MODER
, bitfield [15:14] set to 01 - General purpose output mode - GPIO module, register
GPIOB_OTYPER
, bit 7 set to 0 - Output push-pull - GPIO module, register
GPIOB_OSPEEDR
, bitfield [15:14] set to 00 - 400 kHz Very low speed - GPIO module, register
GPIOB_PUPDR
, bitfield [15:14] set to 00 - No pull-up, pull-down
Now you can use either GPIOB_BSRR
(set/reset) register or GPIOB_ODR (output) register:
- GPIO module, register
GPIOB_BSRR
, bit 7 set to 1 - Set GPIOB pin 7 (high) - GPIO module, register
GPIOB_BSRR
, bit 23 set to 1 - ReSet GPIOB pin 7 (low)