Skip to content

Commit 59de275

Browse files
authored
Merge pull request arduino#32 from adafruit/merge-samd51
Merge samd51
2 parents 625fd55 + 04618d7 commit 59de275

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4592
-784
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.bz2
2+
*.atsuo
23

34
bootloaders/*/build/
45
*~

Diff for: README.md

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,50 @@
1-
# Arduino Core for SAMD21 CPU
1+
# Arduino Core for SAMD21 and SAMD51 CPU
22

33
This repository contains the source code and configuration files of the Arduino Core
4-
for Atmel's SAMD21 processor (used on the Arduino/Genuino Zero, MKR1000 and MKRZero boards).
4+
for Atmel's SAMD21 and SAMD51 processor (used on the Arduino/Genuino Zero, MKR1000 and MKRZero boards).
55

66
In particular, this adds support for the Adafruit SAMD Boards such as the Feather M0
77

88
## Installation on Arduino IDE
99

10-
Install the Adafruit Board Support package json and then install the Adafruit SAMD board package
10+
This is a detailed process for now!
1111

12-
https://learn.adafruit.com/adafruit-feather-m0-basic-proto/using-with-arduino-ide
12+
1. Install Arduino IDE 1.8.5 or greater
13+
2. Remove the Adafruit SAMD board support package if you have installed it
14+
3. make a folder in your ArduinoSketchFolder called "hardware", then make a folder "hardware/Adafruit"
15+
4. in "hardware/Adafruit" git clone https://github.com/adafruit/ArduinoCore-samd, and rename the folder "samd"
16+
5. Check you now have "ArduinoSketcheFolderName/hardware/Adafruit/samd/boards.txt"
17+
6. git checkout samd51 from within the cloned repo, and check boards.txt contains "# Adafruit Metro M4 (SAMD51)"
18+
7. Now we need to update CMSIS! Download https://github.com/adafruit/ArduinoModule-CMSIS-Atmel/archive/master.zip and unzip
19+
8. Find your Arduino CMSIS, in Mac its "~/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS" version # may vary, you'll need "Go to folder..." feature in the Finder to get to " ~/Library/Arduino15" as it is hidden. In Windows it is "C:\Users\yourusername\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0\CMSIS" Inside is a folder named Device
20+
21+
For Linux: the Arduino stuff is located in ~/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS
22+
23+
9. Inside the downloaded CMSIS zip, go into the CMSIS-Atmel/CMSIS folder, you should see a folder named Device. *DRAG THE DEVICE FOLDER ONLY* from the zip to your arduino Library folder so that Device is merged with Device. It will replace a bunch of files.
24+
25+
For Linux, it may be better to just delete the original Device Folder then copy over the new one - the drag/drop worked ok on MACOS, but not so well on my Linux box.
26+
27+
10. You will also need to replace bossac. For Windows or Mac: Go here https://github.com/adafruit/BOSSA/releases and download either windows exe or mac app of latest bossac. unzip. Go to Step 12.
28+
29+
For Linux users it is best to build a copy of bossac locally -
30+
clone the Adafruit Repostitory to somewhere on your local machine.
31+
```
32+
git clone https://github.com/adafruit/BOSSA.git
33+
change to the arduino branch
34+
git checkout arduino
35+
```
36+
Follow the instructions to build bossac in README.md or at https://github.com/adafruit/BOSSA/tree/arduino.
37+
38+
11. Replace the binary at ".../Library/Arduino15/packages/arduino/tools/bossac/1.7.0/bossac" or "...\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0\bossac"
39+
12. On Windows 7 you will also need to install the updated serial driver, download https://github.com/adafruit/Adafruit_Windows_Drivers/archive/master.zip to get all the drivers, and point the Device Manager to the unzipped folder. It isn't signed, so just approve the installation manually.
40+
13. That's it!
1341

1442
## Bugs or Issues
1543

44+
## Known Issues for SAMD51:
45+
* AREF must be tied to 3.3V for dac to work. This is a bug in the SAMD51 silicon.
46+
* USB host mode doesn't work yet
47+
1648
If you find a bug you can submit an issue here on github:
1749

1850
https://github.com/adafruit/ArduinoCore-samd

Diff for: boards.txt

+73-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ adafruit_feather_m0.build.usb_product="Feather M0"
3232
adafruit_feather_m0.build.usb_manufacturer="Adafruit"
3333
adafruit_feather_m0.build.board=SAMD_FEATHER_M0
3434
adafruit_feather_m0.build.core=arduino
35-
adafruit_feather_m0.build.extra_flags=-DARDUINO_SAMD_ZERO -D__SAMD21G18A__ {build.usb_flags}
35+
adafruit_feather_m0.build.extra_flags=-DARDUINO_SAMD_ZERO -DARM_MATH_CM0PLUS -D__SAMD21G18A__ {build.usb_flags}
3636
adafruit_feather_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
3737
adafruit_feather_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
3838
adafruit_feather_m0.build.variant=feather_m0
@@ -41,6 +41,7 @@ adafruit_feather_m0.build.vid=0x239A
4141
adafruit_feather_m0.build.pid=0x800B
4242
adafruit_feather_m0.bootloader.tool=openocd
4343
adafruit_feather_m0.bootloader.file=feather/samd21_sam_ba.bin
44+
adafruit_feather_m0.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
4445

4546
adafruit_feather_m0_express.name=Adafruit Feather M0 Express
4647
adafruit_feather_m0_express.vid.0=0x239A
@@ -59,7 +60,7 @@ adafruit_feather_m0_express.build.usb_product="Feather M0 Express"
5960
adafruit_feather_m0_express.build.usb_manufacturer="Adafruit"
6061
adafruit_feather_m0_express.build.board=SAMD_FEATHER_M0_EXPRESS
6162
adafruit_feather_m0_express.build.core=arduino
62-
adafruit_feather_m0_express.build.extra_flags=-DARDUINO_SAMD_ZERO -DARDUINO_SAMD_FEATHER_M0 -DADAFRUIT_FEATHER_M0_EXPRESS -D__SAMD21G18A__ {build.usb_flags}
63+
adafruit_feather_m0_express.build.extra_flags=-DARDUINO_SAMD_ZERO -DARDUINO_SAMD_FEATHER_M0 -DARM_MATH_CM0PLUS -DADAFRUIT_FEATHER_M0_EXPRESS -D__SAMD21G18A__ {build.usb_flags}
6364
adafruit_feather_m0_express.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
6465
adafruit_feather_m0_express.build.openocdscript=openocd_scripts/arduino_zero.cfg
6566
adafruit_feather_m0_express.build.variant=feather_m0_express
@@ -68,6 +69,7 @@ adafruit_feather_m0_express.build.vid=0x239A
6869
adafruit_feather_m0_express.build.pid=0x801B
6970
adafruit_feather_m0_express.bootloader.tool=openocd
7071
adafruit_feather_m0_express.bootloader.file=feather/samd21_sam_ba.bin
72+
adafruit_feather_m0_express.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
7173

7274
#adafruit_radio_m0.name=Adafruit M0 Radio (Native USB Port)
7375
#adafruit_radio_m0.vid.0=0x239A
@@ -86,7 +88,7 @@ adafruit_feather_m0_express.bootloader.file=feather/samd21_sam_ba.bin
8688
#adafruit_radio_m0.build.usb_manufacturer="Adafruit"
8789
#adafruit_radio_m0.build.board=SAMD_ZERO
8890
#adafruit_radio_m0.build.core=arduino
89-
#adafruit_radio_m0.build.extra_flags=-D__SAMR21G18A__ {build.usb_flags}
91+
#adafruit_radio_m0.build.extra_flags=-D__SAMR21G18A__ -DARM_MATH_CM0PLUS {build.usb_flags}
9092
#adafruit_radio_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
9193
#adafruit_radio_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
9294
#adafruit_radio_m0.build.variant=zero_radio
@@ -113,7 +115,7 @@ adafruit_metro_m0.build.usb_product="Metro M0 Express"
113115
adafruit_metro_m0.build.usb_manufacturer="Adafruit"
114116
adafruit_metro_m0.build.board=SAMD_ZERO
115117
adafruit_metro_m0.build.core=arduino
116-
adafruit_metro_m0.build.extra_flags=-D__SAMD21G18A__ -DARDUINO_SAMD_ZERO -DADAFRUIT_METRO_M0_EXPRESS {build.usb_flags}
118+
adafruit_metro_m0.build.extra_flags=-D__SAMD21G18A__ -DARDUINO_SAMD_ZERO -DARM_MATH_CM0PLUS -DADAFRUIT_METRO_M0_EXPRESS {build.usb_flags}
117119
adafruit_metro_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
118120
adafruit_metro_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
119121
adafruit_metro_m0.build.variant=metro_m0
@@ -122,6 +124,7 @@ adafruit_metro_m0.build.vid=0x239A
122124
adafruit_metro_m0.build.pid=0x8013
123125
adafruit_metro_m0.bootloader.tool=openocd
124126
adafruit_metro_m0.bootloader.file=metro/bootloader_uf2.bin
127+
adafruit_metro_m0.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
125128

126129
# Adafruit Circuit Playground M0
127130
# ------------------------------
@@ -142,7 +145,7 @@ adafruit_circuitplayground_m0.build.usb_product="Circuit Playground Express"
142145
adafruit_circuitplayground_m0.build.usb_manufacturer="Adafruit"
143146
adafruit_circuitplayground_m0.build.board=SAMD_CIRCUITPLAYGROUND_EXPRESS
144147
adafruit_circuitplayground_m0.build.core=arduino
145-
adafruit_circuitplayground_m0.build.extra_flags=-DCRYSTALLESS -DARDUINO_SAMD_ZERO -D__SAMD21G18A__ -DADAFRUIT_CIRCUITPLAYGROUND_M0 {build.usb_flags}
148+
adafruit_circuitplayground_m0.build.extra_flags=-DCRYSTALLESS -DARDUINO_SAMD_ZERO -D__SAMD21G18A__ -DARM_MATH_CM0PLUS -DADAFRUIT_CIRCUITPLAYGROUND_M0 {build.usb_flags}
146149
adafruit_circuitplayground_m0.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
147150
adafruit_circuitplayground_m0.build.openocdscript=openocd_scripts/arduino_zero.cfg
148151
adafruit_circuitplayground_m0.build.variant=circuitplay
@@ -151,6 +154,7 @@ adafruit_circuitplayground_m0.build.vid=0x239A
151154
adafruit_circuitplayground_m0.build.pid=0x8018
152155
adafruit_circuitplayground_m0.bootloader.tool=openocd
153156
adafruit_circuitplayground_m0.bootloader.file=circuitplay/bootloader_uf2.bin
157+
adafruit_circuitplayground_m0.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
154158

155159
adafruit_gemma_m0.name=Adafruit Gemma M0
156160
adafruit_gemma_m0.vid.0=0x239A
@@ -234,6 +238,7 @@ adafruit_itsybitsy_m0.build.vid=0x239A
234238
adafruit_itsybitsy_m0.build.pid=0x800F
235239
adafruit_itsybitsy_m0.bootloader.tool=openocd
236240
adafruit_itsybitsy_m0.bootloader.file=itsybitsy/samd21_sam_ba.bin
241+
adafruit_itsybitsy_m0.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
237242

238243

239244
adafruit_pirkey.name=Adafruit pIRkey
@@ -261,4 +266,66 @@ adafruit_pirkey.build.variant_system_lib=
261266
adafruit_pirkey.build.vid=0x239A
262267
adafruit_pirkey.build.pid=0x801E
263268
adafruit_pirkey.bootloader.tool=openocd
264-
adafruit_pirkey.bootloader.file=pirkey/bootloader_uf2.bin
269+
adafruit_pirkey.bootloader.file=pirkey/bootloader_uf2.bin
270+
adafruit_pirkey.compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
271+
272+
273+
# Adafruit Metro M4 (SAMD51)
274+
# ------------------------------
275+
adafruit_metro_m4.name=Adafruit Metro M4 (SAMD51)
276+
adafruit_metro_m4.vid.0=0x239A
277+
adafruit_metro_m4.pid.0=0x8020
278+
adafruit_metro_m4.vid.1=0x239A
279+
adafruit_metro_m4.pid.1=0x0020
280+
adafruit_metro_m4.upload.tool=bossac
281+
adafruit_metro_m4.upload.protocol=sam-ba
282+
adafruit_metro_m4.upload.maximum_size=507904
283+
adafruit_metro_m4.upload.use_1200bps_touch=true
284+
adafruit_metro_m4.upload.wait_for_upload_port=true
285+
adafruit_metro_m4.upload.native_usb=true
286+
adafruit_metro_m4.build.mcu=cortex-m4
287+
adafruit_metro_m4.build.f_cpu=48000000L
288+
adafruit_metro_m4.build.usb_product="Adafruit Metro M4"
289+
adafruit_metro_m4.build.usb_manufacturer="Adafruit LLC"
290+
adafruit_metro_m4.build.board=METRO_M4
291+
adafruit_metro_m4.build.core=arduino
292+
adafruit_metro_m4.build.extra_flags=-D__SAMD51J19A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
293+
adafruit_metro_m4.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
294+
adafruit_metro_m4.build.openocdscript=openocd_scripts/arduino_zero.cfg
295+
adafruit_metro_m4.build.variant=metro_m4
296+
adafruit_metro_m4.build.variant_system_lib=
297+
adafruit_metro_m4.build.vid=0x239A
298+
adafruit_metro_m4.build.pid=0x8020
299+
adafruit_metro_m4.bootloader.tool=openocd
300+
adafruit_metro_m4.bootloader.file=metroM4/bootloader.bin
301+
adafruit_metro_m4.compiler.arm.cmsis.ldflags="-L{build.variant.path}" -larm_cortexM4lf_math -mfloat-abi=hard -mfpu=fpv4-sp-d16
302+
303+
# Adafruit Feather M4 (SAMD51)
304+
# ------------------------------
305+
#adafruit_feather_m4.name=Adafruit Feather M4 (SAMD51)
306+
#adafruit_feather_m4.vid.0=0x239A
307+
#adafruit_feather_m4.pid.0=0x8022
308+
#adafruit_feather_m4.vid.1=0x239A
309+
#adafruit_feather_m4.pid.1=0x0022
310+
#adafruit_feather_m4.upload.tool=bossac
311+
#adafruit_feather_m4.upload.protocol=sam-ba
312+
#adafruit_feather_m4.upload.maximum_size=507904
313+
#adafruit_feather_m4.upload.use_1200bps_touch=true
314+
#adafruit_feather_m4.upload.wait_for_upload_port=true
315+
#adafruit_feather_m4.upload.native_usb=true
316+
#adafruit_feather_m4.build.mcu=cortex-m4
317+
#adafruit_feather_m4.build.f_cpu=48000000L
318+
#adafruit_feather_m4.build.usb_product="Adafruit Feather M4"
319+
#adafruit_feather_m4.build.usb_manufacturer="Adafruit LLC"
320+
#adafruit_feather_m4.build.board=FEATHER_M4
321+
#adafruit_feather_m4.build.core=arduino
322+
#adafruit_feather_m4.build.extra_flags=-D__SAMD51G19A__ -D__SAMD51__ {build.usb_flags} -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
323+
#adafruit_feather_m4.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
324+
#adafruit_feather_m4.build.openocdscript=openocd_scripts/arduino_zero.cfg
325+
#adafruit_feather_m4.build.variant=feather_m4
326+
#adafruit_feather_m4.build.variant_system_lib=
327+
#adafruit_feather_m4.build.vid=0x239A
328+
#adafruit_feather_m4.build.pid=0x8022
329+
#adafruit_feather_m4.bootloader.tool=openocd
330+
#adafruit_feather_m4.bootloader.file=metroM4/bootloader.bin
331+
#adafruit_feather_m4.compiler.arm.cmsis.ldflags="-L{build.variant.path}" -larm_cortexM4lf_math -mfloat-abi=hard -mfpu=fpv4-sp-d16

Diff for: bootloaders/metroM4/bootloader.bin

16 KB
Binary file not shown.

Diff for: bootloaders/metroM4/update-bootloader.bin

18.3 KB
Binary file not shown.

Diff for: bootloaders/metroM4/update-bootloader.uf2

37 KB
Binary file not shown.

Diff for: cores/arduino/HardwareSerial.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
class HardwareSerial : public Stream
6868
{
6969
public:
70-
virtual void begin(unsigned long);
71-
virtual void begin(unsigned long baudrate, uint16_t config);
72-
virtual void end();
70+
virtual void begin(unsigned long) {}
71+
virtual void begin(unsigned long baudrate, uint16_t config) {}
72+
virtual void end() {}
7373
virtual int available(void) = 0;
7474
virtual int peek(void) = 0;
7575
virtual int read(void) = 0;

Diff for: cores/arduino/Reset.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,72 @@ extern "C" {
3030
extern const uint32_t __text_start__;
3131
#define APP_START ((volatile uint32_t)(&__text_start__) + 4)
3232

33+
#else
34+
35+
#if defined(__SAMD51__)
36+
#define APP_START 0x00004004
3337
#else
3438
#define APP_START 0x00002004
3539
#endif
3640

41+
#endif
42+
3743
static inline bool nvmReady(void) {
44+
#if defined(__SAMD51__)
45+
return NVMCTRL->STATUS.reg & NVMCTRL_STATUS_READY;
46+
#else
3847
return NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY;
48+
#endif
3949
}
4050

4151
__attribute__ ((long_call, section (".ramfunc")))
4252
static void banzai() {
4353
// Disable all interrupts
4454
__disable_irq();
55+
56+
#if defined(__SAMD51__)
57+
//THESE MUST MATCH THE BOOTLOADER
58+
#define DOUBLE_TAP_MAGIC 0xf01669efUL
59+
#define BOOT_DOUBLE_TAP_ADDRESS (HSRAM_ADDR + HSRAM_SIZE - 4)
60+
61+
unsigned long *a = (unsigned long *)BOOT_DOUBLE_TAP_ADDRESS;
62+
*a = DOUBLE_TAP_MAGIC;
63+
//NVMCTRL->ADDR.reg = APP_START;
64+
//NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMD_EB | NVMCTRL_CTRLB_CMDEX_KEY;
65+
66+
// Reset the device
67+
NVIC_SystemReset() ;
4568

69+
while (true);
70+
#else
71+
4672
// Avoid erasing the application if APP_START is < than the minimum bootloader size
4773
// This could happen if without_bootloader linker script was chosen
4874
// Minimum bootloader size in SAMD21 family is 512bytes (RM section 22.6.5)
75+
4976
if (APP_START < (0x200 + 4)) {
5077
goto reset;
5178
}
79+
5280

5381
// Erase application
5482
while (!nvmReady())
5583
;
84+
5685
NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK;
5786
NVMCTRL->ADDR.reg = (uintptr_t)&NVM_MEMORY[APP_START / 4];
5887
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_ER | NVMCTRL_CTRLA_CMDEX_KEY;
88+
5989
while (!nvmReady())
60-
;
90+
;
6191

6292
reset:
6393
// Reset the device
6494
NVIC_SystemReset() ;
6595

6696
while (true);
97+
#endif
98+
6799
}
68100

69101
static int ticks = -1;

0 commit comments

Comments
 (0)