【英飞凌PSOC™ 4100S Max】④基于HAL的极简点灯之旅
<div class='showpostmsg'><p>本篇分享一个简单的点灯之旅。</p><p>首先,我们新建一个空白的(模板)项目:</p>
<p> </p>
<p> </p>
<p> </p>
<p>在新建的工程,左下角可以看到:<strong>Device Configurator 4.0</strong></p>
<p>没错,这就是英飞凌Modus Toolbox的图形化配置工具,类似意法半导体的<strong>CubeMX</strong></p>
<p> </p>
<p> </p>
<p>在<strong>Device Configurator </strong> 界面,我们可以看到熟悉的画面。</p>
<p> </p>
<p>外设设置</p>
<p> </p>
<p>管脚设置</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> <strong>时钟设置</strong></p>
<p> </p>
<p><strong>DMA设置</strong></p>
<p> </p>
<p> </p>
<p>设置好后,对应的右侧就自动生成了可用的代码。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<pre>
<code>/* NOTE: This is a preview only. It combines elements of the
* cycfg_pins.c and cycfg_pins.h files located in the folder
* C:/Users/Administrator/InfineonWork/00/libs/TARGET_CY8CKIT-041S-MAX/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource.
*/
#include "cy_gpio.h"
#if defined (CY_USING_HAL)
#include "cyhal_hwmgr.h"
#endif //defined (CY_USING_HAL)
#define ioss_0_port_6_pin_4_PORT GPIO_PRT6
#define ioss_0_port_6_pin_4_PORT_NUM 6U
#define ioss_0_port_6_pin_4_PIN 4U
#define ioss_0_port_6_pin_4_NUM 4U
#define ioss_0_port_6_pin_4_DRIVEMODE CY_GPIO_DM_PULLDOWN_IN_OFF
#define ioss_0_port_6_pin_4_INIT_DRIVESTATE 1
#ifndef ioss_0_port_6_pin_4_HSIOM
#define ioss_0_port_6_pin_4_HSIOM HSIOM_SEL_GPIO
#endif
#define ioss_0_port_6_pin_4_IRQ ioss_interrupt_gpio_IRQn
#if defined (CY_USING_HAL)
#define ioss_0_port_6_pin_4_HAL_PORT_PIN P6_4
#define ioss_0_port_6_pin_4 P6_4
#define ioss_0_port_6_pin_4_HAL_IRQ CYHAL_GPIO_IRQ_NONE
#define ioss_0_port_6_pin_4_HAL_DIR CYHAL_GPIO_DIR_OUTPUT
#define ioss_0_port_6_pin_4_HAL_DRIVEMODE CYHAL_GPIO_DRIVE_PULLDOWN
#endif //defined (CY_USING_HAL)
const cy_stc_gpio_pin_config_t ioss_0_port_6_pin_4_config =
{
.outVal = 1,
.driveMode = CY_GPIO_DM_PULLDOWN_IN_OFF,
.hsiom = ioss_0_port_6_pin_4_HSIOM,
.intEdge = CY_GPIO_INTR_DISABLE,
.vtrip = CY_GPIO_VTRIP_CMOS,
.slewRate = CY_GPIO_SLEW_FAST,
.vregEn = 0UL,
.ibufMode = 0UL,
.vtripSel = 0UL,
.vrefSel = 0UL,
.vohSel = 0UL,
};
#if defined (CY_USING_HAL)
const cyhal_resource_inst_t ioss_0_port_6_pin_4_obj =
{
.type = CYHAL_RSC_GPIO,
.block_num = ioss_0_port_6_pin_4_PORT_NUM,
.channel_num = ioss_0_port_6_pin_4_PIN,
};
#endif //defined (CY_USING_HAL)
void init_cycfg_pins(void)
{
Cy_GPIO_Pin_Init(ioss_0_port_6_pin_4_PORT, ioss_0_port_6_pin_4_PIN, &ioss_0_port_6_pin_4_config);
}
void reserve_cycfg_pins(void)
{
#if defined (CY_USING_HAL)
cyhal_hwmgr_reserve(&ioss_0_port_6_pin_4_obj);
#endif //defined (CY_USING_HAL)
}
</code></pre>
<p> </p>
<p>本例完成简单的点灯之旅,因功能极其简单,就直接用HAL函数了。</p>
<p>cy_gpio.h</p>
<p> </p>
<p> </p>
<pre>
<code>#include "cy_pdl.h"
#include "cybsp.h"
#include "cy_gpio.h"
int main(void)
{
Cy_GPIO_Pin_FastInit(GPIO_PRT6,4u,CY_GPIO_DM_PULLDOWN,0,0); //P6.4下拉,功能为IO,初始值0
Cy_GPIO_Pin_FastInit(GPIO_PRT12,0u,CY_GPIO_DM_PULLDOWN,0,0);//P12.0下拉,功能为IO,初始值0
for (;;)
{
Cy_GPIO_Inv(GPIO_PRT6, 4u);
Cy_GPIO_Inv(GPIO_PRT12, 0u);
/* Wait for 0.5 seconds */
Cy_SysLib_Delay(500);
}
}
</code></pre>
<p> </p>
<p> </p>
<p>编译运行就可以看到LED2(P6.4),LED3(P12.0)闪烁了。</p>
<p> </p>
<p> </p>
<p>a88c92344f9cb8d5dae9e597d1a0789b<br />
</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>这图形化配置工具一家一个特色啊 </p>
秦天qintian0303 发表于 2024-12-2 09:06
这图形化配置工具一家一个特色啊
<p>用了这么多家,个人感觉还是ST的CubeMX最好用:loveliness:</p>
页:
[1]