summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
authorHonestQiao <[email protected]>2026-07-12 20:58:13 +0800
committerGitHub <[email protected]>2026-07-12 20:58:13 +0800
commit66d3070c80f73a2f2aee7743d1241db8f607f8ea (patch)
tree153fb83312f77432cc8bb12aae37de50287f05a2 /bsp
parentb7eb6fb0e46f6674ea7711f1b5f2ff1a813ac678 (diff)
[bsp][imxrt1180-nxp-evk]add TIMER support (#11511)
* [bsp][imxrt1180-nxp-evk]add TIMER support * [bsp][imxrt1180-nxp-evk]update TIMER support * [bsp][imxrt1180-nxp-evk] move fsl_gpt.c inclusion to SDK package SConscript * [bsp][imxrt1180-nxp-evk] restore main.c to original Hello_World version * [bsp][imxrt1180-nxp-evk] remove libraries/drivers/drv_timer.h * [bsp][imxrt1180-nxp-evk]update TIMER support
Diffstat (limited to 'bsp')
-rw-r--r--bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig14
-rw-r--r--bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm7/board/Kconfig14
-rw-r--r--bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.c65
-rw-r--r--bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.h20
4 files changed, 84 insertions, 29 deletions
diff --git a/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig b/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig
index 699499cf04..cd9e9fabed 100644
--- a/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig
+++ b/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm33/board/Kconfig
@@ -138,6 +138,20 @@ menu "On-chip Peripheral Drivers"
default n
endif
+ menuconfig BSP_USING_CLOCK_TIMER
+ bool "Enable GPT"
+ default n
+ select RT_USING_CLOCK_TIME
+ if BSP_USING_CLOCK_TIMER
+ config BSP_USING_CLOCK_TIMER1
+ bool "Enable GPT1"
+ default n
+
+ config BSP_USING_CLOCK_TIMER2
+ bool "Enable GPT2"
+ default n
+ endif
+
menuconfig BSP_USING_FLEXSPI
bool "Enable FLEXSPI"
default n
diff --git a/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm7/board/Kconfig b/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm7/board/Kconfig
index 20b7ee5251..90ea8d58a2 100644
--- a/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm7/board/Kconfig
+++ b/bsp/nxp/imx/imxrt/imxrt1180-nxp-evk/cm7/board/Kconfig
@@ -152,6 +152,20 @@ menu "On-chip Peripheral Drivers"
bool "Enable FLEXSPI2"
default n
endif
+
+ menuconfig BSP_USING_CLOCK_TIMER
+ bool "Enable GPT"
+ default n
+ select RT_USING_CLOCK_TIME
+ if BSP_USING_CLOCK_TIMER
+ config BSP_USING_CLOCK_TIMER1
+ bool "Enable GPT1"
+ default n
+
+ config BSP_USING_CLOCK_TIMER2
+ bool "Enable GPT2"
+ default n
+ endif
endmenu
menu "Onboard Peripheral Drivers"
diff --git a/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.c b/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.c
index 860c483e92..24edb9f88e 100644
--- a/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.c
+++ b/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.c
@@ -17,7 +17,6 @@
#include <drv_log.h>
#include <rtdevice.h>
-#include "drv_timer.h"
#include "fsl_gpt.h"
#if defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL
@@ -29,15 +28,26 @@
/* Clock divider for PERCLK_CLK clock source */
#define EXAMPLE_GPT_CLOCK_DIVIDER_SELECT (5U)
/* Get source clock for GPT driver (GPT prescaler = 6) */
-#ifdef SOC_IMXRT1170_SERIES
+#if defined(SOC_IMXRT1170_SERIES) || defined(SOC_IMXRT1180_SERIES)
#undef EXAMPLE_GPT_CLOCK_DIVIDER_SELECT
#define EXAMPLE_GPT_CLOCK_DIVIDER_SELECT (2U)
-// 1170 use this root directly, we have already divide this clk, can read it directly
+// 1170/1180 use this root directly, we have already divide this clk, can read it directly
#define EXAMPLE_GPT_CLK_FREQ (CLOCK_GetRootClockFreq(kCLOCK_Root_Gpt1))
#else
#define EXAMPLE_GPT_CLK_FREQ (CLOCK_GetFreq(kCLOCK_IpgClk) / (EXAMPLE_GPT_CLOCK_DIVIDER_SELECT + 1U))
#endif
+/* The effective GPT input clock after root/prescaler configuration.
+ * 1170: 24 MHz root / 3 = 8 MHz; 1180: 240 MHz root / 3 = 80 MHz. */
+#if defined(SOC_IMXRT1180_SERIES)
+#define IMXRT_GPT_MAXFREQ (80000000U)
+#elif defined(SOC_IMXRT1170_SERIES)
+#define IMXRT_GPT_MAXFREQ (8000000U)
+#else
+#define IMXRT_GPT_MAXFREQ (25000000U)
+#endif
+#define IMXRT_GPT_MINFREQ (1U)
+
static void NVIC_Configuration(void)
{
#ifdef BSP_USING_CLOCK_TIMER1
@@ -62,9 +72,36 @@ static rt_err_t imxrt_clock_timer_control(rt_clock_timer_t *timer, rt_uint32_t c
case CLOCK_TIMER_CTRL_FREQ_SET:
{
uint32_t clk;
+ uint32_t freq;
uint32_t pre;
+
+ if (args == RT_NULL)
+ {
+ err = -RT_EEMPTY;
+ break;
+ }
+
+ freq = *((uint32_t *)args);
+ if (freq == 0U)
+ {
+ err = -RT_EINVAL;
+ break;
+ }
+
clk = EXAMPLE_GPT_CLK_FREQ;
- pre = clk / *((uint32_t *)args) - 1;
+ if (freq > clk)
+ {
+ err = -RT_EINVAL;
+ break;
+ }
+
+ pre = clk / freq - 1U;
+ if (pre > 4095U)
+ {
+ err = -RT_EINVAL;
+ break;
+ }
+
GPT_SetClockDivider(clock_timer_dev, pre);
}
break;
@@ -98,7 +135,7 @@ static void imxrt_clock_timer_init(rt_clock_timer_t *timer, rt_uint32_t state)
if (state == 1)
{
- #ifdef SOC_IMXRT1170_SERIES
+ #if defined(SOC_IMXRT1170_SERIES) || defined(SOC_IMXRT1180_SERIES)
#ifdef BSP_USING_CLOCK_TIMER1
/*Clock setting for GPT*/
CLOCK_SetRootClockMux(kCLOCK_Root_Gpt1, EXAMPLE_GPT_CLOCK_SOURCE_SELECT);
@@ -128,7 +165,16 @@ static rt_err_t imxrt_clock_timer_start(rt_clock_timer_t *timer, rt_uint32_t cnt
RT_ASSERT(timer != RT_NULL);
- clock_timer_dev->CR |= (mode != CLOCK_TIMER_MODE_PERIOD) ? GPT_CR_FRR_MASK : 0U;
+ if (mode == CLOCK_TIMER_MODE_PERIOD)
+ {
+ /* Restart mode: counter resets on output compare match, fixed interval */
+ clock_timer_dev->CR &= ~GPT_CR_FRR_MASK;
+ }
+ else
+ {
+ /* Free-run mode: counter keeps running, one-shot match */
+ clock_timer_dev->CR |= GPT_CR_FRR_MASK;
+ }
GPT_SetOutputCompareValue(clock_timer_dev, kGPT_OutputCompare_Channel1, cnt);
@@ -148,6 +194,7 @@ static void imxrt_clock_timer_stop(rt_clock_timer_t *timer)
RT_ASSERT(timer != RT_NULL);
+ GPT_DisableInterrupts(clock_timer_dev, kGPT_OutputCompare1InterruptEnable);
GPT_StopTimer(clock_timer_dev);
}
@@ -162,8 +209,8 @@ static const struct rt_clock_timer_ops imxrt_clock_timer_ops =
static const struct rt_clock_timer_info imxrt_clock_timer_info =
{
- 25000000, /* the maximum count frequency can be set */
- 6103, /* the minimum count frequency can be set */
+ IMXRT_GPT_MAXFREQ, /* the maximum count frequency can be set */
+ IMXRT_GPT_MINFREQ, /* the minimum count frequency can be set */
0xFFFFFFFF,
CLOCK_TIMER_CNTMODE_UP,
};
@@ -198,7 +245,7 @@ int rt_hw_clock_timer_init(void)
if (ret != RT_EOK)
{
- LOG_E("gpt1 register failed\n");
+ LOG_E("gpt2 register failed\n");
}
#endif
diff --git a/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.h b/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.h
deleted file mode 100644
index dc95a020b6..0000000000
--- a/bsp/nxp/imx/imxrt/libraries/drivers/drv_timer.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2006-2023, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
-* Change Logs:
-* Date Author Notes
-* 2018-04-17 WangBing the first version.
-*/
-
-#ifndef DRV_CLOCK_TIMER_H__
-#define DRV_CLOCK_TIMER_H__
-
-#include <rtthread.h>
-#include <rtdevice.h>
-
-int rt_hw_wdt_init(void);
-
-#endif
-