This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 3cf4fbf1e76 arch/arm/stm32: Add getedges support to timer capture
drivers
3cf4fbf1e76 is described below
commit 3cf4fbf1e762b133814923c13aa92044ef4b83e5
Author: Swatantra Yadav <[email protected]>
AuthorDate: Wed Oct 28 00:05:13 2026 +0530
arch/arm/stm32: Add getedges support to timer capture drivers
Implement the getedges callback and edge counting in the timer capture
lower-half drivers for STM32H7, STM32H5, and STM32 M3/M4. This enables users to
query pulse edge counts via CAPIOC_EDGES and CAPIOC_ALL ioctls, and resolves
issue #16828.
Signed-off-by: Swatantra Yadav <[email protected]>
---
.../common/stm32/stm32_capture_m3m4_v1_lowerhalf.c | 35 +++++++++++++++++++++
arch/arm/src/stm32h5/stm32_capture_lowerhalf.c | 36 ++++++++++++++++++++++
arch/arm/src/stm32h7/stm32_capture_lowerhalf.c | 35 +++++++++++++++++++++
3 files changed, 106 insertions(+)
diff --git a/arch/arm/src/common/stm32/stm32_capture_m3m4_v1_lowerhalf.c
b/arch/arm/src/common/stm32/stm32_capture_m3m4_v1_lowerhalf.c
index ea4e0b174fb..3c6f7d8f79f 100644
--- a/arch/arm/src/common/stm32/stm32_capture_m3m4_v1_lowerhalf.c
+++ b/arch/arm/src/common/stm32/stm32_capture_m3m4_v1_lowerhalf.c
@@ -85,6 +85,7 @@ struct stm32_lowerhalf_s
uint32_t clock; /* Timer clock frequency */
uint8_t duty; /* Result pwm frequency */
uint32_t freq; /* Result pwm frequency */
+ uint32_t edges; /* Result pwm edges */
};
/****************************************************************************
@@ -99,6 +100,7 @@ static int stm32_start(struct cap_lowerhalf_s *lower);
static int stm32_stop(struct cap_lowerhalf_s *lower);
static int stm32_getduty(struct cap_lowerhalf_s *lower, uint8_t *duty);
static int stm32_getfreq(struct cap_lowerhalf_s *lower, uint32_t *freq);
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges);
/****************************************************************************
* Private Data
@@ -112,6 +114,7 @@ static const struct cap_ops_s g_cap_ops =
.stop = stm32_stop,
.getduty = stm32_getduty,
.getfreq = stm32_getfreq,
+ .getedges = stm32_getedges,
};
#ifdef CONFIG_STM32_TIM1_CAP
@@ -274,6 +277,7 @@ static int stm32_cap_handler(int irq, void * context, void
* arg)
}
lower->freq = lower->clock / period;
+ lower->edges++;
return OK;
}
@@ -306,6 +310,8 @@ static int stm32_start(struct cap_lowerhalf_s *lower)
return -EBUSY;
}
+ priv->edges = 0;
+
switch (priv->channel)
{
case 1:
@@ -466,6 +472,35 @@ static int stm32_getfreq(struct cap_lowerhalf_s *lower,
uint32_t *freq)
return OK;
}
+/****************************************************************************
+ * Name: stm32_getedges
+ *
+ * Description:
+ * get result edges
+ *
+ * Input Parameters:
+ * lower - A pointer the publicly visible representation of the
+ * "lower-half" driver state structure.
+ * edges - Number of edges seen.
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges)
+{
+ struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
+
+ irqstate_t flags = enter_critical_section();
+
+ *edges = priv->edges;
+
+ leave_critical_section(flags);
+
+ return OK;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/arch/arm/src/stm32h5/stm32_capture_lowerhalf.c
b/arch/arm/src/stm32h5/stm32_capture_lowerhalf.c
index 5b7e4a48619..8975ae3cc99 100644
--- a/arch/arm/src/stm32h5/stm32_capture_lowerhalf.c
+++ b/arch/arm/src/stm32h5/stm32_capture_lowerhalf.c
@@ -85,6 +85,7 @@ struct stm32_lowerhalf_s
uint32_t clock; /* Timer clock frequency */
uint8_t duty; /* Result pwm frequency */
uint32_t freq; /* Result pwm frequency */
+ uint32_t edges; /* Result pwm edges */
};
/****************************************************************************
@@ -99,6 +100,7 @@ static int stm32_start(struct cap_lowerhalf_s *lower);
static int stm32_stop(struct cap_lowerhalf_s *lower);
static int stm32_getduty(struct cap_lowerhalf_s *lower, uint8_t *duty);
static int stm32_getfreq(struct cap_lowerhalf_s *lower, uint32_t *freq);
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges);
/****************************************************************************
* Private Data
@@ -112,6 +114,7 @@ static const struct cap_ops_s g_cap_ops =
.stop = stm32_stop,
.getduty = stm32_getduty,
.getfreq = stm32_getfreq,
+ .getedges = stm32_getedges,
};
#ifdef CONFIG_STM32_TIM1_CAP
@@ -235,6 +238,8 @@ static int stm32_cap_handler(int irq, void * context, void
* arg)
lower->freq = 0;
}
+ lower->edges++;
+
return OK;
}
@@ -266,6 +271,8 @@ static int stm32_start(struct cap_lowerhalf_s *lower)
return -EBUSY;
}
+ priv->edges = 0;
+
switch (priv->channel)
{
case 1:
@@ -437,6 +444,35 @@ static int stm32_getfreq(struct cap_lowerhalf_s *lower,
uint32_t *freq)
return OK;
}
+/****************************************************************************
+ * Name: stm32_getedges
+ *
+ * Description:
+ * get result edges
+ *
+ * Input Parameters:
+ * lower - A pointer the publicly visible representation of the
+ * "lower-half" driver state structure.
+ * edges - Number of edges seen.
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges)
+{
+ struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
+
+ irqstate_t flags = enter_critical_section();
+
+ *edges = priv->edges;
+
+ leave_critical_section(flags);
+
+ return OK;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/arch/arm/src/stm32h7/stm32_capture_lowerhalf.c
b/arch/arm/src/stm32h7/stm32_capture_lowerhalf.c
index 79ee35e3022..8d0e5ad6549 100644
--- a/arch/arm/src/stm32h7/stm32_capture_lowerhalf.c
+++ b/arch/arm/src/stm32h7/stm32_capture_lowerhalf.c
@@ -96,6 +96,7 @@ struct stm32_lowerhalf_s
uint32_t clock; /* Timer clock frequency */
uint8_t duty; /* Result pwm frequency */
uint32_t freq; /* Result pwm frequency */
+ uint32_t edges; /* Result pwm edges */
};
/****************************************************************************
@@ -110,6 +111,7 @@ static int stm32_start(struct cap_lowerhalf_s *lower);
static int stm32_stop(struct cap_lowerhalf_s *lower);
static int stm32_getduty(struct cap_lowerhalf_s *lower, uint8_t *duty);
static int stm32_getfreq(struct cap_lowerhalf_s *lower, uint32_t *freq);
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges);
/****************************************************************************
* Private Data
@@ -123,6 +125,7 @@ static const struct cap_ops_s g_cap_ops =
.stop = stm32_stop,
.getduty = stm32_getduty,
.getfreq = stm32_getfreq,
+ .getedges = stm32_getedges,
};
#ifdef CONFIG_STM32_TIM1_CAP
@@ -285,6 +288,7 @@ static int stm32_cap_handler(int irq, void * context, void
* arg)
}
lower->freq = lower->clock / period;
+ lower->edges++;
return OK;
}
@@ -317,6 +321,8 @@ static int stm32_start(struct cap_lowerhalf_s *lower)
return -EBUSY;
}
+ priv->edges = 0;
+
switch (priv->channel)
{
case 1:
@@ -477,6 +483,35 @@ static int stm32_getfreq(struct cap_lowerhalf_s *lower,
uint32_t *freq)
return OK;
}
+/****************************************************************************
+ * Name: stm32_getedges
+ *
+ * Description:
+ * get result edges
+ *
+ * Input Parameters:
+ * lower - A pointer the publicly visible representation of the
+ * "lower-half" driver state structure.
+ * edges - Number of edges seen.
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int stm32_getedges(struct cap_lowerhalf_s *lower, uint32_t *edges)
+{
+ struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
+
+ irqstate_t flags = enter_critical_section();
+
+ *edges = priv->edges;
+
+ leave_critical_section(flags);
+
+ return OK;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/