Skip to content

Commit 736a63e

Browse files
committed
atmel-samd: Set up the tcc_instance when using an already active TCC.
This fixes a hard lock that happens when using a second channel on an in use TCC. The lock occurred when setting the duty cycle on the channel because the hw address was not available to ASF. Thanks to @ladyada for finding the bug.
1 parent 3658c92 commit 736a63e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

atmel-samd/common-hal/pulseio/PWMOut.c

+4
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,17 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
128128
channel_ok(&pin->primary_timer, primary_timer_index)) {
129129
t = &pin->primary_timer;
130130
index = primary_timer_index;
131+
self->tcc_instance.hw = t->tcc;
132+
self->tcc_instance.double_buffering_enabled = true;
131133
} else if (!variable_frequency &&
132134
secondary_timer_index != 0xff &&
133135
target_timer_frequencies[secondary_timer_index] == frequency &&
134136
pin->secondary_timer.tcc->CTRLA.bit.ENABLE == 1 &&
135137
channel_ok(&pin->secondary_timer, secondary_timer_index)) {
136138
t = &pin->secondary_timer;
137139
index = secondary_timer_index;
140+
self->tcc_instance.hw = t->tcc;
141+
self->tcc_instance.double_buffering_enabled = true;
138142
} else {
139143
// Pick an unused timer if available.
140144

0 commit comments

Comments
 (0)