TeensyHelpers icon indicating copy to clipboard operation
TeensyHelpers copied to clipboard

Installation with PlatformIO

Open ernestum opened this issue 4 years ago • 4 comments

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:

  • Putting the teensy_clock folder in the lib subfolder of my project
  • Putting the teensy_clock folder in the src subfolder of my project
  • Putting the teensy_clock files directly into the src subfolder of my project
  • All of the above variants with the .cppx file renamed to cpp

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 avatar Dec 08 '21 16:12 ernestum

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().

ernestum avatar Dec 08 '21 17:12 ernestum

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

luni64 avatar Dec 08 '21 17:12 luni64

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?

ernestum avatar Dec 09 '21 10:12 ernestum

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.

luni64 avatar Dec 09 '21 10:12 luni64