Untitled
unknown
plain_text
3 years ago
2.2 kB
8
Indexable
/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <stdint.h>
#include <stdio.h>
#define RCC 0x40023800
#define RCC_AHB1ENR (RCC + 0x30)
#define RCC_CFGR (RCC + 0x08)
#define RCC_CR (RCC + 0x00)
#define GPIOA 0x40020000
#define GPIOA_MODER (GPIOA + 0x00)
#define GPIOA_OSPEEDR (GPIOA + 0x08)
#define GPIOA_ODR (GPIOA + 0x14)
#define GPIOA_OTYPER (GPIOA + 0x04)
void delay() {
for (int i = 0; i < 800000; i++);
}
int main(void)
{
uint32_t* rccAhb1enr = (uint32_t*) (RCC_AHB1ENR);
uint32_t* rccCfgr = (uint32_t*) (RCC_CFGR);
uint32_t* rccCr = (uint32_t*) (RCC_CR);
uint32_t* gpioaModer = (uint32_t*) (GPIOA_MODER);
uint32_t* gpioaOspeedr = (uint32_t*) (GPIOA_OSPEEDR);
uint32_t* gpioaOdr = (uint32_t*) (GPIOA_ODR);
uint32_t* gpioaOtyper = (uint32_t*) (GPIOA_OTYPER);
// Enable HSE on
*rccCr |= (1 << 16);
// Wait until the HSE Clock stabled
while(!(*rccCr & (1 << 17)));
// Switch the system clock to HSE
*rccCfgr &= ~(0b11);
*rccCfgr |= (0b10);
// IO port A clock enable
*rccAhb1enr |= (1 << 0);
// Configure the corresponding PA5 as output
*gpioaModer &= ~(0b11 << 10);
*gpioaModer |= (0b01 << 10);
// Configure the type for the output pin
*gpioaOtyper &= ~(0b11 << 10);
*gpioaOtyper |= (0b01 << 10);
// Configure the speed for the output pin
*gpioaOspeedr &= ~(0b11 << 10);
*gpioaOspeedr |= (0b10 << 10);
while (1) {
// Turn on the portA5 and wait
*gpioaOdr |= (1 << 5);
delay();
// Turn off the portA5 and wait
*gpioaOdr &= ~(1 << 5);
delay();
}
}
Editor is loading...