Skip to content

Commit e4b25f2

Browse files
committed
Merge branch 'master' of github.com:adafruit/ArduinoCore-samd
2 parents 43ebb77 + 458b5d9 commit e4b25f2

File tree

12 files changed

+175
-52
lines changed

12 files changed

+175
-52
lines changed

cores/arduino/HardwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class HardwareSerial : public Stream
6868
{
6969
public:
7070
virtual void begin(unsigned long) {}
71-
virtual void begin(unsigned long baudrate, uint16_t config) {}
71+
virtual void begin(unsigned long, uint16_t) {}
7272
virtual void end() {}
7373
virtual int available(void) = 0;
7474
virtual int peek(void) = 0;

cores/arduino/delay.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ unsigned long micros( void )
6161
// a runtime multiplication and shift, saving a few cycles
6262
}
6363

64+
#ifdef __SAMD51__
65+
/*
66+
* On SAMD51, use the (32bit) cycle count maintained by the DWT unit,
67+
* and count exact number of cycles elapsed, rather than guessing how
68+
* many cycles a loop takes, which is dangerous in the presence of
69+
* cache. The overhead of the call and internal code is "about" 20
70+
* cycles. (at 120MHz, that's about 1/6 us)
71+
*/
72+
void delayMicroseconds(unsigned int us)
73+
{
74+
uint32_t start, elapsed;
75+
uint32_t count;
76+
77+
if (us == 0)
78+
return;
79+
80+
count = us * (VARIANT_MCK / 1000000) - 20; // convert us to cycles.
81+
start = DWT->CYCCNT; //CYCCNT is 32bits, takes 37s or so to wrap.
82+
while (1) {
83+
elapsed = DWT->CYCCNT - start;
84+
if (elapsed >= count)
85+
return;
86+
}
87+
}
88+
#endif
89+
90+
6491
void delay( unsigned long ms )
6592
{
6693
if ( ms == 0 )

cores/arduino/delay.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,16 @@ extern void delay( unsigned long dwMs ) ;
6161
*
6262
* \param dwUs the number of microseconds to pause (uint32_t)
6363
*/
64+
#if defined(__SAMD51__)
65+
extern void delayMicroseconds( unsigned int );
66+
#else
6467
static __inline__ void delayMicroseconds( unsigned int ) __attribute__((always_inline, unused)) ;
6568
static __inline__ void delayMicroseconds( unsigned int usec )
6669
{
6770
if ( usec == 0 )
6871
{
6972
return ;
7073
}
71-
72-
#if defined(__SAMD51__)
73-
uint32_t n = usec * (VARIANT_MCK / 1000000) / 12;
74-
75-
__asm__ __volatile__(
76-
"1: \n"
77-
" sub %0, #1 \n" // substract 1 from %0 (n)
78-
" cmp %0, #0 \n" // compare to 0
79-
" bne 1b \n" // if result is not 0 jump to 1
80-
: "+r" (n) // '%0' is n variable with RW constraints
81-
: // no input
82-
: // no clobber
83-
);
84-
85-
#else
8674
/*
8775
* The following loop:
8876
*
@@ -109,10 +97,10 @@ static __inline__ void delayMicroseconds( unsigned int usec )
10997
: // no input
11098
: // no clobber
11199
);
112-
#endif
113100
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
114101
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
115102
}
103+
#endif
116104

117105
#ifdef __cplusplus
118106
}

cores/arduino/pulse.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
3434
uint32_t bit = 1 << p.ulPin;
3535
uint32_t stateMask = state ? bit : 0;
3636

37+
#if defined(__SAMD51__)
38+
/*
39+
* The SAMD51 is fast enough to use really obvious code (similar to
40+
* what was used to produce pulse_asm.S, but using micros() for timing.
41+
* No assembly required, no conversion of loop counts to times (which is
42+
* worrisome in the presence of cache.)
43+
*/
44+
volatile uint32_t *port = &(PORT->Group[p.ulPort].IN.reg);
45+
uint32_t usCallStart; // microseconds at start of call, for timeout.
46+
uint32_t usPulseStart; // microseconds at start of measured pulse.
47+
usCallStart = micros();
48+
// wait for any previous pulse to end
49+
while ((*port & bit) == stateMask) {
50+
if (micros() - usCallStart > timeout)
51+
return -1;
52+
}
53+
// wait for the pulse to start
54+
while ((*port & bit) != stateMask) {
55+
usPulseStart = micros();
56+
if (usPulseStart - usCallStart > timeout)
57+
return -2;
58+
}
59+
60+
// wait for the pulse to stop
61+
while ((*port & bit) == stateMask) {
62+
if (micros() - usCallStart > timeout)
63+
return -3;
64+
}
65+
return micros() - usPulseStart;
66+
#else
3767
// convert the timeout from microseconds to a number of times through
3868
// the initial loop; it takes (roughly) 13 clock cycles per iteration.
3969
uint32_t maxloops = microsecondsToClockCycles(timeout) / 13;
@@ -48,5 +78,6 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
4878
return clockCyclesToMicroseconds(width * 13 + 16);
4979
else
5080
return 0;
81+
#endif // SAMD51
5182
}
5283

cores/arduino/startup.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,14 @@ void SystemInit( void )
252252
CMCC->CTRL.reg = 1;
253253
__enable_irq();
254254
#endif
255-
255+
256+
/*---------------------------------------------------------------------
257+
* Start up the "Debug Watchpoint and Trace" unit, so that we can use
258+
* it's 32bit cycle counter for timing.
259+
*/
260+
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
261+
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
262+
256263
//*************** END SAMD51 *************************//
257264

258265
#else

cores/arduino/wiring_analog.c

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,38 +140,87 @@ void analogReference(eAnalogReference mode)
140140
//TODO: fix gains
141141
switch (mode)
142142
{
143-
case AR_INTERNAL:
144-
case AR_INTERNAL2V23:
143+
case AR_INTERNAL1V0:
145144
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
146-
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; // 1/1.48 VDDANA = 1/1.48* 3V3 = 2.2297
147-
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; // 1/1.48 VDDANA = 1/1.48* 3V3 = 2.2297
145+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_1V0_Val; // select 1.0V
146+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
147+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
148+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
149+
break;
150+
151+
case AR_INTERNAL1V1:
152+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
153+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_1V1_Val; // select 1.1V
154+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
155+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
156+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
157+
break;
158+
159+
case AR_INTERNAL1V2:
160+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
161+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_1V2_Val; // select 1V2
162+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
163+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
164+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
148165
break;
149166

167+
case AR_INTERNAL1V25:
168+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
169+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_1V25_Val; // select 1.25V
170+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
171+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
172+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
173+
break;
174+
175+
case AR_INTERNAL2V0:
176+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
177+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_2V0_Val; // select 2.0V
178+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
179+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
180+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
181+
break;
182+
183+
case AR_INTERNAL2V2:
184+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
185+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_2V2_Val; // select 2.2V
186+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
187+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
188+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
189+
break;
190+
191+
case AR_INTERNAL2V4:
192+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
193+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_2V4_Val; // select 2.4V
194+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
195+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
196+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
197+
break;
198+
199+
case AR_INTERNAL2V5:
200+
//ADC0->GAINCORR.reg = ADC_GAINCORR_GAINCORR(); // Gain Factor Selection
201+
SUPC->VREF.bit.SEL = SUPC_VREF_SEL_2V5_Val; // select 2.5V
202+
SUPC->VREF.bit.VREFOE = 1; // Turn on for use with ADC
203+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; // Use SUPC.VREF
204+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTREF_Val; //
205+
break;
206+
150207
case AR_EXTERNAL:
151208
//ADC0->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
152-
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;
209+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val; // AREF is jumpered to VCC, so 3.3V
153210
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;
154211
break;
155212

156-
/* Don't think this works on SAMD51
157-
case AR_INTERNAL1V0:
158-
//ADC0->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
159-
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference
160-
break;
161-
*/
162-
163213
case AR_INTERNAL1V65:
164-
//ADC0->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
165-
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
166-
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
214+
//ADC0->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val;
215+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; // 1/2 VDDANA = 1.65
216+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; //
167217
break;
168-
218+
169219
case AR_DEFAULT:
170220
default:
171221
//ADC0->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val;
172-
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
173-
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
174-
222+
ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // VDDANA = 3V3
223+
ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; //
175224
break;
176225
}
177226

@@ -368,10 +417,11 @@ void analogWrite(uint32_t pin, uint32_t value)
368417
if (pin == PIN_A0) { // Only 1 DAC on A0 (PA02)
369418
#endif
370419

371-
value = mapResolution(value, _writeResolution, _dacResolution);
372-
373420
#if defined(__SAMD51__)
374421

422+
value = mapResolution(value, _writeResolution, _dacResolution);
423+
424+
375425
uint8_t channel = (pin == PIN_A0 ? 0 : 1);
376426

377427
pinPeripheral(pin, PIO_ANALOG);
@@ -557,7 +607,6 @@ void analogWrite(uint32_t pin, uint32_t value)
557607

558608
if (!tcEnabled[tcNum]) {
559609
tcEnabled[tcNum] = true;
560-
value = mapResolution(value, _writeResolution, 16);
561610
uint16_t GCLK_CLKCTRL_IDs[] = {
562611
GCLK_CLKCTRL_ID(GCM_TCC0_TCC1), // TCC0
563612
GCLK_CLKCTRL_ID(GCM_TCC0_TCC1), // TCC1

cores/arduino/wiring_analog.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ extern "C" {
2727
/*
2828
* \brief SAMD products have only one reference for ADC
2929
*/
30+
// add internal voltages for ATSAMD51 SUPC VREF register
3031
typedef enum _eAnalogReference
3132
{
3233
AR_DEFAULT,
33-
AR_INTERNAL,
34-
AR_EXTERNAL,
3534
AR_INTERNAL1V0,
35+
AR_INTERNAL1V1,
36+
AR_INTERNAL1V2,
37+
AR_INTERNAL1V25,
38+
AR_INTERNAL2V0,
39+
AR_INTERNAL2V2,
40+
AR_INTERNAL2V4,
41+
AR_INTERNAL2V5,
3642
AR_INTERNAL1V65,
37-
AR_INTERNAL2V23
43+
AR_EXTERNAL
3844
} eAnalogReference ;
3945

4046

Binary file not shown.

drivers/prewin10/adafruit_circuit_playground_express.inf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ StartType=3
4646
ErrorControl=1
4747
ServiceBinary=%12%\%DRIVERFILENAME%.sys
4848

49+
[NullInstall.nt]
50+
; nothing to do for a null driver
51+
52+
[NullInstall.nt.Services]
53+
; null driver has no service and no service name
54+
AddService=, 0x00000002
55+
56+
4957
;------------------------------------------------------------------------------
5058
; Vista-64bit Sections
5159
;------------------------------------------------------------------------------
@@ -73,6 +81,13 @@ StartType=3
7381
ErrorControl=1
7482
ServiceBinary=%12%\%DRIVERFILENAME%.sys
7583

84+
[NullInstall.NTamd64]
85+
; nothing to do for a null driver
86+
87+
[NullInstall.NTamd64.Services]
88+
; null driver has no service and no service name
89+
AddService=, 0x00000002
90+
7691

7792
;------------------------------------------------------------------------------
7893
; Vendor and Product ID Definitions
@@ -87,14 +102,14 @@ ServiceBinary=%12%\%DRIVERFILENAME%.sys
87102
[SourceDisksNames]
88103
[DeviceList]
89104
"%DESCRIPTION% UF2 Bootloader (0018:00) BSP"=DriverInstall, USB\VID_239A&PID_0018&MI_00
90-
"%DESCRIPTION% UF2 WebUSB dummy (0018:04) BSP"=DriverInstall, USB\VID_239A&PID_0018&MI_00
105+
"%DESCRIPTION% UF2 WebUSB dummy (0018:04) BSP"=NullInstall, USB\VID_239A&PID_0018&MI_04
91106
"%DESCRIPTION% (0019:00) BSP"=DriverInstall, USB\VID_239A&PID_0019&MI_00
92107
"%DESCRIPTION% Arduino (8018:00) BSP"=DriverInstall, USB\VID_239A&PID_8018&MI_00
93108
"%DESCRIPTION% CircuitPython (8019:00) BSP"=DriverInstall, USB\VID_239A&PID_8019&MI_00
94109

95110
[DeviceList.NTamd64]
96111
"%DESCRIPTION% UF2 Bootloader (0018:00) BSP"=DriverInstall, USB\VID_239A&PID_0018&MI_00
97-
"%DESCRIPTION% UF2 WebUSB dummy (0018:04) BSP"=DriverInstall, USB\VID_239A&PID_0018&MI_00
112+
"%DESCRIPTION% UF2 WebUSB dummy (0018:04) BSP"=NullInstall, USB\VID_239A&PID_0018&MI_04
98113
"%DESCRIPTION% (0019:00) BSP"=DriverInstall, USB\VID_239A&PID_0019&MI_00
99114
"%DESCRIPTION% Arduino (8018:00) BSP"=DriverInstall, USB\VID_239A&PID_8018&MI_00
100115
"%DESCRIPTION% CircuitPython (8019:00) BSP"=DriverInstall, USB\VID_239A&PID_8019&MI_00

platform.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
2121

2222
name=Adafruit SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) Boards
23-
version=1.2.8
23+
version=1.2.9
2424

2525
# Compile variables
2626
# -----------------
@@ -33,7 +33,7 @@ compiler.warning_flags.all=-Wall -Wextra
3333

3434
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
3535
compiler.c.cmd=arm-none-eabi-gcc
36-
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
36+
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
3737
compiler.c.elf.cmd=arm-none-eabi-gcc
3838
compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps
3939
compiler.S.cmd=arm-none-eabi-gcc
@@ -185,4 +185,4 @@ tools.openocd-withbootsize.erase.pattern=
185185

186186
tools.openocd-withbootsize.bootloader.params.verbose=-d2
187187
tools.openocd-withbootsize.bootloader.params.quiet=-d0
188-
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{{runtime.platform.path}/bootloaders/{bootloader.file}}} verify reset; shutdown"
188+
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{{runtime.platform.path}/bootloaders/{bootloader.file}}} verify reset; shutdown"

0 commit comments

Comments
 (0)