手上有块STM32F0 Discovery的板子,刚开始学STM32,先上代码吧。
#include "stm32f0xx.h"
#include "main.h"
void SystemInit(void){}
long RCC_Tmp[10];
long GPIO_Tmp[10];
void SysInit(void)
{
/////////// 配置RCC /////////////////////////////
RCC_Tmp[0] = RCC->CR;
RCC->CR |= 1<<18; //外部高速时钟旁路
RCC_Tmp[1] = RCC->CR;
RCC_Tmp[2] = RCC->AHBENR;
RCC->AHBENR |= 1<<19; //使能PORTC的时钟
RCC_Tmp[3] = RCC->AHBENR;
RCC_Tmp[4] = RCC->AHBRSTR;
RCC->AHBRSTR |= 1<<19 ;//复位PORTC
RCC_Tmp[5] = RCC->AHBRSTR;
RCC_Tmp[2] = RCC->AHBENR;
RCC->AHBENR |= 1<<19; //使能PORTC的时钟
RCC_Tmp[3] = RCC->AHBENR;
RCC_Tmp[6] = RCC->CR2;
RCC->CR2 |= 1<<0; // HSI14震荡器关闭
RCC_Tmp[7] = RCC->CR2;
///////////////////////////////////////////////////
/////////////// 配置GPIOC //////////////////////////////
GPIO_Tmp[0] = GPIOC->MODER;
GPIOC->MODER |= 0x05 <<16; //配置PC8\PC9为通用输出
GPIO_Tmp[1] = GPIOC->MODER;
GPIO_Tmp[2] = GPIOC->ODR;
GPIOC->ODR |= 0x01<<8; //PC8\PC9输出1
GPIO_Tmp[3] = GPIOC->ODR;
GPIO_Tmp[4] = GPIOC->OSPEEDR;
GPIOC->OSPEEDR |= 0x3<<16; //PC8配置为高速口
GPIO_Tmp[5] = GPIOC->OSPEEDR;
//////////////////////////////////////////////////////////
}
int main(void)
{
SysInit();
while (1)
{
GPIOC->ODR |= 0x01 <<9;
GPIOC->ODR &=~0X01<<9;
}}
|