Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern "C"{

// Include Atmel headers
#include "sam.h"
#include "same5x_compat_shim.h"
#include "wiring_constants.h"

#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
Expand Down
6 changes: 3 additions & 3 deletions cores/arduino/Reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern const uint32_t __text_start__;

#else

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
#define APP_START 0x00004004
#else
#define APP_START 0x00002004
Expand All @@ -42,7 +42,7 @@ extern const uint32_t __text_start__;
#endif

static inline bool nvmReady(void) {
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
return NVMCTRL->STATUS.reg & NVMCTRL_STATUS_READY;
#else
return NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY;
Expand All @@ -54,7 +54,7 @@ static void banzai() {
// Disable all interrupts
__disable_irq();

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
//THESE MUST MATCH THE BOOTLOADER
#define DOUBLE_TAP_MAGIC 0xf01669efUL
#define BOOT_DOUBLE_TAP_ADDRESS (HSRAM_ADDR + HSRAM_SIZE - 4)
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SERCOM::SERCOM(Sercom* s)
#elif SERCOM_SPI_FREQ_REF == 100000000 // 100 MHz clock = GCLK2
clockSource = SERCOM_CLOCK_SOURCE_100M;
#endif
#endif // end __SAMD51__
#endif // end SAMD51/SAME5x
}

/* =========================
Expand Down
1 change: 1 addition & 0 deletions cores/arduino/SERCOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define _SERCOM_CLASS_

#include "sam.h"
#include "same5x_compat_shim.h"

// SAMD51 has configurable MAX_SPI, else use peripheral clock default.
// Update: changing MAX_SPI via compiler flags is DEPRECATED, because
Expand Down
6 changes: 3 additions & 3 deletions cores/arduino/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ volatile int64_t toggleCount;
volatile bool toneIsActive = false;
volatile bool firstTimeRunning = false;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
#define TONE_TC TC0
#define TONE_TC_IRQn TC0_IRQn
#define TONE_TC_GCLK_ID TC0_GCLK_ID
Expand Down Expand Up @@ -86,7 +86,7 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)

NVIC_SetPriority(TONE_TC_IRQn, 5);

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
GCLK->PCHCTRL[TONE_TC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK0_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
#else
// Enable GCLK for TC4 and TC5 (timer counter input clock)
Expand Down Expand Up @@ -150,7 +150,7 @@ void tone (uint32_t outputPin, uint32_t frequency, uint32_t duration)
uint16_t tmpReg = 0;
tmpReg |= TC_CTRLA_MODE_COUNT16; // Set Timer counter Mode to 16 bits

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
TONE_TC->COUNT16.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ; // Set TONE_TC mode as match frequency
#else
tmpReg |= TC_CTRLA_WAVEGEN_MFRQ; // Set TONE_TC mode as match frequency
Expand Down
4 changes: 2 additions & 2 deletions cores/arduino/USB/SAMD21_USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class USBDevice_SAMD21G18x {
// Enable
inline void enable() {
usb.CTRLA.bit.ENABLE = 1;
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
while( usb.SYNCBUSY.reg & USB_SYNCBUSY_ENABLE ); //wait for sync
#endif
}
inline void disable() {
usb.CTRLA.bit.ENABLE = 0;
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
while( usb.SYNCBUSY.reg & USB_SYNCBUSY_ENABLE ); //wait for sync
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
}
else if (setup.wValueL == ISERIAL) {
#ifdef PLUGGABLE_USB_ENABLED
#ifdef __SAMD51__
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x008061FC)
#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x00806010)
#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x00806014)
Expand Down Expand Up @@ -333,7 +333,7 @@ void USBDeviceClass::init()
#endif

/* Enable USB clock */
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
MCLK->APBBMASK.reg |= MCLK_APBBMASK_USB;
MCLK->AHBMASK.reg |= MCLK_AHBMASK_USB;

Expand Down Expand Up @@ -377,7 +377,7 @@ void USBDeviceClass::init()
usbd.setFullSpeed();

// Configure interrupts
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
/* Attach to the USB host */
NVIC_SetPriority(USB_0_IRQn, 0UL);
NVIC_SetPriority(USB_1_IRQn, 0UL);
Expand Down
13 changes: 7 additions & 6 deletions cores/arduino/USB/samd21_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "USB_host.h"
#include "samd21_host.h"
#include "sam.h"
#include "same5x_compat_shim.h"
#include "wiring_digital.h"
#include "wiring_private.h"

Expand Down Expand Up @@ -68,7 +69,7 @@ void UHD_Init(void)
USB_SetHandler(&UHD_Handler);

/* Enable USB clock */
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
MCLK->APBBMASK.reg |= MCLK_APBBMASK_USB;
#else
PM->APBBMASK.reg |= PM_APBBMASK_USB;
Expand All @@ -89,7 +90,7 @@ void UHD_Init(void)
* Put Generic Clock Generator 0 as source for Generic Clock Multiplexer 6 (USB reference)
*/

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
GCLK->PCHCTRL[USB_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
#else
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(6) | // Generic Clock Multiplexer 6
Expand All @@ -116,7 +117,7 @@ void UHD_Init(void)


/* Load Pad Calibration */
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
pad_transn = (*((uint32_t *)(NVMCTRL_SW0) // Non-Volatile Memory Controller
#else
pad_transn = (*((uint32_t *)(NVMCTRL_OTP4) // Non-Volatile Memory Controller
Expand All @@ -133,7 +134,7 @@ void UHD_Init(void)

USB->HOST.PADCAL.bit.TRANSN = pad_transn;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
pad_transp = (*((uint32_t *)(NVMCTRL_SW0)
#else
pad_transp = (*((uint32_t *)(NVMCTRL_OTP4)
Expand All @@ -149,7 +150,7 @@ void UHD_Init(void)

USB->HOST.PADCAL.bit.TRANSP = pad_transp;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
pad_trim = (*((uint32_t *)(NVMCTRL_SW0)
#else
pad_trim = (*((uint32_t *)(NVMCTRL_OTP4)
Expand Down Expand Up @@ -189,7 +190,7 @@ void UHD_Init(void)
USB->HOST.CTRLB.bit.VBUSOK = 1;

// Configure interrupts
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
NVIC_SetPriority((IRQn_Type)USB_0_IRQn, 0UL);
NVIC_SetPriority((IRQn_Type)USB_1_IRQn, 0UL);
NVIC_SetPriority((IRQn_Type)USB_2_IRQn, 0UL);
Expand Down
14 changes: 7 additions & 7 deletions cores/arduino/WInterrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void __initialize()
memset(ISRcallback, 0, sizeof(ISRcallback));
nints = 0;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
///EIC MCLK is enabled by default
for (uint32_t i = 0; i <= 15; i++) // EIC_0_IRQn = 12 ... EIC_15_IRQn = 27
{
Expand Down Expand Up @@ -63,7 +63,7 @@ static void __initialize()
*/

// Enable EIC
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
EIC->CTRLA.bit.ENABLE = 1;
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
#else
Expand Down Expand Up @@ -95,7 +95,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
}
uint32_t inMask = (1UL << in);
// Enable wakeup capability on pin in case being used during sleep
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
//I believe this is done automatically
#else
EIC->WAKEUP.reg |= (1 << in);
Expand Down Expand Up @@ -164,7 +164,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
pos = in << 2;
}

#if defined (__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
EIC->CTRLA.bit.ENABLE = 0;
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
#endif
Expand Down Expand Up @@ -197,7 +197,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
}

#if defined (__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
EIC->CTRLA.bit.ENABLE = 1;
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
#endif
Expand All @@ -221,7 +221,7 @@ void detachInterrupt(uint32_t pin)
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);

// Disable wakeup capability on pin during sleep
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
//I believe this is done automatically
#else
// Disable wakeup capability on pin during sleep
Expand Down Expand Up @@ -249,7 +249,7 @@ void detachInterrupt(uint32_t pin)
/*
* External Interrupt Controller NVIC Interrupt Handler
*/
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
void InterruptHandler(uint32_t unused_i)
{
(void)unused_i;
Expand Down
17 changes: 12 additions & 5 deletions cores/arduino/WVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ typedef enum _EAnalogChannel
ADC_Channel5=5,
ADC_Channel6=6,
ADC_Channel7=7,
#if defined __SAMD21J18A__ || defined(__SAMD51__)
#if defined __SAMD21J18A__ || defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
ADC_Channel8=8,
ADC_Channel9=9,
#endif // __SAMD21J18A__
ADC_Channel10=10,
ADC_Channel11=11,
#if defined __SAMD21J18A__ || defined(__SAMD51__)
#if defined __SAMD21J18A__ || defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
ADC_Channel12=12,
ADC_Channel13=13,
ADC_Channel14=14,
Expand All @@ -61,7 +61,14 @@ typedef enum _EAnalogChannel
ADC_Channel_PTAT=0x1C,
} EAnalogChannel ;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)

#ifndef TC_INST_NUM
#define TC_INST_NUM 8
#endif
#ifndef TCC_INST_NUM
#define TCC_INST_NUM 5
#endif

#if defined(__SAMD51G19A__) || defined(__SAME51G19A__)

Expand Down Expand Up @@ -307,7 +314,7 @@ typedef enum _EPioType
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
PIO_TCC_PDEC, /* The pin is controlled by the associated signal of peripheral G. */
PIO_COM, /* The pin is controlled by the associated signal of peripheral H. */
PIO_SDHC, /* The pin is controlled by the associated signal of peripheral I. */
Expand Down Expand Up @@ -341,7 +348,7 @@ typedef enum _EPioType
#define PIN_ATTR_EXTINT (1UL<<6)
#define PIN_ATTR_ANALOG_ALT (1UL<<7)

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
// these correspond to the mux table
#define PIN_ATTR_PWM_E (1UL<<3)
#define PIN_ATTR_PWM_F (1UL<<8)
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/avr/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef _IO_H_
#define _IO_H_

#ifdef __SAMD51__
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
#define RAMSTART (HSRAM_ADDR)
#define RAMSIZE (HSRAM_SIZE)
#else
Expand Down
8 changes: 5 additions & 3 deletions cores/arduino/cortex_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/

#include <sam.h>
#include "same5x_compat_shim.h"
#include <variant.h>
#include <stdio.h>

/* RTOS Hooks */
extern void svcHook(void);
extern void pendSVHook(void);
extern int sysTickHook(void);
extern void SystemInit(void);

/* Default empty handler */
void Dummy_Handler(void)
Expand All @@ -35,7 +37,7 @@ void Dummy_Handler(void)
for (;;) { }
}

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)

/* Cortex-M4 processor handlers */
void Reset_Handler ( void );
Expand Down Expand Up @@ -486,7 +488,7 @@ void Reset_Handler(void)
*pDest = 0;
}

#if defined(__FPU_USED) && defined(__SAMD51__)
#if defined(__FPU_USED) && (defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__))
/* Enable FPU */
SCB->CPACR |= (0xFu << 20);
__DSB();
Expand All @@ -513,7 +515,7 @@ void SysTick_Handler(void)

static void (*usb_isr)(void) = NULL;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
void USB_0_Handler(void)
{
if (usb_isr)
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ unsigned long micros( void )
// a runtime multiplication and shift, saving a few cycles
}

#ifdef __SAMD51__
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
/*
* On SAMD51, use the (32bit) cycle count maintained by the DWT unit,
* and count exact number of cycles elapsed, rather than guessing how
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern void delay( unsigned long dwMs ) ;
*
* \param dwUs the number of microseconds to pause (uint32_t)
*/
#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
extern void delayMicroseconds( unsigned int );
#else
static __inline__ void delayMicroseconds( unsigned int ) __attribute__((always_inline, unused)) ;
Expand Down
3 changes: 1 addition & 2 deletions cores/arduino/pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
uint32_t bit = 1 << p.ulPin;
uint32_t stateMask = state ? bit : 0;

#if defined(__SAMD51__)
#if defined(__SAMD51__) || defined(__SAME51__) || defined(__SAME53__) || defined(__SAME54__)
/*
* The SAMD51 is fast enough to use really obvious code (similar to
* what was used to produce pulse_asm.S, but using micros() for timing.
Expand Down Expand Up @@ -80,4 +80,3 @@ uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout)
return 0;
#endif // SAMD51
}

Loading
Loading