Skip to content

Update time to use SysTick #274

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

Merged
merged 2 commits into from
Sep 29, 2017
Merged

Update time to use SysTick #274

merged 2 commits into from
Sep 29, 2017

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Sep 20, 2017

This doesn't actually use ASF4 at all but enables it again. This depends on #258

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also some merge conflicts to fix.

// _gclk_enable_channel(TC5_GCLK_ID, GCLK_SOURCE_DFLL48M);

// timer_init(&ms_timer, TC5, _tc_get_timer());
SysTick->LOAD = ((CONF_CPU_FREQUENCY / 1000 - 1) << SysTick_LOAD_RELOAD_Pos);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a TODO to replace this eventually, or have this call a HAL routine that returns the frequency? Could call common_hal_mcu_processor_get_frequency().

uint64_t start_ms = ticks_ms;
while (us > 1000) {
while (ticks_ms == start_ms) {}
us -= fractional;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my Googling, SysTick units are dependent on clock frequency, right? The SysTick timer is decremented on each clock cycle. So for instance at 48MHz, one tick is 1sec/48e6. So are you mixing microsoeconds (us) with SysTicks units?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! You are right.

@tannewt
Copy link
Member Author

tannewt commented Sep 23, 2017

Thanks for the review! I'll get to this in a few days after Maker Faire craziness.

@tannewt tannewt force-pushed the update_time branch 3 times, most recently from 0a177fb to 9dd16ac Compare September 29, 2017 15:56
@tannewt
Copy link
Member Author

tannewt commented Sep 29, 2017

@dhalbert could you take another look at this today? Thanks!

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; just the one comment about using CMSIS.


// timer_init(&ms_timer, TC5, _tc_get_timer());
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000;
SysTick->LOAD = ((ticks_per_ms - 1) << SysTick_LOAD_RELOAD_Pos);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do SysTick_Config(ticks_per_ms) to replace lines 49-53.

I remembered what Dean told me about CMSIS and thought there might be a function to do this.

@tannewt
Copy link
Member Author

tannewt commented Sep 29, 2017

Ok, this is ready for review. I confirmed time.sleep works. I don't actually know what code calls delay.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@dhalbert dhalbert merged commit 211b44e into adafruit:master Sep 29, 2017
dhalbert pushed a commit that referenced this pull request Apr 11, 2020
The HID descriptor reported by circuitpython erroneously limited the
maximum keycode to 101, which prevented circuitpython from sending a
number of otherwise valid keycodes.

Closes #274
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

Successfully merging this pull request may close these issues.

2 participants