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

Teensy 4.0 support? #9

Open
bk4nt opened this issue Aug 20, 2019 · 9 comments
Open

Teensy 4.0 support? #9

bk4nt opened this issue Aug 20, 2019 · 9 comments

Comments

@bk4nt
Copy link

bk4nt commented Aug 20, 2019

Hello,

I tried a quick and dirty mod to get things up with Teensy 4.0 but I didn't succeed so far.

Would it be difficult to support also Teensy 4.0 (which has its RAM splitted in two zones)?

Would it need adapations of ChRt-master\src\teensy3 files only?

Best regards

@greiman
Copy link
Owner

greiman commented Aug 20, 2019

Support for Teensy 4.0 requires mods to other files since it is a Cortex M7 processor. The mods are to files in various folders.

I am not sure when I will tackle Teensy 4.0 since I would start with the latest version of ChibiOS so I have the latest Cortex M7F support in CMSIS.

@greiman
Copy link
Owner

greiman commented Aug 21, 2019

I have been looking at the latest ChibiOS 19.3. It really looks good.

I wish I could port it in tickless mode to Arduino style boards. This allows better time resolution with no overhead unless you use a feature.

@bk4nt
Copy link
Author

bk4nt commented Aug 21, 2019

The point is the Arduino IDE, libs, and the accessibility. Other would say move away to another IDE and use ChibiOS source code, but that would mean much more difficulties to get things running on an Arduino or a Teensy (the Teensy 4.0 introducing nice new features, like digital audio).

Thanks for your efforts.

@greiman
Copy link
Owner

greiman commented Oct 3, 2019

Try the new release. It has Teensy 4.0 support with both periodic and tick-less modes.

http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:tickless

The Teensy 4.0 GPT timer exactly matches the requirement for tick-less mode. Most timer functions are a single line of code.

Here is the ChibiOS GPT2 functions. I couldn't believe how simple they are.

/**
 * @brief   Returns the time counter value.
 *
 * @return              The counter value.
 *
 * @notapi
 */
static inline systime_t st_lld_get_counter(void) {
  return (systime_t)GPT2_CNT;
}

/**
 * @brief   Starts the alarm.
 * @note    Makes sure that no spurious alarms are triggered after
 *          this call.
 *
 * @param[in] time      the time to be set for the first alarm
 *
 * @notapi
 */
static inline void st_lld_start_alarm(systime_t time) {
  GPT2_OCR1 = (uint32_t)time;
  GPT2_SR |= GPT_SR_OF1; 
  GPT2_IR = GPT_IR_OF1IE;
}

/**
 * @brief   Stops the alarm interrupt.
 *
 * @notapi
 */
static inline void st_lld_stop_alarm(void) {
  GPT2_IR = 0;
}

/**
 * @brief   Sets the alarm time.
 *
 * @param[in] time      the time to be set for the next alarm
 *
 * @notapi
 */
static inline void st_lld_set_alarm(systime_t time) {
  GPT2_OCR1 = (uint32_t)time;
}

/**
 * @brief   Returns the current alarm time.
 *
 * @return              The currently set alarm time.
 *
 * @notapi
 */
static inline systime_t st_lld_get_alarm(void) {
  return (systime_t)GPT2_OCR1;
}

/**
 * @brief   Determines if the alarm is active.
 *
 * @return              The alarm status.
 * @retval false        if the alarm is not active.
 * @retval true         is the alarm is active
 *
 * @notapi
 */
static inline bool st_lld_is_alarm_active(void) {
  return (GPT2_IR & GPT_SR_OF1) != 0;
}

@boikonur
Copy link

Hi @greiman It seems that latest Teensiduino doesn't work with your lib. I thought its because something in the GPT2 Timer configuration is now off. But I cant seem to make the periodic work as well.

@greiman
Copy link
Owner

greiman commented Aug 23, 2020

Looks like a conflict that causes a lockup. I will look at it more when I have time.

@greiman
Copy link
Owner

greiman commented Aug 24, 2020

Try the latest update. I think I found the problem.

Paul added a 32 byte protected region between bss and the stack. I fill the stack with 0X55 and the new region caused a memory protection fault.

I set stack low address to &_ebss + 32. Hope Paul doesn't change that since there is no symbol for stack low address.

The stack overflow region is a great idea, worth breaking ChRt.

@BoMadsen
Copy link

BoMadsen commented Sep 2, 2020

Firstly I tried the 1.2.0 from platformio, and I was unable to get it to work on the Teensy 4.1. But after I pulled the library directly from here, it worked like a charm. So it looks like the fix is working 👍

@Rainerino
Copy link

Rainerino commented Nov 11, 2020

I have tried the same thing as @BoMadsen suggested, and it fixed the problem. It seems that platformio build is not working, but direct pull from this repo works.

By the way, Thank you very much @greiman for this amazing library!

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

5 participants