Skip to content

Commit 2bcc5c0

Browse files
committed
Fix advanced claimed pin/package timer search
1 parent 9c38f5d commit 2bcc5c0

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

ports/stm/common-hal/microcontroller/Pin.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
8989

9090
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
9191
never_reset_pins[pin_port] |= 1<<pin_number;
92+
// Make sure never reset pins are also always claimed
93+
claimed_pins[pin_port] |= 1<<pin_number;
9294
}
9395

9496
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {

ports/stm/peripherals/timers.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,30 @@ void timers_reset(void) {
9999

100100
TIM_TypeDef * stm_peripherals_find_timer(void) {
101101
// Check for timers on pins outside the package size
102-
// for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
103-
// bool timer_in_package = false;
104-
// // Find each timer instance on the given bank
105-
// for (size_t j = 0; j < MP_ARRAY_SIZE(mcu_tim_pin_list); j++) {
106-
// // If a pin is claimed, we skip it
107-
// if ( (mcu_tim_pin_list[j].tim_index == i)
108-
// && (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true) ) {
109-
// // Search whether any pins in the package array match it
110-
// for (size_t k = 0; k < mcu_pin_globals.map.alloc; k++) {
111-
// if ( (mcu_tim_pin_list[j].pin == (mcu_pin_obj_t*)(mcu_pin_globals.map.table[k].value)) ) {
112-
// timer_in_package = true;
113-
// }
114-
// }
115-
// }
116-
// }
117-
// // If no results are found, no unclaimed pins with this timer are in this package,
118-
// // and it is safe to pick
119-
// if (timer_in_package == false && mcu_tim_banks[i] != NULL) {
120-
// return mcu_tim_banks[i];
121-
// }
122-
// }
102+
for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
103+
bool timer_in_package = false;
104+
// Find each timer instance on the given bank
105+
for (size_t j = 0; j < MP_ARRAY_SIZE(mcu_tim_pin_list); j++) {
106+
// If a pin is claimed, we skip it
107+
if ( (mcu_tim_pin_list[j].tim_index == i + 1)
108+
&& (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true) ) {
109+
// Search whether any pins in the package array match it
110+
for (size_t k = 0; k < mcu_pin_globals.map.alloc; k++) {
111+
if ( (mcu_tim_pin_list[j].pin == (mcu_pin_obj_t*)(mcu_pin_globals.map.table[k].value)) ) {
112+
timer_in_package = true;
113+
}
114+
}
115+
}
116+
}
117+
// If no results are found, no unclaimed pins with this timer are in this package,
118+
// and it is safe to pick
119+
if (timer_in_package == false && mcu_tim_banks[i] != NULL) {
120+
return mcu_tim_banks[i];
121+
}
122+
}
123123

124124
// Work backwards - higher index timers have fewer pin allocations
125-
for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i>=0; i--) {
125+
for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i >= 0; i--) {
126126
if ((!stm_timer_reserved[i]) && (mcu_tim_banks[i] != NULL)) {
127127
return mcu_tim_banks[i];
128128
}

0 commit comments

Comments
 (0)