diff --git a/boards/same51-curiosity-nano/Makefile b/boards/same51-curiosity-nano/Makefile new file mode 100644 index 000000000000..f8fcbb53a065 --- /dev/null +++ b/boards/same51-curiosity-nano/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/same51-curiosity-nano/Makefile.dep b/boards/same51-curiosity-nano/Makefile.dep new file mode 100644 index 000000000000..5472bf8b8d8f --- /dev/null +++ b/boards/same51-curiosity-nano/Makefile.dep @@ -0,0 +1,3 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio +endif diff --git a/boards/same51-curiosity-nano/Makefile.features b/boards/same51-curiosity-nano/Makefile.features new file mode 100644 index 000000000000..7f67cf76fd38 --- /dev/null +++ b/boards/same51-curiosity-nano/Makefile.features @@ -0,0 +1,19 @@ +CPU = samd5x +CPU_MODEL = same51j20a + +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_dac +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_rtc +FEATURES_PROVIDED += periph_rtt +FEATURES_PROVIDED += periph_pwm +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart +FEATURES_PROVIDED += periph_uart_hw_fc +FEATURES_PROVIDED += periph_adc +FEATURES_PROVIDED += periph_can + +# Put other features for this board (in alphabetical order) +FEATURES_PROVIDED += riotboot +FEATURES_PROVIDED += tinyusb_device diff --git a/boards/same51-curiosity-nano/Makefile.include b/boards/same51-curiosity-nano/Makefile.include new file mode 100644 index 000000000000..a5c002804cfc --- /dev/null +++ b/boards/same51-curiosity-nano/Makefile.include @@ -0,0 +1,8 @@ +# If port selection via ttys.py is enabled by `MOST_RECENT_PORT=1`, filter +# USB serials to only select the UART bridge of the embedded EDBG CMSIS-DAP +# debugger. +TTY_BOARD_FILTER := --model 'nEDBG CMSIS-DAP' + +PROGRAMMER ?= openocd + +include $(RIOTMAKE)/boards/sam0.inc.mk diff --git a/boards/same51-curiosity-nano/dist/openocd.cfg b/boards/same51-curiosity-nano/dist/openocd.cfg new file mode 100644 index 000000000000..c8d9f3b90d22 --- /dev/null +++ b/boards/same51-curiosity-nano/dist/openocd.cfg @@ -0,0 +1,2 @@ +source [find target/atsame5x.cfg] +$_TARGETNAME configure -rtos auto diff --git a/boards/same51-curiosity-nano/doc.txt b/boards/same51-curiosity-nano/doc.txt new file mode 100644 index 000000000000..421297163960 --- /dev/null +++ b/boards/same51-curiosity-nano/doc.txt @@ -0,0 +1,86 @@ +/** +@defgroup boards_same51-curiosity-nano Microchip SAM E51 Curiosity Nano +@ingroup boards +@brief Support for the Microchip SAM E51 Curiosity Nano board. + +## Overview + +The `SAM E51 Curiosity Nano` is an evaluation board by Microchip featuring an +ATSAME51J20A SoC. The SoC includes a SAM E51 ARM Cortex-M4F microcontroller. +For programming the MCU comes with 256Kb of RAM and 1024Kb of flash memory. + +The `same51-curiosity-nano` is available from various hardware vendors for ~15$ +(as of 2024 December). + +## Hardware + +![same51-curiosity-nano image](https://www.microchip.com/content/dam/mchp/mrt-dam/devtools/3368-200511-mcu32-ev76s68a-sam-e51-curiosity-nano.jpg) + + +### MCU +| MCU | ATSAME51J20A | +|:------------ |:--------------------- | +| Family | ARM Cortex-M4F | +| Vendor | Microchip | +| RAM | 256Kb | +| Flash | 1024Kb | +| Frequency | up to 120MHz | +| FPU | yes | +| Timers | 8 (16-bit) | +| ADCs | 2x 12-bit (20 channels) | +| UARTs | max 6 (shared with SPI and I2C) | +| SPIs | max 6 (see UART) | +| I2Cs | max 6 (see UART) | +| Vcc | 1.62V - 3.63V | +| Datasheet | [Datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf) | +| Board Manual | [Board Manual](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU32/ProductDocuments/UserGuides/SAM-E51-Curiosity-Nano-User-Guide-DS70005432.pdf)| + +### User Interface + +1 User button and 1 LED: + +| Device | PIN | +|:------------ |:---- | +| LED0 | PA14 | +| SW0 (button) | PA15 | + + +## Implementation Status + +| Device | ID | Supported | Comments | +|:---------------- |:--------- |:--------- |:--------- | +| MCU | same51 | yes | | +| Low-level driver | GPIO | yes | | +| | ADC | yes | | +| | CAN | yes | | +| | DAC | yes | | +| | PWM | yes | | +| | UART | yes | | +| | I2C | yes | | +| | SPI | yes | | +| | USB | yes | | +| | RTT | yes | | +| | RTC | yes | | +| | RNG | yes | | +| | Timer | yes | | + + +## Flashing the device + +Connect the device to your Micro-USB cable using the port labeled as +*DEBUG USB*. + +The standard method for flashing RIOT to the board is using OpenOCD. +by calling: `make BOARD=same51-curiosity-nano -C tests/leds flash` + +On Linux you will have to add a **udev** rule for hidraw, like +``` +bash +echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"' \ + | sudo tee -a /etc/udev/rules.d/99-usb.rules +sudo service udev restart +``` + +## Known Issues / Problems + + */ diff --git a/boards/same51-curiosity-nano/include/board.h b/boards/same51-curiosity-nano/include/board.h new file mode 100644 index 000000000000..40829c1033f4 --- /dev/null +++ b/boards/same51-curiosity-nano/include/board.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_same51-curiosity-nano + * @{ + * + * @file + * @brief Board specific definitions for the Microchip SAM E51 Curiosity Nano + * board + * + * @author Benjamin Valentin + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "periph/gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LED pin definitions and handlers + * @{ + */ +#define LED0_PIN GPIO_PIN(PA, 14) + +#define LED_PORT PORT->Group[PA] +#define LED0_MASK (1 << 14) + +#define LED0_ON (LED_PORT.OUTCLR.reg = LED0_MASK) +#define LED0_OFF (LED_PORT.OUTSET.reg = LED0_MASK) +#define LED0_TOGGLE (LED_PORT.OUTTGL.reg = LED0_MASK) +/** @} */ + +/** + * @name SW0 (Button) pin definitions + * @{ + */ +#define BTN0_PIN GPIO_PIN(PA, 15) +#define BTN0_MODE GPIO_IN_PU +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/same51-curiosity-nano/include/gpio_params.h b/boards/same51-curiosity-nano/include/gpio_params.h new file mode 100644 index 000000000000..2f456bae1cb2 --- /dev/null +++ b/boards/same51-curiosity-nano/include/gpio_params.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_same51-curiosity-nano + * @{ + * + * @file + * @brief Board specific configuration of direct mapped GPIOs + * + * @author Benjamin Valentin + */ + +#ifndef GPIO_PARAMS_H +#define GPIO_PARAMS_H + +#include "board.h" +#include "saul/periph.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief GPIO pin configuration + */ +static const saul_gpio_params_t saul_gpio_params[] = +{ + { + .name = "LED(orange)", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INVERTED + }, + { + .name = "Button(SW0)", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + .flags = SAUL_GPIO_INVERTED + }, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/same51-curiosity-nano/include/periph_conf.h b/boards/same51-curiosity-nano/include/periph_conf.h new file mode 100644 index 000000000000..892750c2d36d --- /dev/null +++ b/boards/same51-curiosity-nano/include/periph_conf.h @@ -0,0 +1,349 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_same51-curiosity-nano + * @{ + * + * @file + * @brief Configuration of CPU peripherals for the Microchip SAM E51 + * Curiosity Nano board + * + * @author Benjamin Valentin + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#include "periph_cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name desired core clock frequency + * @{ + */ +#ifndef CLOCK_CORECLOCK +#define CLOCK_CORECLOCK MHZ(120) +#endif +/** @} */ + +/** + * @name 32kHz Oscillator configuration + * @{ + */ +#define EXTERNAL_OSC32_SOURCE 1 +#define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0 +/** @} */ + +/** + * @brief Enable the internal DC/DC converter + * The board is equipped with the necessary inductor. + */ +#define USE_VREG_BUCK (1) + +/** + * @name Timer peripheral configuration + * @{ + */ +static const tc32_conf_t timer_config[] = { + { /* Timer 0 - System Clock */ + .dev = TC0, + .irq = TC0_IRQn, + .mclk = &MCLK->APBAMASK.reg, + .mclk_mask = MCLK_APBAMASK_TC0 | MCLK_APBAMASK_TC1, + .gclk_id = TC0_GCLK_ID, + .gclk_src = SAM0_GCLK_TIMER, + .flags = TC_CTRLA_MODE_COUNT32, + }, + { /* Timer 1 */ + .dev = TC2, + .irq = TC2_IRQn, + .mclk = &MCLK->APBBMASK.reg, + .mclk_mask = MCLK_APBBMASK_TC2 | MCLK_APBBMASK_TC3, + .gclk_id = TC2_GCLK_ID, + .gclk_src = SAM0_GCLK_TIMER, + .flags = TC_CTRLA_MODE_COUNT32, + } +}; + +/* Timer 0 configuration */ +#define TIMER_0_CHANNELS 2 +#define TIMER_0_ISR isr_tc0 + +/* Timer 1 configuration */ +#define TIMER_1_CHANNELS 2 +#define TIMER_1_ISR isr_tc2 + +#define TIMER_NUMOF ARRAY_SIZE(timer_config) +/** @} */ + +/** + * @name CAN configuration + * @{ + */ +/** Available CAN interfaces */ +static const can_conf_t candev_conf[] = { + { + .can = CAN0, + .rx_pin = GPIO_PIN(PA, 22), + .tx_pin = GPIO_PIN(PB, 23), + .gclk_src = SAM0_GCLK_PERIPH, + }, + { + .can = CAN1, + .rx_pin = GPIO_PIN(PB, 15), + .tx_pin = GPIO_PIN(PB, 14), + .gclk_src = SAM0_GCLK_PERIPH, + } +}; + +/** CAN 0 ISR configuration */ +#define ISR_CAN0 isr_can0 + +/** CAN 1 ISR configuration */ +#define ISR_CAN1 isr_can1 + +/** Number of CAN interfaces */ +#define CAN_NUMOF ARRAY_SIZE(candev_conf) +/** @} */ + +/** + * @name UART configuration + * @{ + */ +static const uart_conf_t uart_config[] = { + { /* Virtual COM Port */ + .dev = &SERCOM5->USART, + .rx_pin = GPIO_PIN(PB, 16), + .tx_pin = GPIO_PIN(PB, 17), + .mux = GPIO_MUX_C, + .rx_pad = UART_PAD_RX_1, + .tx_pad = UART_PAD_TX_0, + .flags = UART_FLAG_NONE, + .gclk_src = SAM0_GCLK_PERIPH, + }, + { /* shared with CAN1 */ + .dev = &SERCOM4->USART, + .rx_pin = GPIO_PIN(PB, 13), + .tx_pin = GPIO_PIN(PB, 12), +#ifdef MODULE_PERIPH_UART_HW_FC + .rts_pin = GPIO_PIN(PB, 14), + .cts_pin = GPIO_PIN(PB, 15), +#endif + .mux = GPIO_MUX_C, + .rx_pad = UART_PAD_RX_1, +#ifdef MODULE_PERIPH_UART_HW_FC + .tx_pad = UART_PAD_TX_0_RTS_2_CTS_3, +#else + .tx_pad = UART_PAD_TX_0, +#endif + .flags = UART_FLAG_NONE, + .gclk_src = SAM0_GCLK_PERIPH, + }, + { + .dev = &SERCOM0->USART, + .rx_pin = GPIO_PIN(PA, 9), + .tx_pin = GPIO_PIN(PA, 8), +#ifdef MODULE_PERIPH_UART_HW_FC + .rts_pin = GPIO_PIN(PA, 10), + .cts_pin = GPIO_PIN(PA, 10), +#endif + .mux = GPIO_MUX_C, + .rx_pad = UART_PAD_RX_1, +#ifdef MODULE_PERIPH_UART_HW_FC + .tx_pad = UART_PAD_TX_0_RTS_2_CTS_3, +#else + .tx_pad = UART_PAD_TX_0, +#endif + .flags = UART_FLAG_NONE, + .gclk_src = SAM0_GCLK_PERIPH, + }, + { /* shared with CAN0 */ + .dev = &SERCOM3->USART, + .rx_pin = GPIO_PIN(PA, 23), + .tx_pin = GPIO_PIN(PA, 22), + .mux = GPIO_MUX_C, + .rx_pad = UART_PAD_RX_1, + .tx_pad = UART_PAD_TX_0, + .flags = UART_FLAG_NONE, + .gclk_src = SAM0_GCLK_PERIPH, + } +}; + +/* interrupt function name mapping */ +#define UART_0_ISR isr_sercom5_2 +#define UART_0_ISR_TX isr_sercom5_0 + +#define UART_1_ISR isr_sercom4_2 +#define UART_1_ISR_TX isr_sercom4_0 + +#define UART_2_ISR isr_sercom0_2 +#define UART_2_ISR_TX isr_sercom0_0 + +#define UART_3_ISR isr_sercom3_2 +#define UART_3_ISR_TX isr_sercom3_0 + +#define UART_NUMOF ARRAY_SIZE(uart_config) +/** @} */ + +/** + * @name PWM configuration + * @{ + */ + +/* PWM0 channels */ +static const pwm_conf_chan_t pwm_chan0_config[] = { + /* GPIO pin, MUX value, TCC channel */ + { + .pin = GPIO_PIN(PA, 14), /* LED0 */ + .mux = GPIO_MUX_F, + .chan = 0, + }, +}; + +/* PWM device configuration */ +static const pwm_conf_t pwm_config[] = { + { + .tim = TCC_CONFIG(TCC2), + .chan = pwm_chan0_config, + .chan_numof = ARRAY_SIZE(pwm_chan0_config), + .gclk_src = SAM0_GCLK_48MHZ, + }, +}; + +/* number of devices that are actually defined */ +#define PWM_NUMOF ARRAY_SIZE(pwm_config) +/** @} */ + +/** + * @name SPI configuration + * @{ + */ +static const spi_conf_t spi_config[] = { + { + .dev = &SERCOM1->SPI, + .miso_pin = GPIO_PIN(PA, 19), + .mosi_pin = GPIO_PIN(PA, 16), + .clk_pin = GPIO_PIN(PA, 27), + .miso_mux = GPIO_MUX_C, + .mosi_mux = GPIO_MUX_C, + .clk_mux = GPIO_MUX_C, + .miso_pad = SPI_PAD_MISO_3, + .mosi_pad = SPI_PAD_MOSI_0_SCK_1, + .gclk_src = SAM0_GCLK_PERIPH, +#ifdef MODULE_PERIPH_DMA + .tx_trigger = SERCOM1_DMAC_ID_TX, + .rx_trigger = SERCOM1_DMAC_ID_RX, +#endif + + }, +}; + +#define SPI_NUMOF ARRAY_SIZE(spi_config) +/** @} */ + +/** + * @name I2C configuration + * @{ + */ +static const i2c_conf_t i2c_config[] = { + { + .dev = &SERCOM2->I2CM, + .speed = I2C_SPEED_NORMAL, + .scl_pin = GPIO_PIN(PA, 13), + .sda_pin = GPIO_PIN(PA, 12), + .mux = GPIO_MUX_C, + .gclk_src = SAM0_GCLK_PERIPH, + .flags = I2C_FLAG_NONE + }, +}; + +#define I2C_NUMOF ARRAY_SIZE(i2c_config) +/** @} */ + +/** + * @name RTT configuration + * @{ + */ +#ifndef RTT_FREQUENCY +#define RTT_FREQUENCY (32768U) +#endif +/** @} */ + +/** + * @name USB peripheral configuration + * + * Pins are only routed to solder pads on the board, no connector populated + * @{ + */ +static const sam0_common_usb_config_t sam_usbdev_config[] = { + { + .dm = GPIO_PIN(PA, 24), + .dp = GPIO_PIN(PA, 25), + .d_mux = GPIO_MUX_H, + .device = &USB->DEVICE, + .gclk_src = SAM0_GCLK_PERIPH, + } +}; +/** @} */ + +/** + * @name ADC Configuration + * @{ + */ + +/* ADC Default values */ +#define ADC_GCLK_SRC SAM0_GCLK_PERIPH /**< clock used for ADC */ +#define ADC_PRESCALER ADC_CTRLA_PRESCALER_DIV8 + +#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u) +#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1 + +static const adc_conf_chan_t adc_channels[] = { + /* inputctrl, dev */ + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA07, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA04, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB09, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA11, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA10, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB08, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB03, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA02, .dev = ADC0 }, + { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB04, .dev = ADC1 }, + { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB05, .dev = ADC1 }, + { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB06, .dev = ADC1 }, + { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB07, .dev = ADC1 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB01, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB00, .dev = ADC0 }, + { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA03, .dev = ADC0 }, +}; + +#define ADC_NUMOF ARRAY_SIZE(adc_channels) +/** @} */ + +/** + * @name DAC configuration + * @{ + */ + /* Must not exceed 12 MHz */ +#define DAC_CLOCK SAM0_GCLK_TIMER + /* Use external reference voltage on PA03 */ + /* (You have to manually connect PA03 with Vcc) */ + /* Internal reference only gives 1V */ +#define DAC_VREF DAC_CTRLB_REFSEL_VREFPU +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ +/** @} */