Вопрос

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:

  1. Configure GPIO port B, pin 7 as an output pin
  2. Set said pin to high

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:

  1. Reset the GPIO registers:
    • RCC module, register AHBRSTR, bit GPIOBRST set to 1 - rst high
    • RCC module, register AHBRSTR, bit GPIOBRST set to 0 - rst low
  2. Enable GPIO registers clock:
    • RCC module, register AHBENR, bit GPIOBEN set to 1 - Enable clock

After that you can start using GPIO registers

  1. GPIO module, register GPIOB_MODER, bitfield [15:14] set to 01 - General purpose output mode
  2. GPIO module, register GPIOB_OTYPER, bit 7 set to 0 - Output push-pull
  3. GPIO module, register GPIOB_OSPEEDR, bitfield [15:14] set to 00 - 400 kHz Very low speed
  4. 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)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top