Skip to content

STM32: Add never_reset reservation to RGBMatrix init #3441

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 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ports/stm/common-hal/rgbmatrix/RGBMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern void _PM_IRQ_HANDLER(void);
void *common_hal_rgbmatrix_timer_allocate() {
TIM_TypeDef * timer = stm_peripherals_find_timer();
stm_peripherals_timer_reserve(timer);
stm_peripherals_timer_never_reset(timer);
Copy link

Choose a reason for hiding this comment

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

with "never_reset", does stm_peripherals_timer_free in common_hal_rgbmatrix_timer_free() remain enough to fully deallocate/free/reset the timer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm sorry, can you rephrase? stm_peripherals_timer_free does undo never reset, is that your question? What do you mean by "remain"?

Copy link

Choose a reason for hiding this comment

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

CopyQ NkqthX

I'm still not fully familiar/comfortable with the transitions among these states; the naming is a bit different in each port and for each type of managed resource and I'm never entirely confident the semantics are the same. (As a larger issue, it wouldn't hurt to document this for developers reference and to ensure consistency)

My question is whether the state transtion from "timer is in never_reset state" to "timer is in free state" by calling "timer_free" is a correct transition. I think you answered yes.

Copy link
Collaborator Author

@hierophect hierophect Sep 20, 2020

Choose a reason for hiding this comment

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

Yes. I think the going concept here is that never_reset is actually a wholly separate option from reserved - it is possible to have an un-reserved pin that is not in never_reset. I suggested joining the two at one point, so that never_reset was strictly a subset of reserved, but I believe we decided against it (I don't fully remember the reason).

Conceptually, reserved is the idea that a pin/peripheral cannot be claimed twice within a single runtime. never_reset is the idea that resetting will not change the reserved status or the pin attributes of that pin/peripheral (basically, immunity status to the reset_all function). To turn off never_reset, you typically call the single-reset function (the not reset-all one) which completely resets all aspects of the pin/peripheral. We have some reset_ok functions which specifically turn off never_reset and nothing else, but they're rarely implemented and even more rarely used.

I'd definitely be down to document this or remove any inconsistencies that you have found. I think we could also revisit whether the two ideas should be combined more concretely in some way - basically, is there ever a scenario where you want something to be in never_reset without it actually being claimed?

return timer;
}

Expand Down
4 changes: 0 additions & 4 deletions ports/stm/peripherals/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ TIM_TypeDef * stm_peripherals_find_timer(void) {
// If no results are found, no unclaimed pins with this timer are in this package,
// and it is safe to pick
if (timer_in_package == false && mcu_tim_banks[i] != NULL) {
// DEBUG: print the timer
return mcu_tim_banks[i];
mp_printf(&mp_plat_print, "Timer: %d\n",i);
}
}
//TODO: secondary search for timers outside the pins in the board profile

// Work backwards - higher index timers have fewer pin allocations
for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i >= 0; i--) {
if ((!stm_timer_reserved[i]) && (mcu_tim_banks[i] != NULL)) {
// DEBUG: print the timer
mp_printf(&mp_plat_print, "Timer: %d\n",i);
return mcu_tim_banks[i];
}
}
Expand Down