Tuesday, January 17, 2017

Using the RTC date/alarm in KinetisK/FRDM-K64


This is (a wip) tutorial on enabling the RTC Alarms on the KinetisK FRDM-K64.

There are a couple of gottchas to look out for when using time related functions
1) is the system clock internal nuttx maintaned counter or syncs with hardware RTC
2) does the internal format use Julian or epoch time.
3) is the RTC format Julian/yymmddss time, or epoch time
The KinetisK has an internal RTC that is 32bits
(The STM32F4 versions have an internal RTC with yyyymmdd mmss)

The internal clock running off the processor xtal, won't be as accurate as the RTC clock.
However I haven't figured out away for checking which is operational from Nuttx cmd line.
I let it run for 12+hrs and then check the accuracy - if its off by a discernible amount then the chances are its running on the internal clock.
The difference between the internal clock and the RTC could provide some strange RTC alarm failures.

To be able to configure the FRDM-K64 (assuming you have a nuttx build environment) set it as per this previous blog configuring-nuttx-to-use-kinetisk-frdm-k64f.

I've developed this already on a private Nuttx build, and I'm submitting it back into Nuttx, using the FRDM-K64 as the basis for the build.

The K64 has one 32bit register and it needs the following enabled for
make menuconfig
date command
 Application Configuration -> NSH Library -> Disable Individual commands
[ ] Disable date
NSH_DISABLE_DATE=N

RTC support
System Type--> Kinetis Peripheral Support  & [*] RTC
CONFIG_KINETIS_RTC

Device Drivers-> Timer Driver Support-> [*] RTC Driver Support
 --- RTC Driver Support
  │ │    [*]   Date/Time RTC Support
  │ │    [*]     Hi-Res RTC Support
  │ │    (1)       Hi-Res RTC frequency (NEW)
  │ │    [*]   RTC Alarm Support
  │ │    (1)     Number of alarms (NEW)
  │ │    [*]   RTC Driver Support
  │ │    [*]     RTC IOCTLs
  │ │    [ ]   External RTC Support (NEW)

CONFIG_RTC_DATETIME
CONFIG_RTC_HIRES=y
CONFIG_RTC_FREQUENCY=1
CONFIG_RTC_ALARM=y
CONFIG_RTC_NALARMS=1
CONFIG_RTC_DRIVER=y
CONFIG_RTC_IOCTL=y


To be able to test
Application -> Examples-> RTC alarm driver example
 [*] RTC alarm driver example
  │ │    (100) Alarm task priority
  │ │    (2048) Alarm stack size
  │ │    (/dev/rtc0) RTC device path
  │ │    (1)   Alarm signal


plug in the FRDM-K64 after updates (as described at mbed), on the USB SDA to a host
On the computer connect to the serial port that comes up.
Compile and then take the nuttx.bin and drop it on the USB port

Some background,  about the Kinetis K devices and family,
I've put up a number of memory maps
groups.yahoo.com/neo/groups/nuttx/files/KinetisComparision/
The Kinetis K has two generations of chips, and a number of families.
The familes K20, K40 K60, K64 are feature descritption
the generations sometimes have enhancements to the feature descriptions
The K60P 100MHz is a generation1 device with base line RTC features
The K60P 120MHz is a generation2 device with RTC enhanced features.
The K66 is only a generation2 device

No comments:

Post a Comment