1、前面介绍了系统时钟配置工具和GPIO配置工具,在这里就可以用到了,笔者看来GPIO工具不利于初学者对STM32的认识,不建议初学者使用,笔者这里也没用用的,只是用的了时钟配置工具。下面简单介绍,系统时钟工具怎么用,其实打开就可以发现,其实excel宏加载文件,很多人不知道如何配置这个宏才能正常使用该工具,即便配置指导就在文件中,笔者初期也是搞了很久才配置好宏,后面发现有个更简单的方法,微软 office 2010.

1) 打开excel,点击另存为。

2)选择保存路径,保存类型(关键)选择为:excel 加载宏,点击"保存"。

3)接着点击原文件中的保存按钮,会弹出 ”另存为“,这里只要更改文件名(避免与原文件冲突),其他不要更改,点击"保存"。

4)打开第二次保存的文件,就会发现可以配置了。其中,RUN是配置生效,Generate是生成C文件。

2、系统时钟配置为PLL,48M,具体如下;

/**
******************************************************************************
* @file    system_stm32f0xx.c
* @author  MCD Application Team
* @version V1.0.1
* @date    14-July-2014
* @brief   CMSIS Cortex-M0 Device Peripheral Access Layer System Source File.
*          This file contains the system clock configuration for STM32F0xx devices,
*          and is generated by the clock configuration tool
*          STM32f0xx_Clock_Configuration_V1.0.1.xls
*
* 1.  This file provides two functions and one global variable to be called from
*     user application:
*      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
*                      and Divider factors, AHB/APBx prescalers and Flash settings),
*                      depending on the configuration made in the clock xls tool.
*                      This function is called at startup just after reset and
*                      before branch to main program. This call is made inside
*                      the "startup_stm32f0xx.s" file.
*
*      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
*                                  by the user application to setup the SysTick
*                                  timer or configure other parameters.
*
*      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
*                                 be called whenever the core clock is changed
*                                 during program execution.
*
* 2. After each device reset the HSI (8 MHz Range) is used as system clock source.
*    Then SystemInit() function is called, in "startup_stm32f0xx.s" file, to
*    configure the system clock before to branch to main program.
*
* 3. If the system clock source selected by user fails to startup, the SystemInit()
*    function will do nothing and HSI still used as system clock source. User can
*    add some code to deal with this issue inside the SetSysClock() function.
*
* 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
*    in "stm32f0xx.h" file. When HSE is used as system clock source, directly or
*    through PLL, and you are using different crystal you have to adapt the HSE
*    value to your own configuration.
*
* 5. This file configures the system clock as follows:
*=============================================================================
*=============================================================================
*        System Clock source                    | PLL(HSI)
*-----------------------------------------------------------------------------
*        SYSCLK(Hz)                             | 48000000
*-----------------------------------------------------------------------------
*        HCLK(Hz)                               | 48000000
*-----------------------------------------------------------------------------
*        AHB Prescaler                          | 1
*-----------------------------------------------------------------------------
*        APB Prescaler                          | 1
*-----------------------------------------------------------------------------
*        HSE Frequency(Hz)                      | NA
*----------------------------------------------------------------------------
*        PLLMUL                                 | 12
*-----------------------------------------------------------------------------
*        PREDIV                                 | 2
*-----------------------------------------------------------------------------
*        Flash Latency(WS)                      | 1
*-----------------------------------------------------------------------------
*        Prefetch Buffer                        | ON
*-----------------------------------------------------------------------------
******************************************************************************
* @attention
*
* 
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*        http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f0xx_system
* @{
*/
/** @addtogroup STM32F0xx_System_Private_Includes
* @{
*/
#include "stm32f0xx.h"
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_Defines
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_Variables
* @{
*/
uint32_t SystemCoreClock    = 48000000;
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_FunctionPrototypes
* @{
*/
static void SetSysClock(void);
/**
* @}
*/
/** @addtogroup STM32F0xx_System_Private_Functions
* @{
*/
/**
* @brief  Setup the microcontroller system.
*         Initialize the Embedded Flash Interface, the PLL and update the
*         SystemCoreClock variable.
* @param  None
* @retval None
*/
void SystemInit (void)
{
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
/* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */
RCC->CFGR &= (uint32_t)0xF8FFB80C;
/* Reset HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xFEF6FFFF;
/* Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
RCC->CFGR &= (uint32_t)0xFFC0FFFF;
/* Reset PREDIV1[3:0] bits */
RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
/* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */
RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
/* Reset HSI14 bit */
RCC->CR2 &= (uint32_t)0xFFFFFFFE;
/* Disable all interrupts */
RCC->CIR = 0x00000000;
/* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
SetSysClock();
}
/**
* @brief  Update SystemCoreClock according to Clock Register Values
*         The SystemCoreClock variable contains the core clock (HCLK), it can
*         be used by the user application to setup the SysTick timer or configure
*         other parameters.
*
* @note   Each time the core clock (HCLK) changes, this function must be called
*         to update SystemCoreClock variable value. Otherwise, any configuration
*         based on this variable will be incorrect.
*
* @note   - The system frequency computed by this function is not the real
*           frequency in the chip. It is calculated based on the predefined
*           constant and the selected clock source:
*
*           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
*
*           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
*
*           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
*             or HSI_VALUE(*) multiplied/divided by the PLL factors.
*
*         (*) HSI_VALUE is a constant defined in stm32f0xx.h file (default value
*             8 MHz) but the real value may vary depending on the variations
*             in voltage and temperature.
*
*         (**) HSE_VALUE is a constant defined in stm32f0xx.h file (default value
*              8 MHz), user has to ensure that HSE_VALUE is same as the real
*              frequency of the crystal used. Otherwise, this function may
*              have wrong result.
*
*         - The result of this function could be not correct when using fractional
*           value for HSE crystal.
* @param  None
* @retval None
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0, pllmull = 0, pllsource = 0, prediv1factor = 0;
/* Get SYSCLK source -------------------------------------------------------*/
tmp = RCC->CFGR & RCC_CFGR_SWS;
switch (tmp)
{
case 0x00:  /* HSI used as system clock */
SystemCoreClock = HSI_VALUE;
break;
case 0x04:  /* HSE used as system clock */
SystemCoreClock = HSE_VALUE;
break;
case 0x08:  /* PLL used as system clock */
/* Get PLL clock source and multiplication factor ----------------------*/
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
pllmull = ( pllmull >> 18) + 2;
if (pllsource == 0x00)
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
}
else
{
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
}
break;
default: /* HSI used as system clock */
SystemCoreClock = HSI_VALUE;
break;
}
/* Compute HCLK clock frequency ----------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
/**
* @brief  Configures the System clock frequency, AHB/APBx prescalers and Flash
*         settings.
* @note   This function should be called only once the RCC clock configuration
*         is reset to the default reset state (done in SystemInit() function).
* @param  None
* @retval None
*/
static void SetSysClock(void)
{
/******************************************************************************/
/*            PLL (clocked by HSI) used as System clock source                */
/******************************************************************************/
/* At this stage the HSI is already enabled and used as System clock source */
/* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
/* Enable Prefetch Buffer and set Flash Latency */
FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY;
/* HCLK = SYSCLK / 1 */
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
/* PCLK = HCLK / 1 */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;
/* PLL configuration */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI_Div2 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL12);
/* Enable PLL */
RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */
while((RCC->CR & RCC_CR_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
{
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

© COPYRIGHT 2012 STMicroelectronics


3、配置GPIO --- LED3:PC9; LED4:PC8 ,根据原理图可知;IO应配置成输出,如题代码如下

   

#include "Gpio.h"
/*
* LED3:PC9 ;  LED4:PC8
*
*/
void LED_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}

4.GPIO配置好了,就只需在MAIN函数中调用一下,然后,在循环中,适当延长一段时间,并改变一下对外输出的电平LED就可以闪烁了,具体代码如下,这里笔者用的的是systick定时器进行延时,下次再对这个定时器做详细介绍。

/**
******************************************************************************
* @file    main.c
* @author  MCD Application Team
* @version V1.0.0
* @date    02-October-2013
* @brief   Main program body
******************************************************************************
* @attention
*
* 
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*        http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "Gpio.h"
/** @addtogroup STM32F0308-Discovery_Demo
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
uint8_t BlinkSpeed = 0;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief  Main program.
* @param  None
* @retval None
*/
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
LED_init();
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
/* Initiate Blink Speed variable */
BlinkSpeed = 1;
while(1){
if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_8) == Bit_SET)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
}
else{
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
}
if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9) == Bit_SET)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
}
else{
GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
}
Delay(300);
}
}
/**
* @brief  Inserts a delay time.
* @param  nTime: specifies the delay time length, in 1 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief  Decrements the TimingDelay variable.
* @param  None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef  USE_FULL_ASSERT
/**
* @brief  Reports the name of the source file and the source line number
*   where the assert_param error has occurred.
* @param  file: pointer to the source file name
* @param  line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

© COPYRIGHT 2013 STMicroelectronics


5、至此,LED可以闪烁了,对GPIO可以用初步认识了。



玩转STM32F0 Value Line Discovery 之 点亮LED相关推荐

  1. 玩转STM32F0 Value Line Discovery 之 GPIO配置工具

    前面简单的介绍了时钟配置工具的使用.按照惯例,下面就是点亮LED,介于官方已经有了LED的程序,下面先不急着介绍怎么点亮LED,而是介绍ST今年推出的一款初始化代码生成工具--- STM32CubeM ...

  2. 玩转STM32F0 Value Line Discovery 之 认识板载资源

    笔者无意中得到一块STM32F0 Value line Discovery ,之前虽然用过ST的芯片,但还真没用过它的探索板,开始拿到板子还再头痛如果用ULINK2如何通过SWD模式调试板子,后面发现 ...

  3. 玩转STM32F0 Value Line Discovery 之 时钟配置工具

    1.通过STM32F0的数据手册,我们可以知道,系统最高频率为 48M.时钟树如图,由图可知系统时钟可以由HSE/HSI/PLL其中之一提供.时钟作为MCU的心跳,提供者其运行的能量,因此时钟的配置很 ...

  4. 玩转STM32F0 Value Line Discovery 之 深入理解 SYSTICK定时器

    在上面的点亮LED中用到了 Systick .GPIO,RCC,这次先介绍 SYSTICK定时器. 1.SYSTICK 定时器,又称节拍定时器.顾名思义,就是为操作系统提供一个固定的时钟参考.话不多说 ...

  5. C51玩8x8LED点阵:PointGame —— 收藏数爆炸的LED小游戏

    ** 前言 ** 我借同学的光驱把光盘中的文件拷出来后,开始尝试玩一玩单片机. 目前做的比较难的是8X8Led点阵的使用,元件感觉有点多啊. 我用的是普中科技HC6800-ES V2.0的开发板,很多 ...

  6. android+app+wifi+控制+协议,玩转OneNET物联网平台之MQTT服务④ —— 远程控制LED(数量无限制)+ Android App控制...

    授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.但愿你们分享给你周边须要的朋友或者同窗,说不定大神成长之路有博哥的奠定石...android 若是以为有用,麻烦点赞收藏,您的 ...

  7. 微信如何赚钱?Kakao和Line营收模式或应借鉴

    利用Line账号接入游戏应用LINE POP 腾讯科技 王鑫 11月20日报道 在想着怎么挣钱这件事上,日韩公司的执行力表现惊人.就在今年9月,韩国通讯应用KaKaoTalk借7月上线的游戏平台盈利. ...

  8. 画个板子玩一玩STM32F030F4P6,也许是最便宜的32bit MCU

    前言,什么是STM32F030F4P6 STM32目前最便宜的芯片之一应该就是这一块,STM32F030F4P6,这一个芯片没有USB,但是其他都有,引脚少,价格低廉,如果找不到原厂,可以买替代的国产 ...

  9. LINE FRIENDS与腾讯QQ推出首款联名产品,全球限量808体

    上海2021年8月9日 /美通社/ -- 在旗下IP BROWN & FRIENDS 诞生十周年之际,国际化创意工作室LINE FRIENDS携手腾讯QQ推出QQ X LINE FRIENDS ...

最新文章

  1. oraclf 复杂查询练习_刷完这些烧脑的SQL练习题,复杂查询才能熟能生巧
  2. java软件测试方法有哪些方法有哪些_如何才算掌握Java
  3. href可以请求后台么_href怎么进行传参
  4. matlab食饵,食饵捕食者模型进一步研究(matlab)
  5. Maven常见问题和陷阱
  6. java实现未读消息提醒_Android自定义View之未读消息提示
  7. 乐观锁的两种实现方式
  8. 钉钉总裁不穷首谈产品观:To B产品用户不只是CEO
  9. Spring IO platform
  10. C/C++混淆点-左移右移操作符
  11. 微信终于可以隐身了,快看看!
  12. 变量 重复声明_JS:定义变量的var、let有何操作?(360°无死角)
  13. 防病毒服务器维护记录表,机房巡检记录表.doc
  14. word-目录突然无法更新解决方法
  15. Arduino作为编程器读写BIOS、bootloader、uboot或者breed
  16. 完美国际服务器管理修改经验倍数,魔兽地图编辑问题--修改经验倍数
  17. ELK生态系统——修改es中index的mapping平滑过渡数据
  18. Linux环境Hadoop的下载安装
  19. 人话解读LGPLv3
  20. html4.0.1兼容ie7,CSS 完美兼容IE6/IE7/FF的通用hack方法

热门文章

  1. Ajax登录注册-----数据请求 交互
  2. Python获取用电情况数据-AHPU校园网
  3. adpcm的压缩和解压缩实现
  4. java final成员变量吗_阳光沙滩博客-为什么Java匿名内部内使用局部变量需要加final?而访问成员变量却不用加final呢?...
  5. dingding上传图片的问题
  6. 香港科技大学陈浩教授招收AI全奖博士
  7. Expanding Low-Density Latent Regions for Open-Set Object Detection
  8. USACO——挤牛奶
  9. redis服务安装详细教程
  10. 微信小程序开发(一) 微信登录流程