I got an STM32L discovery board that contains an stm32l152rb microprocessor. I try to program that board in assembly without any library at all. So far I succeeded in writing linker scripts and a basic routine that copies the .data section into the RAM and zeroes out the bss section. But apart from that I am a little bit lost.
As a tiny experiment to understand how configuring GPIo works, I want to make a program for the board that lights the green LED connected to GPIO port B, pin 7. Reading the datasheet, I conclude that I need to do the following two things:
But at this place, I figuratively don't see the forest for the trees. I am not sure which of the multiple IO modes avaible I should choose and all these acronyms confuse me. I would really appreciate somebody giving me detailed information, instruction and possibly example assembly on how to do this.
Before using GPIO module you must do the following:
AHBRSTR
, bit GPIOBRST
set to 1 - rst highAHBRSTR
, bit GPIOBRST
set to 0 - rst lowAHBENR
, bit GPIOBEN
set to 1 - Enable clockAfter that you can start using GPIO registers
GPIOB_MODER
, bitfield [15:14] set to 01 -
General purpose output modeGPIOB_OTYPER
, bit 7 set to 0 - Output push-pullGPIOB_OSPEEDR
, bitfield [15:14] set to 00 - 400 kHz Very low speedGPIOB_PUPDR
, bitfield [15:14] set to 00 - No pull-up, pull-downNow you can use either GPIOB_BSRR
(set/reset) register or GPIOB_ODR (output) register:
GPIOB_BSRR
, bit 7 set to 1 - Set GPIOB pin 7
(high) GPIOB_BSRR
, bit 23 set to 1 - ReSet
GPIOB pin 7 (low)