Skip to content

Commit cc616ae

Browse files
committed
m4 tc output works. Watch out for the PAC!
1 parent 0397202 commit cc616ae

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ bool start_mp(safe_mode_t safe_mode) {
153153
serial_write(MSG_DOUBLE_FILE_EXTENSION);
154154
}
155155
}
156+
157+
reset_port();
158+
reset_board();
159+
reset_mp();
156160
reset_status_led();
157161

158162
if (result.return_code & PYEXEC_FORCED_EXIT) {
@@ -314,9 +318,6 @@ int __attribute__((used)) main(void) {
314318
}
315319
first_run = false;
316320
skip_repl = start_mp(safe_mode);
317-
reset_port();
318-
reset_board();
319-
reset_mp();
320321
} else if (exit_code != 0) {
321322
break;
322323
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,16 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
330330
tc->COUNT16.CC[0].reg = top;
331331
#endif
332332
#ifdef SAMD51
333+
334+
tc->COUNT16.CTRLA.bit.SWRST = 1;
335+
while (tc->COUNT16.CTRLA.bit.SWRST == 1) {
336+
}
337+
tc_set_enable(tc, false);
333338
tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_PRESCALER(divisor);
334-
tc->COUNT16.CTRLBSET.bit.LUPD = true;
339+
//tc->COUNT16.CTRLBSET.bit.LUPD = true;
335340
tc->COUNT16.WAVE.reg = TC_WAVE_WAVEGEN_MPWM;
336341
tc->COUNT16.CCBUF[0].reg = top;
342+
tc->COUNT16.CCBUF[1].reg = top / 2;
337343
#endif
338344

339345
tc_set_enable(tc, true);
@@ -404,7 +410,10 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self,
404410
tc_insts[t->index]->COUNT16.CC[t->wave_output].reg = adjusted_duty;
405411
#endif
406412
#ifdef SAMD51
407-
tc_insts[t->index]->COUNT16.CCBUF[t->wave_output].reg = adjusted_duty;
413+
while (tc_insts[t->index]->COUNT16.SYNCBUSY.bit.CC1 != 0) {
414+
// Wait for a previous value to be written.
415+
}
416+
tc_insts[t->index]->COUNT16.CCBUF[1].reg = adjusted_duty;
408417
#endif
409418
} else {
410419
uint32_t adjusted_duty = ((uint64_t) tcc_periods[t->index]) * duty / 0xffff;

ports/atmel-samd/supervisor/port.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "common-hal/analogio/AnalogIn.h"
4747
#include "common-hal/analogio/AnalogOut.h"
4848
#include "common-hal/microcontroller/Pin.h"
49+
#include "common-hal/pulseio/PWMOut.h"
4950
#include "tick.h"
5051

5152
extern volatile bool mp_msc_enabled;
@@ -206,8 +207,8 @@ void reset_port(void) {
206207
// pdmin_reset();
207208
// pulsein_reset();
208209
// pulseout_reset();
209-
// pwmout_reset();
210210
// #endif
211+
pwmout_reset();
211212

212213
analogin_reset();
213214

0 commit comments

Comments
 (0)