EFR32FG1开发教程1--点亮LED
前⾔:EFR32芯⽚开发⼯具主要有两个,Simplicity Studio、IAR FOR ARM。个⼈习惯和不喜欢Simplicity Studio代码⽣成⼯具⽣成许多没有作⽤的⽂件和代码原因,采⽤IAR作为开发⼯具。
1. 开发⽂件准备:在⼯程⽬录下建⽴CMSIS⽂件夹
1.1复制软件Simplicity Studio安装⽬录的emlib⽂件夹到⼯程⽬
录SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.2\platform\emlib
1.2复制EFR32FG1P⽂件夹到⼯程⽬录CMSIS⽂件夹下
SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.2\platform\Device\SiliconLabs\EFR32FG1P
1.3复制Include⽂件夹到⼯程⽬录CMSIS⽂件夹下
SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.2\platform\CMSIS\Include
1.4⼯程⽬录下建⽴BSP、USER⽂件夹,如下图所⽰:
2. IAR建⽴⼯程
msi是什么意思2.1选取对应型号,如下图
2.2 在⼯程⽬录中添加main.c和CMSIS\EFR32FG1P\Source下的system_efr32fg1p.c和CMSIS\EFR32FG1P\SourceIAR下的startup_efr32fg1p.s⽂件,并添加库函数到⼯程中,如下图
2.3 ⼯程头⽂件路径添加,并添加全局宏定义EFR32FG1P132F128GM48 如下图所⽰$PROJ_DIR$\USER
store怎么读$PROJ_DIR$\CMSIS\EFR32FG1P\Include
$PROJ_DIR$\CMSIS\Include
$PROJ_DIR$\emlib\inc
children怎么读
3.正式编写程序
/**
******************************************************************************
* @file main.c
* @author Garen
* @version V1.0.0
* @date 2018-05-21
* @brief 程序⼊⼝main函数所在⽂件
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "em_gpio.h"
/* extern variables ---------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
boron/* Private functions ---------------------------------------------------------*/
/**
* @brief 时钟初始化
* @retval None
*/
void BSP_ClocksInit(void)
{
// Device errata
CHIP_Init();
// Initialize the system clocks //时钟采⽤外部晶振38.4M
CMU_HFXOInit_TypeDef hfxoInit = CMU_HFXOINIT_DEFAULT;
CMU_HFXOInit(&hfxoInit);
SystemHFXOClockSet(38400000UL);
// Enable HFXO oscillator, and wait for it to be stable
CMU_OscillatorEnable(cmuOsc_HFXO, true, true);
// U HFXO as high frequency clock
avant gardeCMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
// HFRCO not needed when using HFXO
CMU_OscillatorEnable(cmuOsc_HFRCO, fal, fal);
CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);
CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFRCO);
CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO);
// Default to LFRCO, it's the only option always prent,
// the code below will pick a better option if available
CMU_Osc_TypeDef lowFrequencyClockSource = cmuOsc_LFRCO;
CMU_Select_TypeDef lowFrequencyClockSelect = cmuSelect_LFRCO; if (CMU->STATUS & CMU_STATUS_LFXOENS)
{
lowFrequencyClockSource = cmuOsc_LFXO;
lowFrequencyClockSelect = cmuSelect_LFXO;
brood}
larissa// Enable necessary clocks and t clock lections
CMU_ClockEnable(cmuClock_CORELE, true);
hercyna
CMU_OscillatorEnable(lowFrequencyClockSource, true, true);
CMU_ClockSelectSet(cmuClock_LFA, lowFrequencyClockSelect);
CMU_ClockSelectSet(cmuClock_LFB, lowFrequencyClockSelect);同性恋 英文
CMU_ClockSelectSet(cmuClock_LFE, lowFrequencyClockSelect);
}
/**
* @brief 初始化led对应的IO
* @retval None
*/
void BSP_LedInit(void)
{
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
食草系GPIO_PinModeSet(gpioPortC,11, gpioModePushPull, 1);
}
/
**
* @brief 点亮LED
* @retval None
*/
void BSP_LedOn(void)
{
GPIO_PinOutClear(gpioPortC, 11);
}
/**
* @brief 程序总⼊⼝main()函数 * @retval int
*/
int main(void)
{
//Initialize the system clocks
BSP_ClocksInit();
// Initialize the LEDs on the board BSP_LedInit();
//led on
BSP_LedOn();
while(1)
{
}
}