【HC32F460开发板测评】02.搭建开发环境、创建工程、实现LED闪烁功能
本帖最后由 xld0932 于 2021-3-31 22:26 编辑<p>1、概述</p>
<p> 本篇主要讲述基于HC32F460开发板来搭建开发环境、创建基础工程、编写简单的入门示例,掌握对GPIO输出控制LED灯显示的功能;</p>
<p>2、安装Keil MDK-ARM集成开发环境</p>
<p>2.1.到Keil的官网:<span lang="EN-US" style="font-size:10.5pt"><span style="font-family:等线"><span style="text-decoration: underline; font-family: 幼圆;"><a href="https://www.keil.com/download/product/" style="color:#0563c1; text-decoration:underline">https://www.keil.com/download/product/</a></span></span></span>下载最新版本的MDK-ARM软件;</p>
<p>2.2.双击MDK534.EXE来进行软件安装,如下图所示,点击Next:</p>
<p>2.3.勾选同意事项,然后点击Next,如下图所示:</p>
<p>2.4.选择软件的安装路径,然后点击Next,如下图所示:</p>
<p>2.5.填写相应的信息后,点击Next,如下图所示:</p>
<p>2.6.等待安装完成,如下图所示:</p>
<p>2.7.软件安装完成后,显示如下图所示界面,点击Finish完成安装:</p>
<p>2.8.这个时候,会在电脑桌面上自动生成一个Keil uVision的快捷图标,双击这个图标,可以打开Keil MDK-ARM集成开发环境:</p>
<p></p>
<p>3、安装IDE支持包</p>
<p>3.1.打开HC32F460_IDE_Rev1.0.6压缩包,双击HDSC.HC32F46x.1.0.6进行安装,如下图所示:</p>
<p>3.2.等待安装完成,点击Finish</p>
<p>4.创建Keil工程</p>
<p>4.1.双击电脑桌面上的Keil uVision图标,打开Keil MDK-ARM集成开发环境;</p>
<p>4.2.点击菜单栏Project->New uVision Project...</p>
<p>4.3.在弹出的Create New Project窗口中选择工程需要保存的存储路径,输入工程名称,如下图所示:</p>
<p>4.4.在弹出的Select Device for Target窗口中,根据开发板上MCU型号,选择MCU型号为HC32F460PET6,然后点击OK,如下图所示:</p>
<p>4.5.在Manage Run-Time Enviroment窗口中,选择CMSIS中的CORE及Device中的Startup,然后点击OK,如下图所示:</p>
<p>4.6.这个时候一个空的项目工程就创建好了,这个时候,我们需要在这个空的工程中添加程序文件和对工程进行相应的配置;</p>
<p>4.7.点击工具栏上的Manage Project Items按钮,如下图所示:</p>
<p>4.8.在弹出的Manage Project Items窗口中,添加工程的Groups分组、每个分组中添加相应程序源文件,然后点击OK,如下图所示:</p>
<p>4.9.点击工具栏Options for Target对项目工程进行配置,如下图所示:</p>
<p>4.10.在Target选项卡中,晶振输入8MHz,ARM Compiler选用V5版本,当前不使用硬件浮点、勾选Use MicroLIB选项,如下图所示:</p>
<p>4.11.在Outout选项卡中,输入编译后项目生成文件的文件名,如下图所示:</p>
<p>4.12.在C/C++选项卡中,定义相应的宏、添加头文件包含路径;如下图所示:</p>
<p></p>
<p>4.13.在Debug选项卡中,选择调试下载工具为J-LINI,点击Settings,选择调试对口为JTAG;当前调试工具与开发处于连接的状态,可以通过如下图所示,工具正常检测到了芯片;如果J-LINK工具无法识别HC32F460的芯片,可以直接选用Cortex-M4核的通用芯片即可;如下图所示:</p>
<p></p>
<p>4.14在Utilities选项卡中,勾选Use Debug Driver;然后点击Settings,在弹出的对话框中,勾选Reset and Run,点击确定;如下图所示:</p>
<p></p>
<p>4.15.到此整个项目的工程就配置完成了,接下来就是编写功能代码了;</p>
<p>5.编程实现LED闪烁功能</p>
<p>5.1.LED.c程序源码</p>
<pre>
<code class="language-cpp">/*******************************************************************************
* @file LED.c
* @authorxld0932
* <a href="home.php?mod=space&uid=252314" target="_blank">@version</a> V1.00
* <a href="home.php?mod=space&uid=311857" target="_blank">@date</a> 31-Mar-2021
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief</a> ......
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#define __LED_C__
/* Includes ------------------------------------------------------------------*/
#include "LED.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* LED0 Port/Pin definition */
#defineLED0_PORT (PortE)
#defineLED0_PIN (Pin06)
/* LED1 Port/Pin definition */
#defineLED1_PORT (PortA)
#defineLED1_PIN (Pin07)
/* LED2 Port/Pin definition */
#defineLED2_PORT (PortB)
#defineLED2_PIN (Pin05)
/* LED3 Port/Pin definition */
#defineLED3_PORT (PortB)
#defineLED3_PIN (Pin09)
/* Private macro -------------------------------------------------------------*/
/* LED0~3 toggle definition */
#defineLED0_TOGGLE() (PORT_Toggle(LED0_PORT, LED0_PIN))
#defineLED1_TOGGLE() (PORT_Toggle(LED1_PORT, LED1_PIN))
#defineLED2_TOGGLE() (PORT_Toggle(LED2_PORT, LED2_PIN))
#defineLED3_TOGGLE() (PORT_Toggle(LED3_PORT, LED3_PIN))
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported function prototypes ----------------------------------------------*/
/*******************************************************************************
* @brief
* @param
* @retval
* <a href="home.php?mod=space&uid=1020061" target="_blank">@attention</a> *******************************************************************************/
void LED_Init(void)
{
stc_port_init_t stcPortInit;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcPortInit);
stcPortInit.enPinMode = Pin_Mode_Out;
stcPortInit.enExInt = Enable;
stcPortInit.enPullUp= Enable;
/* LED0 Port/Pin initialization */
PORT_Init(LED0_PORT, LED0_PIN, &stcPortInit);
/* LED1 Port/Pin initialization */
PORT_Init(LED1_PORT, LED1_PIN, &stcPortInit);
/* LED2 Port/Pin initialization */
PORT_Init(LED2_PORT, LED2_PIN, &stcPortInit);
/* LED3 Port/Pin initialization */
PORT_Init(LED3_PORT, LED3_PIN, &stcPortInit);
}
/*******************************************************************************
* @brief
* @param
* @retval
* @attention
*******************************************************************************/
void LED_Toggle(void)
{
LED0_TOGGLE();Ddl_Delay1ms(100);
LED1_TOGGLE();Ddl_Delay1ms(100);
LED2_TOGGLE();Ddl_Delay1ms(100);
LED3_TOGGLE();Ddl_Delay1ms(100);
}
/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
</code></pre>
<p>5.2.LED.h程序源码</p>
<pre>
<code class="language-cpp">/*******************************************************************************
* @file LED.h
* @authorxld0932
* @version V1.00
* @date 31-Mar-2021
* @brief ......
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LED_H__
#define __LED_H__
#ifdef __cplusplus
extern "C" {
#endif
#undefEXTERN
#ifdef__LED_C__
#define EXTERN
#else
#define EXTERN extern
#endif
/* Includes ------------------------------------------------------------------*/
#include "config.h"
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
EXTERN void LED_Init(void);
EXTERN void LED_Toggle(void);
#ifdef __cplusplus
}
#endif
#endif
/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
</code></pre>
<p>5.3.main.c程序源码</p>
<pre>
<code class="language-cpp">/*******************************************************************************
* @file main.c
* @authorxld0932
* @version V1.00
* @date 31-Mar-2021
* @brief ......
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#define __MAIN_C__
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported function prototypes ----------------------------------------------*/
/*******************************************************************************
* @brief
* @param
* @retval
* @attention
*******************************************************************************/
int main(void)
{
LED_Init();
while(1)
{
LED_Toggle();
}
}
/******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
</code></pre>
<p>5.4.需要注意的是,<span style="color:#e74c3c;"><strong>在使用MCU的各个外设时,需要在ddl_config.h配置文件中进行相应的开关设置</strong></span>,如下所示:</p>
<pre>
<code class="language-cpp">/*******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co., Ltd. ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACCOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl_config.h
**
** A detailed description is available at
** <a href="home.php?mod=space&uid=43623" target="_blank">@link</a> DdlConfigGroup Ddl Config description @endlink
**
** - 2018-9-271.0Yangjp First version for Device Driver Library config.
**
******************************************************************************/
#ifndef __DDL_CONFIG_H__
#define __DDL_CONFIG_H__
/*******************************************************************************
* Include files
******************************************************************************/
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup DdlConfigGroup Device Driver Library config(DDLCONFIG)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*! Chip module on-off define */
#define DDL_ON 1u
#define DDL_OFF 0u
/**
*******************************************************************************
** \brief This is the list of modules to be used in the device driver library
** Select the modules you need to use to DDL_ON.
**
** \note DDL_ICG_ENABLE and DDL_UTILITY_ENABLE must be turned on(DDL_ON) to
** ensure that the chip works properly.
******************************************************************************/
#define DDL_ICG_ENABLE DDL_ON
#define DDL_UTILITY_ENABLE DDL_ON
#define DDL_ADC_ENABLE DDL_OFF
#define DDL_AES_ENABLE DDL_OFF
#define DDL_CAN_ENABLE DDL_OFF
#define DDL_CMP_ENABLE DDL_OFF
#define DDL_CLK_ENABLE DDL_OFF
#define DDL_DCU_ENABLE DDL_OFF
#define DDL_DMAC_ENABLE DDL_OFF
#define DDL_EFM_ENABLE DDL_OFF
#define DDL_EMB_ENABLE DDL_OFF
#define DDL_EXINT_NMI_SWI_ENABLE DDL_OFF
#define DDL_GPIO_ENABLE DDL_ON
#define DDL_HASH_ENABLE DDL_OFF
#define DDL_I2C_ENABLE DDL_OFF
#define DDL_I2S_ENABLE DDL_OFF
#define DDL_INTERRUPTS_ENABLE DDL_OFF
#define DDL_KEYSCAN_ENABLE DDL_OFF
#define DDL_MPU_ENABLE DDL_OFF
#define DDL_OTS_ENABLE DDL_OFF
#define DDL_PGA_ENABLE DDL_OFF
#define DDL_PWC_ENABLE DDL_OFF
#define DDL_QSPI_ENABLE DDL_OFF
#define DDL_RMU_ENABLE DDL_OFF
#define DDL_RTC_ENABLE DDL_OFF
#define DDL_SDIOC_ENABLE DDL_OFF
#define DDL_SPI_ENABLE DDL_OFF
#define DDL_SRAM_ENABLE DDL_OFF
#define DDL_SWDT_ENABLE DDL_OFF
#define DDL_TIMER0_ENABLE DDL_OFF
#define DDL_TIMER4_CNT_ENABLE DDL_OFF
#define DDL_TIMER4_EMB_ENABLE DDL_OFF
#define DDL_TIMER4_OCO_ENABLE DDL_OFF
#define DDL_TIMER4_PWM_ENABLE DDL_OFF
#define DDL_TIMER4_SEVT_ENABLE DDL_OFF
#define DDL_TIMER6_ENABLE DDL_OFF
#define DDL_TIMERA_ENABLE DDL_OFF
#define DDL_TRNG_ENABLE DDL_OFF
#define DDL_USART_ENABLE DDL_OFF
#define DDL_USBFS_ENABLE DDL_OFF
#define DDL_WDT_ENABLE DDL_OFF
/*! Midware module on-off define */
#define MW_ON 1u
#define MW_OFF 0u
/**
*******************************************************************************
** \brief This is the list of Midware modules to use
** Select the modules you need to use to MW_ON.
******************************************************************************/
#define MW_SD_CARD_ENABLE MW_OFF
#define MW_USB_ENABLE MW_OFF
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//@} // DdlConfigGroup
#ifdef __cplusplus
}
#endif
#endif /* __DDL_CONFIG_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
</code></pre>
<p> </p>
<p>6.在完成代码功能后,对代码进行编译、下载、运行;我们就来看一下最终程序运行的效果吧</p>
<p><iframe allowfullscreen="true" frameborder="0" height="510" src="https://training.eeworld.com.cn/shareOpenCourseAPI?isauto=true&lessonid=29692" style="background:#eee;margin-bottom:10px;" width="750"></iframe></p>
<p>7.工程源代码</p>
<p></p>
<p>赞~谢谢分享~~</p>
<p>开发板配套的历程就一个.C文件,看着不习惯,还是这个写发看着舒服</p>
<p>最后的那个程序运行的效果的视频,录制的有点短</p>
<p>我用历程里面的空工程文件(hc32f460petb_template)添加了driver文件之后总是出错<img height="29" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/face-with-cold-sweat_1f613.png" width="29" /></p>
<p>不知道是哪里出了问题</p>
<p> </p>
1nnocent 发表于 2021-4-2 11:22
我用历程里面的空工程文件(hc32f460petb_template)添加了driver文件之后总是出错
不知道是哪里出了问 ...
<p>我在config文件里面将GPIO使能打开了,但是编译后main,c文件并没有把GPIO相应的头文件包含进来</p>
<p> </p>
<p>感觉还不错,这个教程非常详细了!点个赞,期待后续的测评帖子哦!</p>
<p>赞~很好的帖子</p>
<p><br/>不需要系统时钟使能吗?<br/></p>
页:
[1]