This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch releases/13.1
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f3cbacfd130ac58579e637982e71f24f4f8051da
Author: raiden00pl <[email protected]>
AuthorDate: Thu Sep 24 15:32:29 2026 +0200

    arm/nrf52,nrf53,nrf91: fix TIMER driver bugs
    
    - setcc/getcc accepted channel index equal to the channel count
    - init never marked the instance as in use
    - TIM_PRESCALER_MASK used the maximum value as the mask
    
    Assisted-by: Claude Code
    Signed-off-by: raiden00pl <[email protected]>
---
 arch/arm/src/nrf52/hardware/nrf52_tim.h | 2 +-
 arch/arm/src/nrf52/nrf52_tim.c          | 8 ++++++--
 arch/arm/src/nrf53/hardware/nrf53_tim.h | 2 +-
 arch/arm/src/nrf53/nrf53_tim.c          | 8 ++++++--
 arch/arm/src/nrf91/hardware/nrf91_tim.h | 2 +-
 arch/arm/src/nrf91/nrf91_tim.c          | 8 ++++++--
 6 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/arch/arm/src/nrf52/hardware/nrf52_tim.h 
b/arch/arm/src/nrf52/hardware/nrf52_tim.h
index 444f663de67..417ff1adf3a 100644
--- a/arch/arm/src/nrf52/hardware/nrf52_tim.h
+++ b/arch/arm/src/nrf52/hardware/nrf52_tim.h
@@ -103,6 +103,6 @@
 
 #define TIM_PRESCALER_SHIFT                (0)                        /* Bits 
0-3: Prescaler value */
 #define TIM_PRESCALER_MAX                  (9)
-#define TIM_PRESCALER_MASK                 (TIM_PRESCALER_MAX << 
TIM_PRESCALER_SHIFT)
+#define TIM_PRESCALER_MASK                 (0xf << TIM_PRESCALER_SHIFT)
 
 #endif /* __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_TIM_H */
diff --git a/arch/arm/src/nrf52/nrf52_tim.c b/arch/arm/src/nrf52/nrf52_tim.c
index 218472c84b1..eafdecf6fe0 100644
--- a/arch/arm/src/nrf52/nrf52_tim.c
+++ b/arch/arm/src/nrf52/nrf52_tim.c
@@ -488,7 +488,7 @@ static int nrf52_tim_setcc(struct nrf52_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -518,7 +518,7 @@ static int nrf52_tim_getcc(struct nrf52_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -832,6 +832,10 @@ struct nrf52_tim_dev_s *nrf52_tim_init(int timer)
 
       tim = NULL;
     }
+  else
+    {
+      tim->inuse = true;
+    }
 
 errout:
   return (struct nrf52_tim_dev_s *)tim;
diff --git a/arch/arm/src/nrf53/hardware/nrf53_tim.h 
b/arch/arm/src/nrf53/hardware/nrf53_tim.h
index 81bb240a910..17df9e2ad8a 100644
--- a/arch/arm/src/nrf53/hardware/nrf53_tim.h
+++ b/arch/arm/src/nrf53/hardware/nrf53_tim.h
@@ -106,7 +106,7 @@
 
 #define TIM_PRESCALER_SHIFT                (0)                        /* Bits 
0-3: Prescaler value */
 #define TIM_PRESCALER_MAX                  (9)
-#define TIM_PRESCALER_MASK                 (TIM_PRESCALER_MAX << 
TIM_PRESCALER_SHIFT)
+#define TIM_PRESCALER_MASK                 (0xf << TIM_PRESCALER_SHIFT)
 
 /* ONESHOT Register */
 
diff --git a/arch/arm/src/nrf53/nrf53_tim.c b/arch/arm/src/nrf53/nrf53_tim.c
index 129880454d9..45fd20ce124 100644
--- a/arch/arm/src/nrf53/nrf53_tim.c
+++ b/arch/arm/src/nrf53/nrf53_tim.c
@@ -488,7 +488,7 @@ static int nrf53_tim_setcc(struct nrf53_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -518,7 +518,7 @@ static int nrf53_tim_getcc(struct nrf53_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -832,6 +832,10 @@ struct nrf53_tim_dev_s *nrf53_tim_init(int timer)
 
       tim = NULL;
     }
+  else
+    {
+      tim->inuse = true;
+    }
 
 errout:
   return (struct nrf53_tim_dev_s *)tim;
diff --git a/arch/arm/src/nrf91/hardware/nrf91_tim.h 
b/arch/arm/src/nrf91/hardware/nrf91_tim.h
index 6cecc9f3b60..87fbf86f600 100644
--- a/arch/arm/src/nrf91/hardware/nrf91_tim.h
+++ b/arch/arm/src/nrf91/hardware/nrf91_tim.h
@@ -106,7 +106,7 @@
 
 #define TIM_PRESCALER_SHIFT                (0)                        /* Bits 
0-3: Prescaler value */
 #define TIM_PRESCALER_MAX                  (9)
-#define TIM_PRESCALER_MASK                 (TIM_PRESCALER_MAX << 
TIM_PRESCALER_SHIFT)
+#define TIM_PRESCALER_MASK                 (0xf << TIM_PRESCALER_SHIFT)
 
 /* ONESHOT Register */
 
diff --git a/arch/arm/src/nrf91/nrf91_tim.c b/arch/arm/src/nrf91/nrf91_tim.c
index 31e224568a6..91468f8d77d 100644
--- a/arch/arm/src/nrf91/nrf91_tim.c
+++ b/arch/arm/src/nrf91/nrf91_tim.c
@@ -488,7 +488,7 @@ static int nrf91_tim_setcc(struct nrf91_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -518,7 +518,7 @@ static int nrf91_tim_getcc(struct nrf91_tim_dev_s *dev, 
uint8_t i,
 
   /* Is the channel supported? */
 
-  if (i > tim->chan)
+  if (i >= tim->chan)
     {
       tmrerr("ERROR: unsupported TIMER channel %d\n", i);
       ret = -EINVAL;
@@ -832,6 +832,10 @@ struct nrf91_tim_dev_s *nrf91_tim_init(int timer)
 
       tim = NULL;
     }
+  else
+    {
+      tim->inuse = true;
+    }
 
 errout:
   return (struct nrf91_tim_dev_s *)tim;

Reply via email to