【国民技术N32WB031_STB开发板评测】创建MDK模版
[复制链接]
1、下载pack包,【国民技术N32WB031_STB开发板评测】资源的下载 - RF/无线 - 电子工程世界-论坛 (eeworld.com.cn)
2、解压SDK后,我们双击安装Pack包:
3、安装的话一路Nexct就行了。
4、新建一个template文件夹,用来创建我们以后的工程:
5、拷贝SDK中的firmware、bsp文件到模版目录:
6、新建APP用于存放man.c,新建MDK用于保存mdk的输出文件、工程文件等:
7、在MDK目录下面新建文件夹bin、Listings、Objects分别用来存放bin或者hex固件、链接文件、编译的中间文件
8、打开MDK,新建工程到template的MDK文件夹下:
9、按下图添加启动汇编文件startup_n32wb03x.s,如下图所示:
10、新建CMSIS,并添加system_n32wb03x.c
11、新建FWLB用于存官方驱动,添加misc.c、n32wb03x_gpio.c、n32wb03x_rcc.c、n32wb03x_usart.c
12、新建DOC用于存放readme.txt记录日志等。新建bsp把log.c加入进来,新建APP用来存放main.c
目录与文件大致如下图:
13、添加头文件:
14、添加rebuild输出 :fromelf --bin --output=.\bin\N32WB03.bin .\Objects\N32WB03_Template.axf
15、添加宏定义:N32WB03X, USE_STDPERIPH_DRIVER, USE_FULL_ASSERT
17、编译一下,没有报错:
到些模块就建好了。
18、添加测试代码:
#include "main.h"
#include <stdio.h>
#include <stdint.h>
int main(void)
{
LedInit(LED1_PORT, LED1_PIN);
LedInit(LED2_PORT, LED2_PIN);
LedOn(LED1_PORT, LED1_PIN);
LedOn(LED2_PORT, LED2_PIN);
while (1)
{
LedBlink(LED1_PORT, LED1_PIN);
LedOff(LED2_PORT, LED2_PIN);
Delay(0x28FFFF);
LedOn(LED2_PORT, LED2_PIN);
Delay(0x28FFFF);
}
}
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] Configures LED GPIO.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedInit(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_InitType GPIO_InitStructure;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
/* Enable the GPIO Clock */
if (GPIOx == GPIOA)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
}
else if (GPIOx == GPIOB)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
}
else
{
return;
}
/* Configure the GPIO pin */
if (Pin <= GPIO_PIN_ALL)
{
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
}
}
/**
* @brief Turns selected Led on.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedOn(GPIO_Module *GPIOx, uint16_t Pin)
{
GPIO_SetBits(GPIOx, Pin);
}
/**
* @brief Turns selected Led Off.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedOff(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_ResetBits(GPIOx, Pin);
}
/**
* @brief Toggles the selected Led.
* @param GPIOx x can be A to G to select the GPIO port.
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
*/
void LedBlink(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_TogglePin(GPIOx, Pin);
}
下载后,就可以看到两个LED灯在闪烁了。
|