Skip to content

Commit dc9cd60

Browse files
committed
atmel-samd: Introduce, use SAMx5FAM
This is the same as SAMD51 before, except in a few places where I had already added a special-case for SAME54
1 parent f3733bc commit dc9cd60

File tree

24 files changed

+146
-139
lines changed

24 files changed

+146
-139
lines changed

ports/atmel-samd/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ CFLAGS += \
158158
-mcpu=cortex-m4 \
159159
-mfloat-abi=hard \
160160
-mfpu=fpv4-sp-d16 \
161-
-DSAMD51
161+
-DSAMx5FAM -DSAMD51
162162
endif
163163
ifeq ($(CHIP_FAMILY), same54)
164164
CFLAGS += \
@@ -167,7 +167,7 @@ CFLAGS += \
167167
-mcpu=cortex-m4 \
168168
-mfloat-abi=hard \
169169
-mfpu=fpv4-sp-d16 \
170-
-DSAMD51 -DSAME54
170+
-DSAMx5FAM -DSAME54
171171
endif
172172

173173

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ MP_DEFINE_CONST_DICT(samd_clock_globals, samd_clock_global_dict_table);
272272

273273
#endif // SAMD21
274274

275-
#ifdef SAMD51
275+
#ifdef SAMx5FAM
276276

277277

278278

ports/atmel-samd/common-hal/_pew/PewPew.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void pew_init() {
8888
#ifdef SAMD21
8989
turn_on_clocks(true, index, 0);
9090
#endif
91-
#ifdef SAMD51
91+
#ifdef SAMx5FAM
9292
turn_on_clocks(true, index, 1);
9393
#endif
9494

@@ -98,7 +98,7 @@ void pew_init() {
9898
TC_CTRLA_PRESCALER_DIV64 |
9999
TC_CTRLA_WAVEGEN_MFRQ;
100100
#endif
101-
#ifdef SAMD51
101+
#ifdef SAMx5FAM
102102
tc_reset(tc);
103103
tc_set_enable(tc, false);
104104
tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16

ports/atmel-samd/common-hal/analogio/AnalogOut.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
5050
mp_raise_NotImplementedError(translate("No DAC on chip"));
5151
#else
5252
if (pin->number != PIN_PA02
53-
#ifdef SAMD51
53+
#ifdef SAMx5FAM
5454
&& pin->number != PIN_PA05
5555
#endif
5656
) {
@@ -59,13 +59,13 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
5959
}
6060

6161
self->channel = 0;
62-
#ifdef SAMD51
62+
#ifdef SAMx5FAM
6363
if (pin->number == PIN_PA05) {
6464
self->channel = 1;
6565
}
6666
#endif
6767

68-
#ifdef SAMD51
68+
#ifdef SAMx5FAM
6969
hri_mclk_set_APBDMASK_DAC_bit(MCLK);
7070
#endif
7171

@@ -80,16 +80,16 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
8080
// Don't double init the DAC on the SAMD51 when both outputs are in use. We use the free state
8181
// of each output pin to determine DAC state.
8282
int32_t result = ERR_NONE;
83-
#ifdef SAMD51
83+
#ifdef SAMx5FAM
8484
if (!common_hal_mcu_pin_is_free(&pin_PA02) || !common_hal_mcu_pin_is_free(&pin_PA05)) {
8585
#endif
8686
// Fake the descriptor if the DAC is already initialized.
8787
self->descriptor.device.hw = DAC;
88-
#ifdef SAMD51
88+
#ifdef SAMx5FAM
8989
} else {
9090
#endif
9191
result = dac_sync_init(&self->descriptor, DAC);
92-
#ifdef SAMD51
92+
#ifdef SAMx5FAM
9393
}
9494
#endif
9595
if (result != ERR_NONE) {
@@ -109,18 +109,18 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
109109
}
110110

111111
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
112-
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
112+
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMx5FAM)
113113
if (common_hal_analogio_analogout_deinited(self)) {
114114
return;
115115
}
116116
dac_sync_disable_channel(&self->descriptor, self->channel);
117117
reset_pin_number(PIN_PA02);
118118
// Only deinit the DAC on the SAMD51 if both outputs are free.
119-
#ifdef SAMD51
119+
#ifdef SAMx5FAM
120120
if (common_hal_mcu_pin_is_free(&pin_PA02) && common_hal_mcu_pin_is_free(&pin_PA05)) {
121121
#endif
122122
dac_sync_deinit(&self->descriptor);
123-
#ifdef SAMD51
123+
#ifdef SAMx5FAM
124124
}
125125
#endif
126126
self->deinited = true;
@@ -147,7 +147,7 @@ void analogout_reset(void) {
147147
#ifdef SAMD21
148148
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
149149
#endif
150-
#ifdef SAMD51
150+
#ifdef SAMx5FAM
151151
while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) {}
152152
#endif
153153
DAC->CTRLA.reg |= DAC_CTRLA_SWRST;

ports/atmel-samd/common-hal/audiobusio/I2SOut.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
#define SERCTRL(name) I2S_SERCTRL_ ## name
6060
#endif
6161

62-
#ifdef SAMD51
62+
#ifdef SAMx5FAM
6363
#define SERCTRL(name) I2S_TXCTRL_ ## name
6464
#endif
6565

6666
void i2sout_reset(void) {
6767
// Make sure the I2S peripheral is running so we can see if the resources we need are free.
68-
#ifdef SAMD51
68+
#ifdef SAMx5FAM
6969
// Connect the clock units to the 2mhz clock. It can't disable without it.
7070
connect_gclk_to_peripheral(5, I2S_GCLK_ID_0);
7171
connect_gclk_to_peripheral(5, I2S_GCLK_ID_1);
@@ -76,7 +76,7 @@ void i2sout_reset(void) {
7676
}
7777

7878
// Make sure the I2S peripheral is running so we can see if the resources we need are free.
79-
#ifdef SAMD51
79+
#ifdef SAMx5FAM
8080
// Connect the clock units to the 2mhz clock by default. They can't reset without it.
8181
disconnect_gclk_from_peripheral(5, I2S_GCLK_ID_0);
8282
disconnect_gclk_from_peripheral(5, I2S_GCLK_ID_1);
@@ -132,7 +132,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
132132
serializer = 1;
133133
}
134134
#endif
135-
#ifdef SAMD51
135+
#ifdef SAMx5FAM
136136
// Only clock unit 0 can be used for transmission.
137137
if (bit_clock == &pin_PA10 || bit_clock == &pin_PB16) { // I2S SCK[0]
138138
bc_clock_unit = 0;
@@ -170,14 +170,14 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
170170
mp_raise_RuntimeError(translate("Serializer in use"));
171171
}
172172
#endif
173-
#ifdef SAMD51
173+
#ifdef SAMx5FAM
174174
if (I2S->CTRLA.bit.TXEN == 1) {
175175
mp_raise_RuntimeError(translate("Serializer in use"));
176176
}
177177
#endif
178178
}
179179

180-
#ifdef SAMD51
180+
#ifdef SAMx5FAM
181181
#define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_J
182182
#endif
183183
#ifdef SAMD21
@@ -254,7 +254,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
254254
#ifdef SAMD21
255255
uint32_t serctrl = (self->clock_unit << I2S_SERCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_TX) | I2S_SERCTRL_TXSAME_SAME | I2S_SERCTRL_EXTEND_MSBIT | I2S_SERCTRL_TXDEFAULT_ONE | I2S_SERCTRL_SLOTADJ_LEFT;
256256
#endif
257-
#ifdef SAMD51
257+
#ifdef SAMx5FAM
258258
uint32_t serctrl = (self->clock_unit << I2S_RXCTRL_CLKSEL_Pos) | I2S_TXCTRL_TXSAME_SAME;
259259
#endif
260260
if (audiosample_channel_count(sample) == 1) {
@@ -277,7 +277,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
277277
#ifdef SAMD21
278278
I2S->SERCTRL[self->serializer].reg = serctrl;
279279
#endif
280-
#ifdef SAMD51
280+
#ifdef SAMx5FAM
281281
I2S->TXCTRL.reg = serctrl;
282282
#endif
283283

@@ -291,7 +291,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
291291
uint32_t tx_register = (uint32_t) &I2S->DATA[self->serializer].reg;
292292
uint8_t dmac_id = I2S_DMAC_ID_TX_0 + self->serializer;
293293
#endif
294-
#ifdef SAMD51
294+
#ifdef SAMx5FAM
295295
uint32_t tx_register = (uint32_t) &I2S->TXDATA.reg;
296296
uint8_t dmac_id = I2S_DMAC_ID_TX_0;
297297
#endif
@@ -316,7 +316,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
316316
I2S->CTRLA.vec.SEREN = 1 << self->serializer;
317317
while ((I2S->SYNCBUSY.vec.SEREN & (1 << self->serializer)) != 0) {}
318318
#endif
319-
#ifdef SAMD51
319+
#ifdef SAMx5FAM
320320
I2S->CTRLA.bit.TXEN = 1;
321321
while (I2S->SYNCBUSY.bit.TXEN == 1) {}
322322
#endif
@@ -333,7 +333,7 @@ void common_hal_audiobusio_i2sout_resume(audiobusio_i2sout_obj_t* self) {
333333
#ifdef SAMD21
334334
I2S->INTFLAG.reg = I2S_INTFLAG_TXUR0 << self->serializer;
335335
#endif
336-
#ifdef SAMD51
336+
#ifdef SAMx5FAM
337337
I2S->INTFLAG.reg = I2S_INTFLAG_TXUR0 | I2S_INTFLAG_TXUR1;
338338
#endif
339339

@@ -351,7 +351,7 @@ void common_hal_audiobusio_i2sout_stop(audiobusio_i2sout_obj_t* self) {
351351
I2S->CTRLA.vec.SEREN &= ~(1 << self->serializer);
352352
while ((I2S->SYNCBUSY.vec.SEREN & (1 << self->serializer)) != 0) {}
353353
#endif
354-
#ifdef SAMD51
354+
#ifdef SAMx5FAM
355355
I2S->CTRLA.bit.TXEN = 0;
356356
while (I2S->SYNCBUSY.bit.TXEN == 1) {}
357357
#endif
@@ -368,7 +368,7 @@ void common_hal_audiobusio_i2sout_stop(audiobusio_i2sout_obj_t* self) {
368368
disconnect_gclk_from_peripheral(self->gclk, I2S_GCLK_ID_0 + self->clock_unit);
369369
disable_clock_generator(self->gclk);
370370

371-
#ifdef SAMD51
371+
#ifdef SAMx5FAM
372372
connect_gclk_to_peripheral(5, I2S_GCLK_ID_0 + self->clock_unit);
373373
#endif
374374

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define SERCTRL(name) I2S_SERCTRL_ ## name
6161
#endif
6262

63-
#ifdef SAMD51
63+
#ifdef SAMx5FAM
6464
#define SERCTRL(name) I2S_RXCTRL_ ## name
6565
#endif
6666

@@ -94,7 +94,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
9494
self->clock_unit = 1;
9595
#endif
9696
#endif
97-
#ifdef SAMD51
97+
#ifdef SAMx5FAM
9898
if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) {
9999
self->clock_unit = 0;
100100
} else if (clock_pin == &pin_PB12
@@ -122,7 +122,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
122122
#endif
123123
self->serializer = 1;
124124
#endif
125-
#ifdef SAMD51
125+
#ifdef SAMx5FAM
126126
if (data_pin == &pin_PB10 || data_pin == &pin_PA22) {
127127
self->serializer = 1;
128128
#endif
@@ -145,13 +145,13 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
145145
mp_raise_RuntimeError(translate("Serializer in use"));
146146
}
147147
#endif
148-
#ifdef SAMD51
148+
#ifdef SAMx5FAM
149149
if (I2S->CTRLA.bit.RXEN == 1) {
150150
mp_raise_RuntimeError(translate("Serializer in use"));
151151
}
152152
#endif
153153
}
154-
#ifdef SAMD51
154+
#ifdef SAMx5FAM
155155
#define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_J
156156
#endif
157157
#ifdef SAMD21
@@ -185,7 +185,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
185185
#ifdef SAMD21
186186
uint32_t serctrl = (self->clock_unit << I2S_SERCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_PDM2) | SERCTRL(DATASIZE_32);
187187
#endif
188-
#ifdef SAMD51
188+
#ifdef SAMx5FAM
189189
uint32_t serctrl = (self->clock_unit << I2S_RXCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_PDM2) | SERCTRL(DATASIZE_32);
190190
#endif
191191

@@ -196,7 +196,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
196196
#ifdef SAMD21
197197
I2S->SERCTRL[self->serializer].reg = serctrl;
198198
#endif
199-
#ifdef SAMD51
199+
#ifdef SAMx5FAM
200200
I2S->RXCTRL.reg = serctrl;
201201
#endif
202202

@@ -274,7 +274,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
274274
#ifdef SAMD21
275275
descriptor->SRCADDR.reg = (uint32_t)&I2S->DATA[self->serializer];
276276
#endif
277-
#ifdef SAMD51
277+
#ifdef SAMx5FAM
278278
descriptor->SRCADDR.reg = (uint32_t)&I2S->RXDATA;
279279
#endif
280280

@@ -295,7 +295,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
295295
#ifdef SAMD21
296296
second_descriptor->SRCADDR.reg = (uint32_t)&I2S->DATA[self->serializer];
297297
#endif
298-
#ifdef SAMD51
298+
#ifdef SAMx5FAM
299299
second_descriptor->SRCADDR.reg = (uint32_t)&I2S->RXDATA;
300300
#endif
301301
second_descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID |
@@ -400,7 +400,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
400400
#ifdef SAMD21
401401
#define MAX_WAIT_COUNTS 1000
402402
#endif
403-
#ifdef SAMD51
403+
#ifdef SAMx5FAM
404404
#define MAX_WAIT_COUNTS 6000
405405
#endif
406406
// If wait_counts exceeds the max count, buffer has probably stopped filling;

0 commit comments

Comments
 (0)