From 736a63e85a331ebcfdbfe6210b1d39569fb330c9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 9 Jun 2017 17:16:33 -0700 Subject: [PATCH] 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. --- atmel-samd/common-hal/pulseio/PWMOut.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/atmel-samd/common-hal/pulseio/PWMOut.c b/atmel-samd/common-hal/pulseio/PWMOut.c index a98bf37ad0..336948a2e8 100644 --- a/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/atmel-samd/common-hal/pulseio/PWMOut.c @@ -128,6 +128,8 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, channel_ok(&pin->primary_timer, primary_timer_index)) { t = &pin->primary_timer; index = primary_timer_index; + self->tcc_instance.hw = t->tcc; + self->tcc_instance.double_buffering_enabled = true; } else if (!variable_frequency && secondary_timer_index != 0xff && target_timer_frequencies[secondary_timer_index] == frequency && @@ -135,6 +137,8 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, channel_ok(&pin->secondary_timer, secondary_timer_index)) { t = &pin->secondary_timer; index = secondary_timer_index; + self->tcc_instance.hw = t->tcc; + self->tcc_instance.double_buffering_enabled = true; } else { // Pick an unused timer if available.