Skip to content

Commit c7af175

Browse files
committed
m4 pulseout works
1 parent 6a7d889 commit c7af175

6 files changed

Lines changed: 49 additions & 12 deletions

File tree

main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ bool start_mp(safe_mode_t safe_mode) {
146146
const char *supported_filenames[] = STRING_LIST("code.txt", "code.py", "main.py", "main.txt");
147147
const char *double_extension_filenames[] = STRING_LIST("code.txt.py", "code.py.txt", "code.txt.txt","code.py.py",
148148
"main.txt.py", "main.py.txt", "main.txt.txt","main.py.py");
149+
reset_mp();
149150
found_main = maybe_run_list(supported_filenames, &result);
150151
if (!found_main){
151152
found_main = maybe_run_list(double_extension_filenames, &result);
@@ -156,7 +157,6 @@ bool start_mp(safe_mode_t safe_mode) {
156157

157158
reset_port();
158159
reset_board();
159-
reset_mp();
160160
reset_status_led();
161161

162162
if (result.return_code & PYEXEC_FORCED_EXIT) {
@@ -300,6 +300,7 @@ int __attribute__((used)) main(void) {
300300
bool first_run = true;
301301
for (;;) {
302302
if (!skip_repl) {
303+
reset_mp();
303304
autoreload_suspend();
304305
new_status_color(REPL_RUNNING);
305306
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
@@ -310,7 +311,6 @@ int __attribute__((used)) main(void) {
310311
autoreload_resume();
311312
reset_port();
312313
reset_board();
313-
reset_mp();
314314
}
315315
if (exit_code == PYEXEC_FORCED_EXIT) {
316316
if (!first_run) {

ports/atmel-samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ endif
9595
ifeq ($(DEBUG), 1)
9696
# Turn on Python modules useful for debugging (e.g. uheap, ustack).
9797
CFLAGS += -ggdb
98-
CFLAGS += -flto
98+
#CFLAGS += -flto
9999
ifeq ($(CHIP_FAMILY), samd21)
100100
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
101101
endif

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self,
293293
#ifdef SAMD51
294294
Tc* tc = tc_insts[t->index];
295295
while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {
296-
// Wait for a previous value to be written.
296+
// Wait for a previous value to be written. This can wait up to one period so we do
297+
// other stuff in the meantime.
298+
#ifdef MICROPY_VM_HOOK_LOOP
299+
MICROPY_VM_HOOK_LOOP
300+
#endif
297301
}
298302
tc->COUNT16.CCBUF[1].reg = adjusted_duty;
299303
#endif
@@ -302,7 +306,11 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self,
302306
uint8_t channel = tcc_channel(t);
303307
Tcc* tcc = tcc_insts[t->index];
304308
while ((tcc->SYNCBUSY.vec.CC & (1 << channel)) != 0) {
305-
// Wait for a previous value to be written.
309+
// Wait for a previous value to be written. This can wait up to one period so we do
310+
// other stuff in the meantime.
311+
#ifdef MICROPY_VM_HOOK_LOOP
312+
MICROPY_VM_HOOK_LOOP
313+
#endif
306314
}
307315
#ifdef SAMD21
308316
tcc->CCB[channel].reg = adjusted_duty;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu
185185
Tc* tc = tc_insts[pulseout_tc_index];
186186
tc->COUNT16.CC[0].reg = current_compare;
187187

188+
// Clear our interrupt in case it was set earlier
189+
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
188190
tc->COUNT16.INTENSET.reg = TC_INTENSET_MC0;
189191
tc_enable_interrupts(pulseout_tc_index);
190192
turn_on(active_pincfg);

ports/atmel-samd/timers.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include "hpl/gclk/hpl_gclk_base.h"
3636
#endif
3737

38+
#ifdef SAMD51
39+
#include "hri/hri_gclk_d51.h"
40+
#endif
41+
3842
// This bitmask keeps track of which channels of a TCC are currently claimed.
3943
#ifdef SAMD21
4044
const uint8_t tcc_cc_num[3] = {4, 2, 2};
@@ -51,7 +55,7 @@ const uint8_t tc_gclk_ids[TC_INST_NUM] = {TC3_GCLK_ID,
5155
const uint8_t tcc_gclk_ids[3] = {TCC0_GCLK_ID, TCC1_GCLK_ID, TCC2_GCLK_ID};
5256
#endif
5357
#ifdef SAMD51
54-
static const uint8_t tcc_cc_num[5] = {6, 4, 3, 2, 2};
58+
const uint8_t tcc_cc_num[5] = {6, 4, 3, 2, 2};
5559
const uint8_t tc_gclk_ids[TC_INST_NUM] = {TC0_GCLK_ID,
5660
TC1_GCLK_ID,
5761
TC2_GCLK_ID,
@@ -228,6 +232,13 @@ void shared_timer_handler(bool is_tc, uint8_t index) {
228232
}
229233
}
230234

235+
#ifdef SAMD51
236+
#define TC_OFFSET 0
237+
#endif
238+
#ifdef SAMD21
239+
#define TC_OFFSET 0
240+
#endif
241+
231242
void TCC0_Handler(void) {
232243
shared_timer_handler(false, 0);
233244
}
@@ -237,22 +248,38 @@ void TCC1_Handler(void) {
237248
void TCC2_Handler(void) {
238249
shared_timer_handler(false, 2);
239250
}
240-
void TC3_Handler(void) {
251+
// TC0 - TC2 only exist on the SAMD51
252+
#ifdef TC0
253+
void TC0_Handler(void) {
241254
shared_timer_handler(true, 0);
242255
}
243-
void TC4_Handler(void) {
256+
#endif
257+
#ifdef TC1
258+
void TC1_Handler(void) {
244259
shared_timer_handler(true, 1);
245260
}
246-
void TC5_Handler(void) {
261+
#endif
262+
#ifdef TC2
263+
void TC2_Handler(void) {
247264
shared_timer_handler(true, 2);
248265
}
266+
#endif
267+
void TC3_Handler(void) {
268+
shared_timer_handler(true, 3 - TC_OFFSET);
269+
}
270+
void TC4_Handler(void) {
271+
shared_timer_handler(true, 4 - TC_OFFSET);
272+
}
273+
void TC5_Handler(void) {
274+
shared_timer_handler(true, 5 - TC_OFFSET);
275+
}
249276
#ifdef TC6
250277
void TC6_Handler(void) {
251-
shared_timer_handler(true, 3);
278+
shared_timer_handler(true, 6 - TC_OFFSET);
252279
}
253280
#endif
254281
#ifdef TC7
255282
void TC7_Handler(void) {
256-
shared_timer_handler(true, 4);
283+
shared_timer_handler(true, 7 - TC_OFFSET);
257284
}
258285
#endif

ports/atmel-samd/timers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const uint8_t tc_gclk_ids[TC_INST_NUM];
3434
const uint8_t tcc_gclk_ids[3];
3535
#endif
3636
#ifdef SAMD51
37-
static const uint8_t tcc_cc_num[5];
37+
const uint8_t tcc_cc_num[5];
3838
const uint8_t tc_gclk_ids[TC_INST_NUM];
3939
const uint8_t tcc_gclk_ids[5];
4040
#endif

0 commit comments

Comments
 (0)