summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-07-09 11:41:00 -0400
committerLucian Copeland <hierophect@gmail.com>2020-07-09 11:42:37 -0400
commit2bcc5c06c2efe5fb9469cab2f8f9aa801fbde14b (patch)
treebcfb8e2d5d724a222b1ed83a63c5ea074212119d
parent9c38f5dcb1a219faee7ecacfd9bf98a5f7771206 (diff)
Fix advanced claimed pin/package timer search
-rw-r--r--ports/stm/common-hal/microcontroller/Pin.c2
-rw-r--r--ports/stm/peripherals/timers.c44
2 files changed, 24 insertions, 22 deletions
diff --git a/ports/stm/common-hal/microcontroller/Pin.c b/ports/stm/common-hal/microcontroller/Pin.c
index 3e3fc0522..d919b07ea 100644
--- a/ports/stm/common-hal/microcontroller/Pin.c
+++ b/ports/stm/common-hal/microcontroller/Pin.c
@@ -89,6 +89,8 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
never_reset_pins[pin_port] |= 1<<pin_number;
+ // Make sure never reset pins are also always claimed
+ claimed_pins[pin_port] |= 1<<pin_number;
}
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c
index f28b36eec..589c28310 100644
--- a/ports/stm/peripherals/timers.c
+++ b/ports/stm/peripherals/timers.c
@@ -99,30 +99,30 @@ void timers_reset(void) {
TIM_TypeDef * stm_peripherals_find_timer(void) {
// Check for timers on pins outside the package size
- // for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
- // bool timer_in_package = false;
- // // Find each timer instance on the given bank
- // for (size_t j = 0; j < MP_ARRAY_SIZE(mcu_tim_pin_list); j++) {
- // // If a pin is claimed, we skip it
- // if ( (mcu_tim_pin_list[j].tim_index == i)
- // && (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true) ) {
- // // Search whether any pins in the package array match it
- // for (size_t k = 0; k < mcu_pin_globals.map.alloc; k++) {
- // if ( (mcu_tim_pin_list[j].pin == (mcu_pin_obj_t*)(mcu_pin_globals.map.table[k].value)) ) {
- // timer_in_package = true;
- // }
- // }
- // }
- // }
- // // 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) {
- // return mcu_tim_banks[i];
- // }
- // }
+ for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
+ bool timer_in_package = false;
+ // Find each timer instance on the given bank
+ for (size_t j = 0; j < MP_ARRAY_SIZE(mcu_tim_pin_list); j++) {
+ // If a pin is claimed, we skip it
+ if ( (mcu_tim_pin_list[j].tim_index == i + 1)
+ && (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true) ) {
+ // Search whether any pins in the package array match it
+ for (size_t k = 0; k < mcu_pin_globals.map.alloc; k++) {
+ if ( (mcu_tim_pin_list[j].pin == (mcu_pin_obj_t*)(mcu_pin_globals.map.table[k].value)) ) {
+ timer_in_package = true;
+ }
+ }
+ }
+ }
+ // 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) {
+ return mcu_tim_banks[i];
+ }
+ }
// Work backwards - higher index timers have fewer pin allocations
- for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i>=0; i--) {
+ for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i >= 0; i--) {
if ((!stm_timer_reserved[i]) && (mcu_tim_banks[i] != NULL)) {
return mcu_tim_banks[i];
}