这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 【FRDMRW612系列】2、GPIO体验

共1条 1/1 1 跳转至

【FRDMRW612系列】2、GPIO体验

高工
2026-07-17 11:39:19     打赏

【软件环境】

MCUXpresso IDE 25.6

【LED原理图】

打开FRDMRW612数据手册,查找到LED部分

image.png

开发板可供用户使用的有三个LED,分别接到了GPIO_1、GPIO_12、GPIO_0。低电平点亮。

【工程配置】

在helloworld的工程中打开配置工具。

image.png

配置GPIO_0为output模式,更新源代码。

【代码实现】

1、查看board目录下面的pinmux.c中gpio的初始化代码:

/* FUNCTION ************************************************************************************************************
 *
 * Function Name : BOARD_InitPins
 * Description   : 
 *
 * END ****************************************************************************************************************/
/* Function assigned for the Cortex-M33 */
void BOARD_InitPins(void)
{
    /* Enables the clock for the GPIO0 module */
    GPIO_PortInit(GPIO, 0);

    gpio_pin_config_t gpio0_pinM1_config = {
        .pinDirection = kGPIO_DigitalOutput,
        .outputLogic = 0U
    };
    /* Initialize GPIO functionality on pin PIO0_0 (pin M1)  */
    GPIO_PinInit(GPIO, 0U, 0U, &gpio0_pinM1_config);
    /* Initialize FC3_USART_DATA functionality on pin GPIO_24 (pin E5) */
    IO_MUX_SetPinMux(IO_MUX_FC3_USART_DATA);
    /* Initialize GPIO0 functionality on pin GPIO_0 (pin M1) */
    IO_MUX_SetPinMux(IO_MUX_GPIO0);
}

可以看到对gpip_0已经初始化输出模式。

2、rw612的GPIO输出操作

/*!
 * @brief Sets the output level of the one GPIO pin to the logic 1 or 0.
 *
 * @param base    GPIO peripheral base pointer(Typically GPIO)
 * @param port   GPIO port number
 * @param pin    GPIO pin number
 * @param output  GPIO pin output logic level.
 *        - 0: corresponding pin output low-logic level.
 *        - 1: corresponding pin output high-logic level.
 */
static inline void GPIO_PinWrite(GPIO_Type *base, uint32_t port, uint32_t pin, uint8_t output)
{
base->B[port][pin] = output;
}

根据sdk中示例,我添加测试代码如下:

/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017, 2024 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "app.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * 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)
{
}
}

/*!
 * @brief Main function
 */
int main(void)
{
char ch;

/* Init board hardware. */
BOARD_InitHardware();

PRINTF("MCUX SDK version: %s\r\n", MCUXSDK_VERSION_FULL_STR);

PRINTF("hello world.\r\n");
/* Set systick reload value to generate 1ms interrupt */
if (SysTick_Config(SystemCoreClock / 1000U))
{
while (1)
{
}
}
while (1)
{
   	SysTick_DelayTicks(100U);
   	GPIO_PinWrite(GPIO, 0, 0, 1);
   	SysTick_DelayTicks(100U);
   	GPIO_PinWrite(GPIO, 0, 0, 0);
}
}

【下载验证】

下载好到开发板后,可以看到开板上的蓝色RGB灯以100ms的频率闪烁了。

【总结】

通过mcuxpresso ide的图形化配置,可以快速实现对GPIO output的操作。





关键词: FRDMRW612     MCUXpresso IDE         

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]