Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoGaius committed Nov 28, 2023
1 parent 21ac762 commit 36d981e
Show file tree
Hide file tree
Showing 22 changed files with 1,819 additions and 2,502 deletions.
2,349 changes: 35 additions & 2,314 deletions boards.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions bootloaders/metroM4/board_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "board_definitions_metro_m4.h"
#elif defined(BOARD_ID_FEATHER_M4)
#include "board_definitions_feather_m4.h"
#elif defined(BOARD_ID_P1AM_M4)
#include "board_definitions_p1am200_m4.h"
#else
#error You must define a BOARD_ID and add the corresponding definitions in board_definitions.h
#endif
Expand Down
83 changes: 83 additions & 0 deletions bootloaders/metroM4/board_definitions_p1am200_m4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _BOARD_DEFINITIONS_H_
#define _BOARD_DEFINITIONS_H_
/*
* USB device definitions
*/
#define STRING_PRODUCT "FACTS P1AM-200"
#define USB_VID_HIGH 0x13
#define USB_VID_LOW 0x54
#define USB_PID_HIGH 0x40
#define USB_PID_LOW 0x02


/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
#define BOOT_DOUBLE_TAP_ADDRESS (HSRAM_ADDR + HSRAM_SIZE - 4)
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *)BOOT_DOUBLE_TAP_ADDRESS))

/*
* If BOOT_LOAD_PIN is defined the bootloader is started if the selected
* pin is tied LOW.
*/
//#define BOOT_LOAD_PIN PIN_PA21 // Pin 7
//#define BOOT_LOAD_PIN PIN_PA15 // Pin 5

#define GPIO(port, pin) ((((port)&0x7u) << 5) + ((pin)&0x1Fu))

#define BOOK_USART_MASK APBAMASK
#define BOOT_USART_MODULE SERCOM0
#define BOOT_USART_BUS_CLOCK_INDEX MCLK_APBAMASK_SERCOM0
#define BOOT_GCLK_ID_CORE SERCOM0_GCLK_ID_CORE
#define BOOT_GCLK_ID_SLOW SERCOM0_GCLK_ID_SLOW
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
#define BOOT_USART_PAD3 PINMUX_UNUSED
#define BOOT_USART_PAD2 PINMUX_UNUSED

#define BOOT_USART_PAD1 PINMUX_PA10C_SERCOM0_PAD2
#define BOOT_USART_PAD0 PINMUX_PA11C_SERCOM0_PAD3

/* Master clock frequency */
#define CPU_FREQUENCY (48000000ul)
#define VARIANT_MCK CPU_FREQUENCY

/* Frequency of the board main oscillator */
#define VARIANT_MAINOSC (32768ul)

/* Calibration values for DFLL48 pll */
#define NVM_SW_CALIB_DFLL48M_COARSE_VAL (58)
#define NVM_SW_CALIB_DFLL48M_FINE_VAL (64)

#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (21)

#define BOARD_LEDRX_PORT (1)
#define BOARD_LEDRX_PIN (6)

#define BOARD_LEDTX_PORT (0)
#define BOARD_LEDTX_PIN (27)

#endif // _BOARD_DEFINITIONS_H_
Binary file not shown.
2 changes: 1 addition & 1 deletion cores/arduino/USB/USBAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class USBDeviceClass {
uint32_t sendControl(int /* ep */, const void *data, uint32_t len) { return sendControl(data, len); }
uint32_t recvControl(void *data, uint32_t len);
uint32_t sendConfiguration(uint32_t maxlen);
bool sendStringDescriptor(const uint8_t *string, uint32_t maxlen);
bool sendStringDescriptor(const uint8_t *string, uint8_t maxlen);
void initControl(int end);
uint8_t SendInterfaces(uint32_t* total);
void packMessages(bool val);
Expand Down
8 changes: 3 additions & 5 deletions cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ static EPHandler *epHandlers[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
// Send a USB descriptor string. The string is stored as a
// plain ASCII string but is sent out as UTF-16 with the
// correct 2-byte prefix
bool USBDeviceClass::sendStringDescriptor(const uint8_t *string, uint32_t maxlen)
bool USBDeviceClass::sendStringDescriptor(const uint8_t *string, uint8_t maxlen)
{
if (maxlen < 2)
return false;

uint8_t* buffer = (uint8_t*)malloc(maxlen);
uint8_t buffer[maxlen];
buffer[0] = strlen((const char*)string) * 2 + 2;
buffer[1] = 0x03;

Expand All @@ -126,9 +126,7 @@ bool USBDeviceClass::sendStringDescriptor(const uint8_t *string, uint32_t maxlen
buffer[i] = 0;
}

bool ret = USBDevice.sendControl(buffer, i);
free(buffer);
return ret;
return USBDevice.sendControl(buffer, i);
}

bool _dry_run = false;
Expand Down
165 changes: 26 additions & 139 deletions cores/arduino/WVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

#pragma once

#ifdef __SAME51J19A__
#include "same51j19a.h"
#endif

#include <stdint.h>
#include "sam.h"
#include <limits.h>
//#include <limits.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -39,18 +43,18 @@ typedef enum _EAnalogChannel
ADC_Channel5=5,
ADC_Channel6=6,
ADC_Channel7=7,
#if defined __SAMD21J18A__ || defined(__SAMD51__)
// #if defined __SAMD21J18A__ || defined(__SAMD51__)
ADC_Channel8=8,
ADC_Channel9=9,
#endif // __SAMD21J18A__
// #endif // __SAMD21J18A__
ADC_Channel10=10,
ADC_Channel11=11,
#if defined __SAMD21J18A__ || defined(__SAMD51__)
// #if defined __SAMD21J18A__ || defined(__SAMD51__)
ADC_Channel12=12,
ADC_Channel13=13,
ADC_Channel14=14,
ADC_Channel15=15,
#endif // __SAMD21J18A__
// #endif // __SAMD21J18A__
ADC_Channel16=16,
ADC_Channel17=17,
ADC_Channel18=18,
Expand All @@ -61,44 +65,14 @@ typedef enum _EAnalogChannel
ADC_Channel_PTAT=0x1C,
} EAnalogChannel ;

#if defined(__SAMD51__)

#if defined(__SAMD51G19A__)

typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),
TCC0_CH4 = (0<<8)|(4),
TCC0_CH5 = (0<<8)|(5),
TCC1_CH0 = (1<<8)|(0),
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(2),
TCC1_CH3 = (1<<8)|(3),
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(2),
TC0_CH0 = (3<<8)|(0),
TC0_CH1 = (3<<8)|(1),
TC1_CH0 = (4<<8)|(0),
TC1_CH1 = (4<<8)|(1),
TC2_CH0 = (5<<8)|(0),
TC2_CH1 = (5<<8)|(1),
TC3_CH0 = (6<<8)|(0),
TC3_CH1 = (6<<8)|(1),
} ETCChannel ;
#elif defined(__SAMD51J19A__) || defined(__SAMD51J20A__) || defined(__SAME51J19A__)

typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),

TCC0_CH4 = (0<<8)|(4),
TCC0_CH5 = (0<<8)|(5),
TCC0_CH6 = (0<<8)|(6),
Expand All @@ -107,13 +81,11 @@ typedef enum _ETCChannel
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(2),
TCC1_CH3 = (1<<8)|(3),
TCC1_CH4 = (1<<8)|(4),
TCC1_CH5 = (1<<8)|(5),
TCC1_CH6 = (1<<8)|(6),
TCC1_CH7 = (1<<8)|(7),
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(2),
TCC2_CH3 = (2<<8)|(3),

TCC3_CH0 = (3<<8)|(0),
TCC3_CH1 = (3<<8)|(1),
TCC4_CH0 = (4<<8)|(0),
Expand All @@ -124,6 +96,8 @@ typedef enum _ETCChannel
TC1_CH1 = (6<<8)|(1),
TC2_CH0 = (7<<8)|(0),
TC2_CH1 = (7<<8)|(1),
TC2_CH2 = (7<<8)|(2),
TC2_CH3 = (7<<8)|(3),
TC3_CH0 = (8<<8)|(0),
TC3_CH1 = (8<<8)|(1),
TC4_CH0 = (9<<8)|(0),
Expand All @@ -136,87 +110,15 @@ typedef enum _ETCChannel
TC7_CH1 = (12<<8)|(1),
} ETCChannel ;

#elif defined(__SAME53N20A__) || defined(__SAME53N19A__) || defined(__SAME54P20A__) || defined(__SAME54P19A__) || defined(__SAME54N20A__) || defined(__SAME54N19A__) || defined(__SAMD51P20A__) || defined(__SAMD51P19A__) || defined(__SAMD51N20A__) || defined(__SAMD51N19A__) || defined(__SAME51N20A__) || defined(__SAME51N19A__)

typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),
TCC0_CH4 = (0<<8)|(4),
TCC0_CH5 = (0<<8)|(5),
TCC1_CH0 = (1<<8)|(0),
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(2),
TCC1_CH3 = (1<<8)|(3),
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(2),
TCC3_CH0 = (3<<8)|(0),
TCC3_CH1 = (3<<8)|(1),
TCC4_CH0 = (4<<8)|(0),
TCC4_CH1 = (4<<8)|(1),
TC0_CH0 = (5<<8)|(0),
TC0_CH1 = (5<<8)|(1),
TC1_CH0 = (6<<8)|(0),
TC1_CH1 = (6<<8)|(1),
TC2_CH0 = (7<<8)|(0),
TC2_CH1 = (7<<8)|(1),
TC3_CH0 = (8<<8)|(0),
TC3_CH1 = (8<<8)|(1),
TC4_CH0 = (9<<8)|(0),
TC4_CH1 = (9<<8)|(1),
TC5_CH0 = (10<<8)|(0),
TC5_CH1 = (10<<8)|(1),
TC6_CH0 = (11<<8)|(0),
TC6_CH1 = (11<<8)|(1),
TC7_CH0 = (12<<8)|(0),
TC7_CH1 = (12<<8)|(1),
} ETCChannel ;

#endif

typedef ETCChannel EPWMChannel;
//typedef ETCChannel EPWMChannel;
extern const uint32_t GCLK_CLKCTRL_IDs[TCC_INST_NUM+TC_INST_NUM];

#define NOT_ON_PWM NOT_ON_TIMER
extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;

#define GetTCNumber( x ) ( (x) >> 8 )
#define GetTCChannelNumber( x ) ( (x) & 0xff )
#define GetTC( x ) ( g_apTCInstances[(x) >> 8] )

#else
// Definitions for TC channels
typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),
TCC0_CH4 = (0<<8)|(0), // Channel 4 is 0!
TCC0_CH5 = (0<<8)|(1), // Channel 5 is 1!
TCC0_CH6 = (0<<8)|(2), // Channel 6 is 2!
TCC0_CH7 = (0<<8)|(3), // Channel 7 is 3!
TCC1_CH0 = (1<<8)|(0),
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(0), // Channel 2 is 0!
TCC1_CH3 = (1<<8)|(1), // Channel 3 is 1!
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(0), // Channel 2 is 0!
TCC2_CH3 = (2<<8)|(1), // Channel 3 is 1!
TC3_CH0 = (3<<8)|(0),
TC3_CH1 = (3<<8)|(1),
TC4_CH0 = (4<<8)|(0),
TC4_CH1 = (4<<8)|(1),
TC5_CH0 = (5<<8)|(0),
TC5_CH1 = (5<<8)|(1),
#if defined (__SAMD21J18A__)
TC6_CH0 = (6<<8)|(0),
TC6_CH1 = (6<<8)|(1),
TC7_CH0 = (7<<8)|(0),
TC7_CH1 = (7<<8)|(1),
#endif // __SAMD21J18A__
} ETCChannel ;

// Definitions for PWM channels
typedef enum _EPWMChannel
Expand Down Expand Up @@ -244,21 +146,15 @@ typedef enum _EPWMChannel
PWM4_CH1=TC4_CH1,
PWM5_CH0=TC5_CH0,
PWM5_CH1=TC5_CH1,
#if defined(__SAMD21J18A__)
// #if defined(__SAMD21J18A__)
PWM6_CH0=TC6_CH0,
PWM6_CH1=TC6_CH1,
PWM7_CH0=TC7_CH0,
PWM7_CH1=TC7_CH1,
#endif // __SAMD21J18A__
} EPWMChannel ;
// #endif // __SAMD21J18A__

#endif

extern const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM] ;
} EPWMChannel ;

#define GetTCNumber( x ) ( (x) >> 8 )
#define GetTCChannelNumber( x ) ( (x) & 0xff )
#define GetTC( x ) ( g_apTCInstances[(x) >> 8] )

typedef enum _EPortType
{
Expand Down Expand Up @@ -307,19 +203,16 @@ 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__)

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_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. */
PIO_I2S, /* The pin is controlled by the associated signal of peripheral J. */
PIO_PCC, /* The pin is controlled by the associated signal of peripheral K. */
PIO_GMAC, /* The pin is controlled by the associated signal of peripheral L. */
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral M. */
PIO_CCL, /* The pin is controlled by the associated signal of peripheral N. */
#else
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
#endif

PIO_DIGITAL, /* The pin is controlled by PORT. */
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
Expand All @@ -340,15 +233,9 @@ typedef enum _EPioType
#define PIN_ATTR_TIMER_ALT (1UL<<5)
#define PIN_ATTR_EXTINT (1UL<<6)
#define PIN_ATTR_ANALOG_ALT (1UL<<7)

#if defined(__SAMD51__)
// these correspond to the mux table
#define PIN_ATTR_PWM_E (1UL<<3)
#define PIN_ATTR_PWM_F (1UL<<8)
#define PIN_ATTR_PWM_G (1UL<<9)
#else
#define PIN_ATTR_PWM (1UL<<3)
#endif

/* Types used for the table below */
typedef struct _PinDescription
Expand Down
Loading

0 comments on commit 36d981e

Please sign in to comment.