Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation with PlatformIO #2

Open
ernestum opened this issue Dec 8, 2021 · 4 comments
Open

Installation with PlatformIO #2

ernestum opened this issue Dec 8, 2021 · 4 comments

Comments

@ernestum
Copy link

ernestum commented Dec 8, 2021

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
Copy link
Author

ernestum commented Dec 8, 2021

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
Copy link
Owner

luni64 commented Dec 8, 2021

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
Copy link
Author

ernestum commented Dec 9, 2021

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
Copy link
Owner

luni64 commented Dec 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants