luni64 / TeensyHelpers

A couple of utility functions and classes to improve usage of the Teensy IntervalTimer class, the attachInterrupt and the pinMode function.
MIT License
19 stars 0 forks source link

Installation with PlatformIO #2

Open ernestum opened 2 years ago

ernestum commented 2 years ago

Hi, thanks for this nice helper library! I wanted to use teensy_clock in my PlatformIO project with a Teensy 3.1. Unfortunately it was unclear how to properly incorporate the library in my source code. What I tried so far:

I always get an error at link time:

.pio/build/teensy31/src/main.cpp.o: In function `L_214_delayMicroseconds':
main.cpp:(.text._Z20perform_needed_stepshR7StepperS0_S0_S0_+0x28): undefined reference to `cycles64::get()'
collect2: error: ld returned 1 exit status
*** [.pio/build/teensy31/firmware.elf] Error 1

(it is a different error when I rename the .cppx file)

Do you have any hints for me?

ernestum commented 2 years ago

The issue seems to be, that the code was written for the Teensy 4.0/4.1. When I remove all references to the snvs interrupt, I get it to compile with the following folder structure:

lib
├── cycle6s4
│   ├── cycle64s.cpp
│   └── cycles64.h
├── README
└── teensy_clock
    ├── teensy_clock.cpp
    └── teensy_clock.h

However, the time does not seem to advance after the initial sync to the RTC. For this to work we need to enable the cycle counter in the cycle64.cpp by adding

ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;

to the begin().

luni64 commented 2 years ago

Yes, this was done for the T4. For the T3.1 you need to enable the cycle counter as you have already found. Please also note, that if you disable the RTC interrupt you need to make sure that you call cycles64::get() at least once per overflow time of the cycle counter. For a T3.2 at 96MHz that would be at least every 2^32/96MHz = 44.7s. Placing a dummy cycles64::get() in loop() should be good enough.

Edit: Fixed the wrong cppx extension in the repo

ernestum commented 2 years ago

Thanks for the fix. When I include the teensy_clock code in my code in this way. Where would you want me to place the license file? One copy in each subfolder?

luni64 commented 2 years ago

Actually I don't care. Would be nice if you could place a link to the repo somewhere but event that is not necessary from my point of view.