TA的每日心情 | 奋斗 昨天 13:19 |
|---|
签到天数: 2644 天 连续签到: 36 天 [LV.Master]伴坛终老
司徒
- 积分
- 40475
|
本帖最后由 yinwuqing 于 2024-11-12 00:16 编辑
一、前言
FRDM-MCXN947试用活动由安富利与eefocus联合举办,非常荣幸能够获得此次试用机会。其实早在今年三月份,在NXP技术交流社区,申请到MCX-N947-BRK板,当时没注意就将这两块板搞混,后面在实际评测中才发觉硬件电路上是有明显差异的。我们知道MCXN947采用双核架构,集成两个Cortex-M33内核和神经处理单元,工作主频150MHz,搭配2048KB Flash/512KB RAM,是一款高度集成的微控制器,板卡上采用BGA封装,占用PCB面积小,为高性能要求、低成本设计的项目提供了可能。
二、获取资料
关于FRDM-MCXN947开发板的资料包,用户可通过MCUXpresso SDK构建工具构建FRDM-MCXN947,当然用户必须先得在NXP官网上注册一个账号,然后进入到该网页,选择使用该SDK应用在的主机操作系统,一般是windows系统,选择导出适用的工具链即IDE平台。这里建议选择“所有工具链”,接着勾选集成相对应功能接口的工程参考示例,最后选择底下的“构建SDK”,然后下载即可。
这里笔者还是采用先前构建的“SDK_2.14.0_FRDM-MCXN947”版本,当前NXP官方已经提供了“SDK_2.16.100_FRDM-MCXN947”版本,两个版本大体上相同,只是对部分功能接口进行了优化。
三、开箱上电
板卡拿到手已有一段时间了,跟其它坛友一样,来晒晒这块高性能的开发板吧。
上面为纸盒中的全部物料,接下来拆开防静电袋,对核心板来个特写。
使用Type-C数据线给板卡上电,板卡出厂默认的点灯状态变化如下:
四、环境搭建
官方主推采用MCUXpressoIDE进行SDK导入,使用该IDE导入不需要将构建好的SDK包解压。直接拖入IDE底下的表格中。不过笔者习惯与MDK工具,因此这里介绍一下使用Keil开发FRDM-MCXN947。既然使用Keil开发,首先我们得安装好基于MCXN947的pack支持包,“NXP.MCXN947_DFP.19.0.0.pack”文件分享如下附件:
将构建好的“SDK_2_14_0_FRDM-MCXN947.zip”文件解压到无中文字符、无空格的文件夹路径下,然后进入到“\boards\frdmmcxn947\demo_apps\led_blinky”目录,使用Keil uVision5打开led_blinky工程,此时工程全编译ok,要想实现点亮RGB的其它颜色,需要修改系统默认的工程源码。
五、代码编写
编写之前,需要了解一下这款开发板的整体硬件布局,开发板的资源框图,官方已在原理图中给出。
主要是注意RGB灯的管脚,因为官方闪灯只用到RGB的红色管脚,在原理图中的第11页,我们可得知RGB灯信号引脚分布。
由上图可知,RGB的三颗灯都是低电平有效,因此在代码中增加逻辑处理代码如下:
pin_mux.c增加绿灯、蓝灯的初始化设置。pin_mux.c
- #include "fsl_common.h"
- #include "fsl_port.h"
- #include "pin_mux.h"
- void BOARD_InitBootPins(void)
- {
- BOARD_InitPins();
- }
- void BOARD_InitPins(void)
- {
- /* Enables the clock for PORT0 controller: Enables clock */
- CLOCK_EnableClock(kCLOCK_Port0);
- /* Enables the clock for PORT1 controller: Enables clock */
- CLOCK_EnableClock(kCLOCK_Port1);
- const port_pin_config_t port0_10_pinB12_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_10 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_10 (pin B12) is configured as PIO0_10 */
- PORT_SetPinConfig(PORT0, 10U, &port0_10_pinB12_config);
- const port_pin_config_t port0_27_pinE10_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_27 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_27 (pin E10) is configured as PIO0_27 */
- PORT_SetPinConfig(PORT0, 27U, &port0_27_pinE10_config);
- const port_pin_config_t port1_2_pinC04_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO1_2 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT1_2 (pin C04) is configured as PIO1_2 */
- PORT_SetPinConfig(PORT1, 2U, &port1_2_pinC04_config);
- const port_pin_config_t port0_2_pinB16_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* High drive strength is configured */
- kPORT_HighDriveStrength,
- /* Pin is configured as SWO */
- kPORT_MuxAlt1,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_2 (pin B16) is configured as SWO */
- PORT_SetPinConfig(PORT0, 2U, &port0_2_pinB16_config);
- }
复制代码
led_blinky.c
- #include "pin_mux.h"
- #include "peripherals.h"
- #include "board.h"
- /*******************************************************************************
- * Variables
- ******************************************************************************/
- volatile uint32_t g_systickCounter;
- /*******************************************************************************
- * Code
- ******************************************************************************/
- void SysTick_Handler(void)
- {
- if (g_systickCounter != 0U)
- {
- g_systickCounter--;
- }
- }
- void SysTick_DelayTicks(uint32_t n)
- {
- g_systickCounter = n;
- while (g_systickCounter != 0U){}
- }
- int main(void)
- {
- /* Board pin init */
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio1);
- BOARD_InitPins();
- LED_RED_INIT(LOGIC_LED_OFF);
- LED_BLUE_INIT(LOGIC_LED_OFF);
- LED_GREEN_INIT(LOGIC_LED_OFF);
-
- /* Set systick reload value to generate 1ms interrupt */
- if (SysTick_Config(SystemCoreClock / 1000U))
- {
- while (1){}
- }
- while (1)
- {
- /* Delay 300 ms */
- SysTick_DelayTicks(300U);
- GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1u << BOARD_LED_GREEN_GPIO_PIN);
- SysTick_DelayTicks(300U);
- GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1u << BOARD_LED_BLUE_GPIO_PIN);
- SysTick_DelayTicks(300U);
- GPIO_PortToggle(BOARD_LED_RED_GPIO, 1u << BOARD_LED_RED_GPIO_PIN);
- }
- }
复制代码
六、编译下载
点击编译图标,完成整个工程编译,此时生成的固件针对core0内核,选择“CMSIS-DAP”接口方式
添加相应的下载算法
七、在线运行闪灯效果
由于编译后的固件程序是下载到core0中运行的,Keil工程中有release版与debug版,直接在线调试debug版,全速运行,则能看到固件程序在core0内核中执行的效果。
|
|