Skip to content

Commit 2cb7039

Browse files
authored
Merge pull request adafruit#1184 from adafruit/pwmout-tcc-channel-claiming
PWMOut was not claming channels on shared TCCs
2 parents caa2328 + f289863 commit 2cb7039

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ before_script:
5353
sudo apt-get install -y python3 gcc-multilib pkg-config libffi-dev libffi-dev:i386 qemu-system
5454
5555
- ([[ -z "$TRAVIS_TEST" ]] || sudo apt-get install -y qemu-system)
56-
- ([[ -z "$TRAVIS_BOARD" ]] || (wget https://s3.amazonaws.com/adafruit-circuit-python/gcc-arm-embedded_7-2017q4-1~trusty3_amd64.deb && sudo dpkg -i gcc-arm-embedded*_amd64.deb))
57-
- ([[ $TRAVIS_TEST != "qemu" ]] || (wget https://s3.amazonaws.com/adafruit-circuit-python/gcc-arm-embedded_7-2017q4-1~trusty3_amd64.deb && sudo dpkg -i gcc-arm-embedded*_amd64.deb))
56+
- ([[ -z "$TRAVIS_BOARD" ]] || (wget https://s3.amazonaws.com/adafruit-circuit-python/gcc-arm-embedded_7-2018q2-1~trusty1_amd64.deb && sudo dpkg -i gcc-arm-embedded*_amd64.deb))
57+
- ([[ $TRAVIS_TEST != "qemu" ]] || (wget https://s3.amazonaws.com/adafruit-circuit-python/gcc-arm-embedded_7-2018q2-1~trusty1_amd64.deb && sudo dpkg -i gcc-arm-embedded*_amd64.deb))
5858

5959
# For teensy build
6060
- sudo apt-get install realpath

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
5151

5252
// This bitmask keeps track of which channels of a TCC are currently claimed.
5353
#ifdef SAMD21
54-
uint8_t tcc_channels[3] = {0xf0, 0xfc, 0xfc};
54+
uint8_t tcc_channels[3]; // Set by pwmout_reset() to {0xf0, 0xfc, 0xfc} initially.
5555
#endif
5656
#ifdef SAMD51
57-
uint8_t tcc_channels[5] = {0xc0, 0xf0, 0xf8, 0xfc, 0xfc};
57+
uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc, 0xfc} initially.
5858
#endif
5959

6060
void pwmout_reset(void) {
@@ -75,7 +75,7 @@ void pwmout_reset(void) {
7575
for (uint8_t j = 0; j < tcc_cc_num[i]; j++) {
7676
mask <<= 1;
7777
}
78-
tcc_channels[i] = 0xf0;
78+
tcc_channels[i] = mask;
7979
tccs[i]->CTRLA.bit.SWRST = 1;
8080
}
8181
Tc *tcs[TC_INST_NUM] = TC_INSTS;
@@ -122,7 +122,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
122122
// Figure out which timer we are using.
123123

124124
// First see if a tcc is already going with the frequency we want and our
125-
// channel is unused. tc's don't have neough channels to share.
125+
// channel is unused. tc's don't have enough channels to share.
126126
const pin_timer_t* timer = NULL;
127127
uint8_t mux_position = 0;
128128
if (!variable_frequency) {
@@ -139,6 +139,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
139139
if (tcc->CTRLA.bit.ENABLE == 1 && channel_ok(t)) {
140140
timer = t;
141141
mux_position = j;
142+
// Claim channel.
143+
tcc_channels[timer->index] |= (1 << tcc_channel(timer));
144+
142145
}
143146
}
144147
}

0 commit comments

Comments
 (0)