Skip to content

Commit d628d2a

Browse files
committed
atmel-samd working
1 parent a0721fc commit d628d2a

7 files changed

Lines changed: 349 additions & 23 deletions

File tree

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,263 @@ const mp_obj_type_t samd_clock_type = {
163163
.print = samd_clock_print,
164164
.locals_dict = (mp_obj_t)&samd_clock_locals_dict,
165165
};
166+
167+
#ifdef SAMD21
168+
169+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
170+
CLOCK_SOURCE(XOSC);
171+
CLOCK_SOURCE(GCLKIN);
172+
CLOCK_SOURCE(GCLKGEN1);
173+
CLOCK_SOURCE(OSCULP32K);
174+
#endif
175+
CLOCK_SOURCE(OSC32K);
176+
CLOCK_SOURCE(XOSC32K);
177+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
178+
CLOCK_SOURCE(OSC8M);
179+
CLOCK_SOURCE(DFLL48M);
180+
CLOCK_SOURCE(DPLL96M);
181+
182+
CLOCK_GCLK_(SYSCTRL, DFLL48);
183+
CLOCK_GCLK_(SYSCTRL, FDPLL);
184+
CLOCK_GCLK_(SYSCTRL, FDPLL32K);
185+
CLOCK_GCLK(WDT);
186+
#endif
187+
CLOCK_GCLK(RTC);
188+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
189+
CLOCK_GCLK(EIC);
190+
CLOCK_GCLK(USB);
191+
CLOCK_GCLK_(EVSYS, 0);
192+
CLOCK_GCLK_(EVSYS, 1);
193+
CLOCK_GCLK_(EVSYS, 2);
194+
CLOCK_GCLK_(EVSYS, 3);
195+
CLOCK_GCLK_(EVSYS, 4);
196+
CLOCK_GCLK_(EVSYS, 5);
197+
CLOCK_GCLK_(EVSYS, 6);
198+
CLOCK_GCLK_(EVSYS, 7);
199+
CLOCK_GCLK_(EVSYS, 8);
200+
CLOCK_GCLK_(EVSYS, 9);
201+
CLOCK_GCLK_(EVSYS, 10);
202+
CLOCK_GCLK_(EVSYS, 11);
203+
CLOCK(SERCOMx_SLOW, 1, 19);
204+
CLOCK_GCLK_(SERCOM0, CORE);
205+
CLOCK_GCLK_(SERCOM1, CORE);
206+
CLOCK_GCLK_(SERCOM2, CORE);
207+
CLOCK_GCLK_(SERCOM3, CORE);
208+
CLOCK_GCLK_(SERCOM4, CORE);
209+
CLOCK_GCLK_(SERCOM5, CORE);
210+
CLOCK(TCC0_TCC1, 1, 26);
211+
CLOCK(TCC2_TCC3, 1, 27);
212+
CLOCK(TC4_TC5, 1, 28);
213+
CLOCK(TC6_TC7, 1, 29);
214+
CLOCK_GCLK(ADC);
215+
CLOCK_GCLK_(AC, DIG);
216+
CLOCK_GCLK_(AC, ANA);
217+
CLOCK_GCLK(DAC);
218+
CLOCK_GCLK(PTC);
219+
CLOCK_GCLK_(I2S, 0);
220+
CLOCK_GCLK_(I2S, 1);
221+
222+
CLOCK(SYSTICK, 2, 0);
223+
#endif
224+
225+
STATIC const mp_rom_map_elem_t samd_clock_global_dict_table[] = {
226+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
227+
CLOCK_ENTRY(XOSC),
228+
CLOCK_ENTRY(GCLKIN),
229+
CLOCK_ENTRY(GCLKGEN1),
230+
CLOCK_ENTRY(OSCULP32K),
231+
#endif
232+
CLOCK_ENTRY(OSC32K),
233+
CLOCK_ENTRY(XOSC32K),
234+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
235+
CLOCK_ENTRY(OSC8M),
236+
CLOCK_ENTRY(DFLL48M),
237+
CLOCK_ENTRY(DPLL96M),
238+
CLOCK_ENTRY_(SYSCTRL, DFLL48),
239+
CLOCK_ENTRY_(SYSCTRL, FDPLL),
240+
CLOCK_ENTRY_(SYSCTRL, FDPLL32K),
241+
CLOCK_ENTRY(WDT),
242+
#endif
243+
CLOCK_ENTRY(RTC),
244+
#ifdef SAMD21_EXPOSE_ALL_CLOCKS
245+
CLOCK_ENTRY(EIC),
246+
CLOCK_ENTRY(USB),
247+
CLOCK_ENTRY_(EVSYS, 0),
248+
CLOCK_ENTRY_(EVSYS, 1),
249+
CLOCK_ENTRY_(EVSYS, 2),
250+
CLOCK_ENTRY_(EVSYS, 3),
251+
CLOCK_ENTRY_(EVSYS, 4),
252+
CLOCK_ENTRY_(EVSYS, 5),
253+
CLOCK_ENTRY_(EVSYS, 6),
254+
CLOCK_ENTRY_(EVSYS, 7),
255+
CLOCK_ENTRY_(EVSYS, 8),
256+
CLOCK_ENTRY_(EVSYS, 9),
257+
CLOCK_ENTRY_(EVSYS, 10),
258+
CLOCK_ENTRY_(EVSYS, 11),
259+
CLOCK_ENTRY(SERCOMx_SLOW),
260+
CLOCK_ENTRY_(SERCOM0, CORE),
261+
CLOCK_ENTRY_(SERCOM1, CORE),
262+
CLOCK_ENTRY_(SERCOM2, CORE),
263+
CLOCK_ENTRY_(SERCOM3, CORE),
264+
CLOCK_ENTRY_(SERCOM4, CORE),
265+
CLOCK_ENTRY_(SERCOM5, CORE),
266+
CLOCK_ENTRY(TCC0_TCC1),
267+
CLOCK_ENTRY(TCC2_TCC3),
268+
CLOCK_ENTRY(TC4_TC5),
269+
CLOCK_ENTRY(TC6_TC7),
270+
CLOCK_ENTRY(ADC),
271+
CLOCK_ENTRY_(AC, DIG),
272+
CLOCK_ENTRY_(AC, ANA),
273+
CLOCK_ENTRY(DAC),
274+
CLOCK_ENTRY(PTC),
275+
CLOCK_ENTRY_(I2S, 0),
276+
CLOCK_ENTRY_(I2S, 1),
277+
278+
CLOCK_ENTRY(SYSTICK),
279+
#endif
280+
};
281+
MP_DEFINE_CONST_DICT(samd_clock_globals, samd_clock_global_dict_table);
282+
283+
#endif // SAMD21
284+
285+
#ifdef SAMD51
286+
287+
288+
289+
#include <instance/can0.h>
290+
#include <instance/can1.h>
291+
#include <instance/i2s.h>
292+
#include <instance/sdhc1.h>
293+
#include <instance/sercom6.h>
294+
#include <instance/sercom7.h>
295+
#include <instance/tcc4.h>
296+
297+
CLOCK_SOURCE(XOSC0);
298+
CLOCK_SOURCE(XOSC1);
299+
CLOCK_SOURCE(GCLKIN);
300+
CLOCK_SOURCE(GCLKGEN1);
301+
CLOCK_SOURCE(OSCULP32K);
302+
CLOCK_SOURCE(XOSC32K);
303+
CLOCK_SOURCE(DFLL);
304+
CLOCK_SOURCE(DPLL0);
305+
CLOCK_SOURCE(DPLL1);
306+
307+
CLOCK_GCLK_(OSCCTRL, DFLL48);
308+
CLOCK_GCLK_(OSCCTRL, FDPLL0);
309+
CLOCK_GCLK_(OSCCTRL, FDPLL1);
310+
CLOCK_GCLK_(OSCCTRL, FDPLL032K); // GCLK_OSCCTRL_FDPLL1_32K, GCLK_SDHC0_SLOW, GCLK_SDHC1_SLOW, GCLK_SERCOM[0..7]_SLOW
311+
CLOCK_GCLK(EIC);
312+
CLOCK_GCLK_(FREQM, MSR);
313+
// 6: GCLK_FREQM_REF
314+
CLOCK_GCLK_(SERCOM0, CORE);
315+
CLOCK_GCLK_(SERCOM1, CORE);
316+
CLOCK(TC0_TC1, 1, 9);
317+
CLOCK_GCLK(USB);
318+
CLOCK_GCLK_(EVSYS, 0);
319+
CLOCK_GCLK_(EVSYS, 1);
320+
CLOCK_GCLK_(EVSYS, 2);
321+
CLOCK_GCLK_(EVSYS, 3);
322+
CLOCK_GCLK_(EVSYS, 4);
323+
CLOCK_GCLK_(EVSYS, 5);
324+
CLOCK_GCLK_(EVSYS, 6);
325+
CLOCK_GCLK_(EVSYS, 7);
326+
CLOCK_GCLK_(EVSYS, 8);
327+
CLOCK_GCLK_(EVSYS, 9);
328+
CLOCK_GCLK_(EVSYS, 10);
329+
CLOCK_GCLK_(EVSYS, 11);
330+
CLOCK_GCLK_(SERCOM2, CORE);
331+
CLOCK_GCLK_(SERCOM3, CORE);
332+
CLOCK(TCC0_TCC1, 1, 25);
333+
CLOCK(TC2_TC3, 1, 26);
334+
CLOCK_GCLK(CAN0);
335+
CLOCK_GCLK(CAN1);
336+
CLOCK(TCC2_TCC3, 1, 29);
337+
CLOCK(TC4_TC5, 1, 30);
338+
// CLOCK_GCLK(PDEC);
339+
// CLOCK_GCLK(AC);
340+
// CLOCK_GCLK(CCL);
341+
CLOCK_GCLK_(SERCOM4, CORE);
342+
CLOCK_GCLK_(SERCOM5, CORE);
343+
CLOCK_GCLK_(SERCOM6, CORE);
344+
CLOCK_GCLK_(SERCOM7, CORE);
345+
CLOCK_GCLK(TCC4);
346+
CLOCK(TC6_TC7, 1, 39);
347+
CLOCK_GCLK(ADC0);
348+
CLOCK_GCLK(ADC1);
349+
CLOCK_GCLK(DAC);
350+
CLOCK_GCLK_(I2S, 0);
351+
CLOCK_GCLK_(I2S, 1);
352+
// CLOCK_GCLK(SDHC0);
353+
// CLOCK_GCLK(SDHC1);
354+
// 47: GCLK_CM4_TRACE
355+
356+
CLOCK(SYSTICK, 2, 0);
357+
CLOCK(CPU, 2, 1);
358+
CLOCK(RTC, 2, 2);
359+
360+
361+
STATIC const mp_rom_map_elem_t samd_clock_global_dict_table[] = {
362+
CLOCK_ENTRY(XOSC0),
363+
CLOCK_ENTRY(XOSC1),
364+
CLOCK_ENTRY(GCLKIN),
365+
CLOCK_ENTRY(GCLKGEN1),
366+
CLOCK_ENTRY(OSCULP32K),
367+
CLOCK_ENTRY(XOSC32K),
368+
CLOCK_ENTRY(DFLL),
369+
CLOCK_ENTRY(DPLL0),
370+
CLOCK_ENTRY(DPLL1),
371+
372+
CLOCK_ENTRY_(OSCCTRL, DFLL48),
373+
CLOCK_ENTRY_(OSCCTRL, FDPLL0),
374+
CLOCK_ENTRY_(OSCCTRL, FDPLL1),
375+
CLOCK_ENTRY_(OSCCTRL, FDPLL032K),
376+
CLOCK_ENTRY(EIC),
377+
CLOCK_ENTRY_(FREQM, MSR),
378+
CLOCK_ENTRY_(SERCOM0, CORE),
379+
CLOCK_ENTRY_(SERCOM1, CORE),
380+
CLOCK_ENTRY(TC0_TC1),
381+
CLOCK_ENTRY(USB),
382+
CLOCK_ENTRY_(EVSYS, 0),
383+
CLOCK_ENTRY_(EVSYS, 1),
384+
CLOCK_ENTRY_(EVSYS, 2),
385+
CLOCK_ENTRY_(EVSYS, 3),
386+
CLOCK_ENTRY_(EVSYS, 4),
387+
CLOCK_ENTRY_(EVSYS, 5),
388+
CLOCK_ENTRY_(EVSYS, 6),
389+
CLOCK_ENTRY_(EVSYS, 7),
390+
CLOCK_ENTRY_(EVSYS, 8),
391+
CLOCK_ENTRY_(EVSYS, 9),
392+
CLOCK_ENTRY_(EVSYS, 10),
393+
CLOCK_ENTRY_(EVSYS, 11),
394+
CLOCK_ENTRY_(SERCOM2, CORE),
395+
CLOCK_ENTRY_(SERCOM3, CORE),
396+
CLOCK_ENTRY(TCC0_TCC1),
397+
CLOCK_ENTRY(TC2_TC3),
398+
CLOCK_ENTRY(CAN0),
399+
CLOCK_ENTRY(CAN1),
400+
CLOCK_ENTRY(TCC2_TCC3),
401+
CLOCK_ENTRY(TC4_TC5),
402+
// CLOCK_ENTRY(PDEC),
403+
// CLOCK_ENTRY(AC),
404+
// CLOCK_ENTRY(CCL),
405+
CLOCK_ENTRY_(SERCOM4, CORE),
406+
CLOCK_ENTRY_(SERCOM5, CORE),
407+
CLOCK_ENTRY_(SERCOM6, CORE),
408+
CLOCK_ENTRY_(SERCOM7, CORE),
409+
CLOCK_ENTRY(TCC4),
410+
CLOCK_ENTRY(TC6_TC7),
411+
CLOCK_ENTRY(ADC0),
412+
CLOCK_ENTRY(ADC1),
413+
CLOCK_ENTRY(DAC),
414+
CLOCK_ENTRY_(I2S, 0),
415+
CLOCK_ENTRY_(I2S, 1),
416+
// CLOCK_ENTRY(SDHC0),
417+
// CLOCK_ENTRY(SDHC1),
418+
419+
CLOCK_ENTRY(SYSTICK),
420+
CLOCK_ENTRY(CPU),
421+
CLOCK_ENTRY(RTC),
422+
};
423+
MP_DEFINE_CONST_DICT(samd_clock_globals, samd_clock_global_dict_table);
424+
425+
#endif // SAMD51

ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void frequencyin_samd51_start_dpll() {
213213
// Will also enable the Lock Bypass due to low-frequency sources causing DPLL unlocks
214214
// as outlined in the Errata (1.12.1)
215215
OSCCTRL->Dpll[1].DPLLRATIO.reg = OSCCTRL_DPLLRATIO_LDRFRAC(0) | OSCCTRL_DPLLRATIO_LDR(2999);
216-
if (board_has_crystal()) { // we can use XOSC32K directly as the source
216+
if (BOARD_HAS_CRYSTAL) { // we can use XOSC32K directly as the source
217217
OSC32KCTRL->XOSC32K.bit.EN32K = 1;
218218
OSCCTRL->Dpll[1].DPLLCTRLB.reg = OSCCTRL_DPLLCTRLB_REFCLK(1) |
219219
OSCCTRL_DPLLCTRLB_LBYPASS;

ports/atmel-samd/mpconfigport.h

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,16 @@
3030
// Definitions for which SAMD chip we're using.
3131
#include "include/sam.h"
3232

33+
34+
////////////////////////////////////////////////////////////////////////////////////////////////////
35+
#ifdef SAMD21
36+
3337
#if INTERNAL_FLASH_FILESYSTEM
3438
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64*1024)
3539
#else
3640
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
3741
#endif
3842

39-
#ifndef CALIBRATE_CRYSTALLESS
40-
#define CALIBRATE_CRYSTALLESS (0)
41-
#endif
42-
43-
// if CALIBRATE_CRYSTALLESS is requested, make room for storing
44-
// calibration data generated from external USB.
45-
#ifndef CIRCUITPY_INTERNAL_CONFIG_SIZE
46-
#if CALIBRATE_CRYSTALLESS
47-
#define CIRCUITPY_INTERNAL_CONFIG_SIZE (256)
48-
#else
49-
#define CIRCUITPY_INTERNAL_CONFIG_SIZE (0)
50-
#endif
51-
#endif
52-
53-
#ifdef SAMD21
54-
5543
// HMCRAMC0_SIZE is defined in the ASF4 include files for each SAMD21 chip.
5644
#define RAM_SIZE HMCRAMC0_SIZE
5745
#define BOOTLOADER_SIZE (8*1024)
@@ -84,6 +72,8 @@
8472

8573
#endif // SAMD21
8674

75+
////////////////////////////////////////////////////////////////////////////////////////////////////
76+
8777
#ifdef SAMD51
8878

8979
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
@@ -110,13 +100,37 @@
110100
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
111101
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
112102
#define MICROPY_PY_FUNCTION_ATTRS (1)
103+
// MICROPY_PY_UJSON depends on MICROPY_PY_IO
113104
#define MICROPY_PY_IO (1)
114105
#define MICROPY_PY_UJSON (1)
115106
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
116107
// MICROPY_PY_UERRNO_LIST - Use the default
117108

118109
#endif // SAMD51
119110

111+
////////////////////////////////////////////////////////////////////////////////////////////////////
112+
113+
// This also includes mpconfigboard.h.
114+
#include "py/circuitpy_mpconfig.h"
115+
116+
#ifndef CALIBRATE_CRYSTALLESS
117+
#define CALIBRATE_CRYSTALLESS (0)
118+
#endif
119+
120+
#ifndef BOARD_HAS_CRYSTAL
121+
#define BOARD_HAS_CRYSTAL (0)
122+
#endif
123+
124+
// if CALIBRATE_CRYSTALLESS is requested, make room for storing
125+
// calibration data generated from external USB.
126+
#ifndef CIRCUITPY_INTERNAL_CONFIG_SIZE
127+
#if CALIBRATE_CRYSTALLESS
128+
#define CIRCUITPY_INTERNAL_CONFIG_SIZE (NVMCTRL_ROW_SIZE) // 256
129+
#else
130+
#define CIRCUITPY_INTERNAL_CONFIG_SIZE (0)
131+
#endif
132+
#endif
133+
120134
// Flash layout, starting at 0x00000000
121135
//
122136
// bootloader (8 or 16kB)
@@ -155,8 +169,6 @@
155169

156170
#include "peripherals/samd/dma.h"
157171

158-
#include "py/circuitpy_mpconfig.h"
159-
160172
#define MICROPY_PORT_ROOT_POINTERS \
161173
CIRCUITPY_COMMON_ROOT_POINTERS \
162174
mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT];

0 commit comments

Comments
 (0)