Hey was just wondering if someone could post an example of how to use GPIO_MODR, AHB1ENR and GPIO_BSSR for setting up an LED on an STM32 board in assembly, any help is greatly appreciated; thanks!
Compile your C code. See how it is done in the compiled code (port GPIOA, pin 10):
#include <stdint.h>
#define __IO volatile
typedef struct
{
__IO uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */
__IO uint32_t OTYPER; /*!< GPIO port output type register, Address offset: 0x04 */
__IO uint32_t OSPEEDR; /*!< GPIO port output speed register, Address offset: 0x08 */
__IO uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register, Address offset: 0x0C */
__IO uint32_t IDR; /*!< GPIO port input data register, Address offset: 0x10 */
__IO uint32_t ODR; /*!< GPIO port output data register, Address offset: 0x14 */
__IO uint32_t BSRR; /*!< GPIO port bit set/reset, Address offset: 0x18 */
__IO uint32_t LCKR; /*!< GPIO port configuration lock register, Address offset: 0x1C */
__IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x20-0x24 */
} GPIO_TypeDef;
#define PERIPH_BASE (0x40000000UL) /*!< Base address of : AHB/APB Peripherals */
#define D3_AHB1PERIPH_BASE (PERIPH_BASE + 0x18020000UL)
#define GPIOA_BASE (D3_AHB1PERIPH_BASE + 0x0000UL)
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
void foo()
{
GPIOA -> MODER &= ~(0b11 << (10 * 2));
GPIOA -> MODER |= 1 << (10 * 2);
while(1)
{
GPIOA -> BSRR = 1 << 10;
GPIOA -> BSRR = 1 << (10 + 16);
}
}
foo:
ldr r3, .L3
mov r1, #1024
ldr r2, [r3]
bic r2, r2, #3145728
str r2, [r3]
ldr r2, [r3]
orr r2, r2, #1048576
str r2, [r3]
mov r2, #67108864
.L2:
str r1, [r3, #24]
str r2, [r3, #24]
b .L2
.L3:
.word 1476526080
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.