Skip to content

kinetis/pit: Update Kconfig, implement oneshot PIT#18853

Open
ghnotgood wants to merge 1 commit intoapache:masterfrom
ghnotgood:master
Open

kinetis/pit: Update Kconfig, implement oneshot PIT#18853
ghnotgood wants to merge 1 commit intoapache:masterfrom
ghnotgood:master

Conversation

@ghnotgood
Copy link
Copy Markdown
Contributor

Implementation of the Kinetis' Periodic Interrupt Timer (PIT). The lower half driver is oneshot.

Summary

Kinetis' PIT is not yet implemented. It is simpler than FlexTimer Module (FTM) but good enough for oneshot timer-like use cases.

This PR implements Kinetis' PIT using oneshot count-based API.

Please, note that I am not completely sure about the resolution parameter of the oneshot_initialize procedure. The frequency of the PIT depends on the BOARD_BUS_FREQ and timing does not work as expected when something different is used. I am probably missing something and I am happy to fix it when I understand it. Thank you.

Impact

Developers can

#if defined(CONFIG_ONESHOT)
#  if defined(CONFIG_KINETIS_PIT_CH0)
  struct oneshot_lowerhalf_s *oneshot0 = oneshot_initialize(0, 0);
  if (NULL == oneshot0)
    {
      syslog(LOG_ERR, "ERROR: PIT0 initialization failed");
    }
  else
    {
      ret = oneshot_register("/dev/pit0", oneshot0);
      if (OK != ret)
        {
          syslog(LOG_ERR, "ERROR: PIT0 register failed");
        }
    }
#  endif
#endif

and then use /dev/pit0 as oneshot timer.

Testing

With the changes to .config

CONFIG_KINETIS_PIT=y
CONFIG_KINETIS_PIT_CH0=y

CONFIG_ONESHOT=y
CONFIG_ONESHOT_COUNT=y

CONFIG_EXAMPLES_ONESHOT=y
CONFIG_EXAMPLES_ONESHOT_DEVNAME="/dev/pit0"

I have run started our board:

__start: Reset status: 00:00
oneshot_register: devname=/dev/pit0 lower=0x1fff0564

NuttShell (NSH) NuttX-12.13.0

and run the oneshot example:

vtk15> oneshot
Oponeshot_ioctl: cmd=5664 arg=1fffa354
ening /deoneshot_ioctl: cmd=5665 arg=1fffa35c
v/pit0
Maximum delay is 71582788
Starting oneshot timer with delay 2000000 microseconds
Waiting...
Finished
vtk15> 

The delay between Waiting... and Finished was approximately 2 seconds.

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels May 6, 2026
linguini1
linguini1 previously approved these changes May 6, 2026
Copy link
Copy Markdown
Contributor

@linguini1 linguini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well written and good test info! I would probably add your caveat about the bus speed to the RST docs for this chip.

Comment thread arch/arm/src/kinetis/kinetis_oneshot_pit.c Outdated
@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 6, 2026

Sorry @ghnotgood: CI Check failed because of esp32p4-function-ev-board:ethernet, it will be fixed soon thanks :-)
apache/nuttx-apps#3405 (comment)

Configuration/Tool: esp32p4-function-ev-board/ethernet
  [1/1] Normalize esp32p4-function-ev-board/ethernet
55d54
< CONFIG_NSH_ARCHINIT=y

@ghnotgood
Copy link
Copy Markdown
Contributor Author

I would probably add your caveat about the bus speed to the RST docs for this chip.

You mean Documentation/platforms/arm/kinetis/index.rst? The information about unused resolution parameter feels too specific for this file to me. However, I kept the information in the comment of the oneshot_initialize procedure.

xiaoxiang781216
xiaoxiang781216 previously approved these changes May 6, 2026
@xiaoxiang781216
Copy link
Copy Markdown
Contributor

@ghnotgood please fix:

Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:1:78: error: Block comments have different lengths
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:21:77: error: Block comments have different lengths
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:35:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:37:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:38:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:40:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:41:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:43:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:44:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:46:1: warning: #include outside of 'Included Files' section
/home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:59: implementaiton ==> implementation

Implementation of the Kinetis' Periodic Interrupt Timer (PIT). The lower
half driver is oneshot.

Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
@ghnotgood
Copy link
Copy Markdown
Contributor Author

@ghnotgood please fix:

Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:1:78: error: Block comments have different lengths
Error: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:21:77: error: Block comments have different lengths
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:35:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:37:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:38:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:40:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:41:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:43:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:44:1: warning: #include outside of 'Included Files' section
Warning: /home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:46:1: warning: #include outside of 'Included Files' section
/home/runner/work/nuttx/nuttx/nuttx/arch/arm/src/kinetis/kinetis_oneshot_pit.c:59: implementaiton ==> implementation

I have added Included Files section and fixed typo. Thanks.

I have a question about the Block comments have different lengths error, though. It looks like that the last line of the block comment check in block_comment_width procedure excludes the leading space, which forces the first line of the block comment to be aligned to 77, not 78 (missing last *).

I think this should be fixed with

$ git diff
diff --git i/tools/nxstyle.c w/tools/nxstyle.c
index d464dc3fb0..e6196b8892 100644
--- i/tools/nxstyle.c
+++ w/tools/nxstyle.c
@@ -1050,7 +1050,7 @@ static int block_comment_width(char *line)
     {
       /* Return the length of the line up to the final '*' */
 
-      return e;
+      return e + b;
     }
 
   /* But there is also a special single line comment that begins with "[slash]* "

How should I proceed?

@linguini1
Copy link
Copy Markdown
Contributor

I would probably add your caveat about the bus speed to the RST docs for this chip.

You mean Documentation/platforms/arm/kinetis/index.rst? The information about unused resolution parameter feels too specific for this file to me. However, I kept the information in the comment of the oneshot_initialize procedure.

Good alternative! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants