8000 Initial SAMR board revision. · sparkfun/circuitpython@94c5cea · GitHub
[go: up one dir, main page]

Skip to content

Commit 94c5cea

Browse files
committed
Initial SAMR board revision.
1 parent 9da79c8 commit 94c5cea

File tree

16 files changed

+239
-21
lines changed

16 files changed

+239
-21
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
- TRAVIS_BOARD=pca10056
1515
- TRAVIS_BOARD=trinket_m0
1616
- TRAVIS_BOARD=feather_m4_express
17+
- TRAVIS_BOARD=feather_radiofruit_zigbee
1718
- TRAVIS_BOARD=arduino_zero
1819
- TRAVIS_BOARD=circuitplayground_express_crickit
1920
- TRAVIS_BOARD=feather_m0_basic
@@ -50,7 +51,7 @@ notifications:
5051
before_script:
5152
- sudo dpkg --add-architecture i386
5253

53-
- ([[ -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))
54+
- ([[ -z "$TRAVIS_BOARD" || $TRAVIS_BOARD = "feather_huzzah" ]] || (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))
5455

5556
# For nrf builds
5657
- ([[ $TRAVIS_BOARD != "feather52832" && $TRAVIS_BOARD != "pca10056" ]] || sudo ports/nrf/drivers/bluetooth/download_ble_stack.sh)
@@ -62,7 +63,7 @@ before_script:
6263
- ([[ $TRAVIS_TEST != "docs" ]] || sudo pip install Sphinx sphinx-rtd-theme recommonmark)
6364
- ([[ $TRAVIS_TEST != "translations" ]] || sudo pip3 install polib)
6465
- gcc --version
65-
- ([[ -z "$TRAVIS_BOARD" ]] || arm-none-eabi-gcc --version)
66+
- ([[ -z "$TRAVIS_BOARD" || $TRAVIS_BOARD = "feather_huzzah" ]] || arm-none-eabi-gcc --version)
6667
- python3 --version
6768

6869
script:

ports/atmel-samd/Makefile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ SRC_COMMON_HAL = \
336336
pulseio/PWMOut.c \
337337
usb_hid/__init__.c \
338338
usb_hid/Device.c \
339-
audioio/__init__.c \
340-
audioio/AudioOut.c \
341339
touchio/__init__.c \
342340
touchio/TouchIn.c \
343341

@@ -378,13 +376,8 @@ SRC_BINDINGS_ENUMS = \
378376
supervisor/__init__.c \
379377
util.c
380378

381-
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
382-
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
383-
$(addprefix common-hal/, $(SRC_COMMON_HAL))
384379

385380
SRC_SHARED_MODULE = \
386-
audioio/RawSample.c \
387-
audioio/WaveFile.c \
388381
bitbangio/__init__.c \
389382
bitbangio/I2C.c \
390383
bitbangio/OneWire.c \
@@ -402,17 +395,33 @@ SRC_SHARED_MODULE = \
402395
uheap/__init__.c \
403396
ustack/__init__.c
404397

398+
# SAMRs don't have a DAC
399+
ifneq ($(CHIP_VARIANT),SAMR21G18A)
400+
SRC_COMMON_HAL += \
401+
audioio/__init__.c \
402+
audioio/AudioOut.c
403+
SRC_SHARED_MODULE += \
404+
audioio/RawSample.c \
405+
audioio/WaveFile.c
406+
endif
407+
405408
# The smallest SAMD51 packages don't have I2S. Everything else does.
406409
ifneq ($(CHIP_VARIANT),SAMD51G18A)
407410
ifneq ($(CHIP_VARIANT),SAMD51G19A)
408-
SRC_COMMON_HAL += \
409-
audiobusio/__init__.c \
410-
audiobusio/I2SOut.c \
411-
audiobusio/PDMIn.c
412-
SRC_C += peripherals/samd/i2s.c peripherals/samd/$(CHIP_FAMILY)/i2s.c
411+
ifneq ($(CHIP_VARIANT),SAMR21G18A)
412+
SRC_COMMON_HAL += \
413+
audiobusio/__init__.c \
414+
audiobusio/I2SOut.c \
415+
audiobusio/PDMIn.c
416+
SRC_C += peripherals/samd/i2s.c peripherals/samd/$(CHIP_FAMILY)/i2s.c
417+
endif
413418
endif
414419
endif
415420

421+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
422+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
423+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
424+
416425
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
417426
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
418427

ports/atmel-samd/background.c

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
volatile uint64_t last_finished_tick = 0;
3434

3535
void run_background_tasks(void) {
36+
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
3637
audio_dma_background();
38+
#endif
3739
usb_msc_background();
3840
usb_cdc_background();
3941
last_finished_tick = ticks_ms;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRING 179B EMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "boards/board.h"
28+
29+
void board_init(void)
30+
{
31+
}
32+
33+
bool board_requests_safe_mode(void) {
34+
return false;
35+
}
36+
37+
void reset_board(void) {
38+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#define MICROPY_HW_BOARD_NAME "Adafruit Feather RadioFruit Zigbee"
2+
#define MICROPY_HW_MCU_NAME "samr21g18"
3+
4+
#define MICROPY_HW_NEOPIXEL (&pin_PA22)
5+
6+
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
7+
#define SPI_FLASH_BAUDRATE (8000000)
8+
9+
#define SPI_FLASH_MOSI_PIN PIN_PA31
10+
#define SPI_FLASH_MISO_PIN PIN_PA30
11+
#define SPI_FLASH_SCK_PIN PIN_PA17
12+
#define SPI_FLASH_CS_PIN PIN_PA28
13+
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA31D_SERCOM1_PAD3
14+
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA30D_SERCOM1_PAD2
15+
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA17C_SERCOM1_PAD1
16+
#define SPI_FLASH_SERCOM SERCOM1
17+
#define SPI_FLASH_SERCOM_INDEX 1
18+
#define SPI_FLASH_MOSI_PAD 3
19+
#define SPI_FLASH_MISO_PAD 2
20+
#define SPI_FLASH_SCK_PAD 1
21+
// <o> Transmit Data Pinout
22+
// <0x0=>PAD[0,1]_DO_SCK
23+
// <0x1=>PAD[2,3]_DO_SCK
24+
// <0x2=>PAD[3,1]_DO_SCK
25+
// <0x3=>PAD[0,3]_DO_SCK
26+
#define SPI_FLASH_DOPO 2
27+
#define SPI_FLASH_DIPO 2 // same as MISO pad
28+
29+
// These are pins not to reset.
30+
#define MICROPY_PORT_A (PORT_PA17 | PORT_PA22 | PORT_PA24 | PORT_PA25 | PORT_PA28 | PORT_PA30 | PORT_PA31)
31+
#define MICROPY_PORT_B ( 0 )
32+
#define MICROPY_PORT_C ( 0 )
33+
34+
#include "external_flash/external_flash.h"
35+
36+
// If you change this, then make sure to update the linker scripts as well to
37+
// make sure you don't overwrite code.
38+
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
39+
40+
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
41+
42+
#include "external_flash/devices.h"
43+
44+
#define EXTERNAL_FLASH_DEVICE_COUNT 2
45+
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
46+
GD25Q16C
47+
48+
#include "external_flash/external_flash.h"
49+
50+
#define BOARD_HAS_CRYSTAL 1
51+
52+
#define DEFAULT_I2C_BUS_SCL (&pin_PA13)
53+
#define DEFAULT_I2C_BUS_SDA (&pin_PA12)
54+
55+
#define DEFAULT_SPI_BUS_SCK (&pin_PB23)
56+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB22)
57+
#define DEFAULT_SPI_BUS_MISO (&pin_PA23)
58+
59+
#define DEFAULT_UART_BUS_RX (&pin_PA09)
60+
#define DEFAULT_UART_BUS_TX (&pin_PA08)
61+
62+
// USB is always used internally so skip the pin objects for it.
63+
#define IGNORE_PIN_PA24 1
64+
#define IGNORE_PIN_PA25 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LD_FILE = boards/samd21x18-bootloader-external-flash.ld
2+
USB_VID = 0x239A
3+
USB_PID = 0x8023
4+
USB_PRODUCT = "Feather RadioFruit Zigbee"
5+
USB_MANUFACTURER = "Adafruit Industries LLC"
6+
7+
SPI_FLASH_FILESYSTEM = 1
8+
LONGINT_IMPL = MPZ
9+
10+
CHIP_VARIANT = SAMR21G18A
11+
CHIP_FAMILY = samd21
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "board_busses.h"
4+
5+
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
6+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PB02) },
7+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB03) },
8+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA04) },
9+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA05) },
10+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA06) },< 10000 /div>
11+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA07) },
12+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB23) },
13+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB22) },
14+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA23) },
15+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA09) },
16+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA09) },
17+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA08) },
18+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA08) },
19+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA12) },
20+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA13) },
21+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA14) },
22+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA15) },
23+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA16) },
24+
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) },
25+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) },
26+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA22) },
27+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA22) },
28+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA27) },
29+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
30+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
31+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
32+
33+
// Internally connected within the package
34+
{ MP_ROM_QSTR(MP_QSTR_DIG3), MP_ROM_PTR(&pin_PA10) },
35+
{ MP_ROM_QSTR(MP_QSTR_DIG4), MP_ROM_PTR(&pin_PA11) },
36+
{ MP_ROM_QSTR(MP_QSTR_SLP_TR), MP_ROM_PTR(&pin_PA20) },
37+
{ MP_ROM_QSTR(MP_QSTR_IRQ), MP_ROM_PTR(&pin_PB00) },
38+
{ MP_ROM_QSTR(MP_QSTR_DIG1), MP_ROM_PTR(&pin_PA16) },
39+
{ MP_ROM_QSTR(MP_QSTR_DIG2), MP_ROM_PTR(&pin_PA17) },
40+
{ MP_ROM_QSTR(MP_QSTR_RF_MOSI), MP_ROM_PTR(&pin_PB30) },
41+
{ MP_ROM_QSTR(MP_QSTR_SEL), MP_ROM_PTR(&pin_PB31) },
42+
{ MP_ROM_QSTR(MP_QSTR_CLKM), MP_ROM_PTR(&pin_PC16) },
43+
{ MP_ROM_QSTR(MP_QSTR_RF_SCK), MP_ROM_PTR(&pin_PC18) },
44+
{ MP_ROM_QSTR(MP_QSTR_RF_MISO), MP_ROM_PTR(&pin_PC19) },
45+
};
46+
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

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

100644100755
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545

4646
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
4747
const mcu_pin_obj_t *pin) {
48+
#if defined(SAMD21) && !defined(PIN_PA02)
49+
mp_raise_NotImplementedError("No DAC on chip");
50+
#else
4851
if (pin->number != PIN_PA02
4952
#ifdef SAMD51
5053
&& pin->number != PIN_PA05
@@ -97,13 +100,15 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
97100
gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_B);
98101

99102
dac_sync_enable_channel(&self->descriptor, self->channel);
103+
#endif
100104
}
101105

102106
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
103107
return self->deinited;
104108
}
105109

106110
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
111+
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
107112
if (common_hal_analogio_analogout_deinited(self)) {
108113
return;
109114
}
@@ -119,16 +124,23 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
119124
#endif
120125
self->deinited = true;
121126
// TODO(tannewt): Turn off the DAC clocks to save power.
127+
#endif
122128
}
123129

124130
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
125131
uint16_t value) {
132+
#if defined(SAMD21) && !defined(PIN_PA02)
133+
return;
134+
#endif
126135
// Input is 16 bit so make sure and set LEFTADJ to 1 so it takes the top
127136
// bits. This is currently done in asf4_conf/*/hpl_dac_config.h.
128137
dac_sync_write(&self->descriptor, self->channel, &value, 1);
129138
}
130139

131140
void analogout_reset(void) {
141+
#if defined(SAMD21) && !defined(PIN_PA02)
142+
return;
143+
#endif
132144
#ifdef SAMD21
133145
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
134146
#endif

ports/atmel-samd/common-hal/busio/SPI.c

100644100755
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
5353
uint8_t mosi_pad = 0;
5454
uint8_t miso_pad = 0;
5555
uint8_t dopo = 255;
56+
#ifdef PIN_PC19
57+
if (miso == &pin_PC19) {
58+
if (mosi == &pin_PB30 && clock == &pin_PC18) {
59+
sercom = SERCOM4;
60+
sercom_index = 4;
61+
clock_pinmux = MUX_F;
62+
mosi_pinmux = MUX_F;
63+
miso_pinmux = MUX_F;
64+
clock_pad = 3;
65+
mosi_pad = 2;
66+
miso_pad = 0;
67+
dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad);
68 10000 +
}
69+
// Error, leave SERCOM unset to throw an exception later.
70+
} else {
71+
#endif
5672
for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) {
5773
sercom_index = clock->sercom[i].index; // 2 for SERCOM2, etc.
5874
if (sercom_index >= SERCOM_INST_NUM) {
@@ -109,6 +125,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
109125
break;
110126
}
111127
}
128+
#ifdef PIN_PC19
129+
}
130+
#endif
112131
if (sercom == NULL) {
113132
mp_raise_ValueError("Invalid pins");
114133
}

ports/atmel-samd/common-hal/microcontroller/__init__.c

100644100755
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,16 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
264264
{ MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) },
265265
#endif
266266
#if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03)
267-
{ MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }
267+
{ MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) },
268+
#endif
269+
#if defined(PIN_PC16)
270+
{ MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) },
271+
#endif
272+
#if defined(PIN_PC18)
273+
{ MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) },
274+
#endif
275+
#if defined(PIN_PC19)
276+
{ MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) },
268277
#endif
269278
};
270279
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);

ports/atmel-samd/mpconfigport.h

100644100755
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,21 @@ extern const struct _mp_obj_module_t usb_hid_module;
213213
// Scan gamepad every 32ms
214214
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
215215

216-
#if defined(__SAMD51G19A__) || defined(__SAMD51G18A__)
216+
#if defined(__SAMD51G19A__) || defined(__SAMD51G18A__) || defined(__SAMR21G18A__)
217217
#define AUDIOBUSIO_MODULE
218218
#else
219219
#define AUDIOBUSIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audiobusio), (mp_obj_t)&audiobusio_module },
220220
#endif
221221

222+
#if defined(__SAMR21G18A__)
223+
#define AUDIOIO_MODULE
224+
#else
225+
#define AUDIOIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module },
226+
#endif
227+
222228
#ifndef EXTRA_BUILTIN_MODULES
223229
#define EXTRA_BUILTIN_MODULES \
224-
{ MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \
230+
AUDIOIO_MODULE \
225231
AUDIOBUSIO_MODULE \
226232
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }, \
227233
{ MP_OBJ_NEW_QSTR(MP_QSTR_rotaryio), (mp_obj_t)&rotaryio_module }, \

0 commit comments

Comments
 (0)
0