Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/adafruit-metro-m4-express: initial port #20912

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
13 changes: 13 additions & 0 deletions boards/adafruit-metro-m4-express/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.

config BOARD
default "adafruit-metro-m4-express" if BOARD_ADAFRUIT_METRO_M4_EXPRESS

config BOARD_ADAFRUIT_METRO_M4_EXPRESS
bool
default y
select CPU_MODEL_SAMD51J19
5 changes: 5 additions & 0 deletions boards/adafruit-metro-m4-express/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = board

DIRS = $(RIOTBOARD)/common/samdx1-arduino-bootloader

include $(RIOTBASE)/Makefile.base
17 changes: 17 additions & 0 deletions boards/adafruit-metro-m4-express/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

# default to using littlefs2 on QSPI flash
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEPKG += littlefs2
USEMODULE += mtd
endif

ifneq (,$(filter mtd,$(USEMODULE)))
FEATURES_REQUIRED += periph_spi_on_qspi
USEMODULE += mtd_spi_nor
endif

# setup the samd21 arduino bootloader related dependencies
include $(RIOTBOARD)/common/samdx1-arduino-bootloader/Makefile.dep
21 changes: 21 additions & 0 deletions boards/adafruit-metro-m4-express/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CPU = samd5x
CPU_MODEL = samd51j19a

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += highlevel_stdio
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_dac
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_usbdev

# other board features
FEATURES_PROVIDED += arduino_analog
FEATURES_PROVIDED += arduino_pins
FEATURES_PROVIDED += arduino_shield_isp
FEATURES_PROVIDED += arduino_shield_uno
FEATURES_PROVIDED += arduino_spi
6 changes: 6 additions & 0 deletions boards/adafruit-metro-m4-express/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CFLAGS += -DBOOTLOADER_UF2

# Include all definitions for flashing with bossa other USB
include $(RIOTBOARD)/common/samdx1-arduino-bootloader/Makefile.include
# Include handling of serial and non-bossa programmers (if selected by user)
include $(RIOTMAKE)/boards/sam0.inc.mk
65 changes: 65 additions & 0 deletions boards/adafruit-metro-m4-express/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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_adafruit-metro-m4-express
* @{
*
* @file
* @brief Board specific implementations for the Adafruit Metro M4 Express
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
* @}
*/

#include "board.h"
#include "periph/gpio.h"
#include "timex.h"
#ifdef MODULE_VFS_DEFAULT
#include "vfs_default.h"
#endif

#ifdef MODULE_MTD_SPI_NOR

#include "mtd_spi_nor.h"

/* GD25Q16C */
static const mtd_spi_nor_params_t _samd51_nor_params = {
.opcode = &mtd_spi_nor_opcode_default,
.wait_chip_erase = 25 * US_PER_SEC,
.wait_32k_erase = 150 * US_PER_MS,
.wait_64k_erase = 200 * US_PER_MS,
.wait_sector_erase = 50 * US_PER_MS,
.wait_chip_wake_up = 10 * US_PER_MS,
.clk = MHZ(54),
.flag = SPI_NOR_F_SECT_4K
| SPI_NOR_F_SECT_32K
| SPI_NOR_F_SECT_64K,
.spi = SPI_DEV(SPI_NUMOF - 1),
.mode = SPI_MODE_0,
.cs = SAM0_QSPI_PIN_CS,
.wp = SAM0_QSPI_PIN_DATA_2,
.hold = SAM0_QSPI_PIN_DATA_3,
};

static mtd_spi_nor_t samd51_nor_dev = {
.base = {
.driver = &mtd_spi_nor_driver,
.page_size = 256,
.pages_per_sector = 16,
},
.params = &_samd51_nor_params,
};

MTD_XFA_ADD(samd51_nor_dev, 0);

#ifdef MODULE_VFS_DEFAULT
VFS_AUTO_MOUNT(littlefs2, VFS_MTD(samd51_nor_dev), VFS_DEFAULT_NVM(0), 0);
#endif

#endif /* MODULE_MTD_SPI_NOR */
2 changes: 2 additions & 0 deletions boards/adafruit-metro-m4-express/dist/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source [find target/atsame5x.cfg]
$_TARGETNAME configure -rtos auto
71 changes: 71 additions & 0 deletions boards/adafruit-metro-m4-express/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
@defgroup boards_adafruit-metro-m4-express Adafruit Metro M4 Express
@ingroup boards
@brief Support for the Adafruit Metro M4 Express

General information
===================

@image html https://cdn-learn.adafruit.com/assets/assets/000/085/521/large1024/adafruit_products_metro-m4-top.jpg "Picture of the Adafruit Metro M4 Express"

The main features of the board are:
- ATSAMD51 Cortex M4 running at 120 MHz
- Hardware DSP and floating point support
- 512 MiB Flash
- 192 KiB KiB RAM
- external 2 MiB QSPI Flash storage
- WS281x RGB LED (NeoPixel)
- 32-bit, 3.3V logic and power
- native USB

Pinout
------

@image html https://cdn-learn.adafruit.com/assets/assets/000/111/183/original/adafruit_products_Adafruit_Metro_M4_Express_Pinout.png "Official Pinout of the Metro M4 Express" width=100%

Links
=====

- [Official Board Documentation](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51)

Schematics
==========

@image html https://cdn-learn.adafruit.com/assets/assets/000/053/093/original/adafruit_products_schem.png "Original Board Schematics"

Arduino Compatibility
=====================

The board is compatible with Shields for the Arduino UNO / Arduino Zero.

@warning The SPI bus on D11/D12/D13 is only available when `periph_uart` is
not used, as this pins are connected to the same SERCOM peripheral.
This is board design flaw that we cannot work around unless
resorting to desperate means such as bit-banging either the SPI bus
or the UART interface.

Flash the board
===============

The board is flashed using its on-board
[boot loader](https://github.com/adafruit/uf2-samdx1).

The process is automated in the usual `make flash` target.

If RIOT is already running on the board, it will automatically reset the CPU
and enter the bootloader. If some other firmware is running or RIOT crashed,
you need to enter the bootloader manually by double tapping the board's reset
button.

Readiness of the bootloader is indicated by LED pulsing in red.

@note You may need to pass `MOST_RECENT_PORT=0` and manually pass the `PORT`
if you enter the bootloader by hand.

Accessing STDIO
---------------

The usual way to obtain a console on this board is using an emulated USB serial
port.

*/
118 changes: 118 additions & 0 deletions boards/adafruit-metro-m4-express/include/arduino_iomap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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_adafruit-metro-m4-express
* @{
*
* @file
* @brief Mapping from MCU pins to Arduino pins
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*/

#ifndef ARDUINO_IOMAP_H
#define ARDUINO_IOMAP_H

#include "periph/gpio.h"
#include "periph/adc.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Mapping of MCU pins to Arduino pins
* @{
*/
#define ARDUINO_PIN_0 GPIO_PIN(PA, 23)
#define ARDUINO_PIN_1 GPIO_PIN(PA, 22)
#define ARDUINO_PIN_2 GPIO_PIN(PB, 17)
#define ARDUINO_PIN_3 GPIO_PIN(PB, 16)
#define ARDUINO_PIN_4 GPIO_PIN(PB, 13)
#define ARDUINO_PIN_5 GPIO_PIN(PB, 14)
#define ARDUINO_PIN_6 GPIO_PIN(PB, 15)
#define ARDUINO_PIN_7 GPIO_PIN(PB, 12)

#define ARDUINO_PIN_8 GPIO_PIN(PA, 21)
#define ARDUINO_PIN_9 GPIO_PIN(PA, 20)
#define ARDUINO_PIN_10 GPIO_PIN(PA, 18)
#define ARDUINO_PIN_11 GPIO_PIN(PA, 19)
#define ARDUINO_PIN_12 GPIO_PIN(PA, 17)
#define ARDUINO_PIN_13 GPIO_PIN(PA, 16)

/* SDA and SCL */
#define ARDUINO_PIN_14 GPIO_PIN(PB, 2) /* SDA */
#define ARDUINO_PIN_15 GPIO_PIN(PB, 3) /* SCL */

/* Analog pins as digital pins: */
#define ARDUINO_PIN_16 GPIO_PIN(PA, 2) /* A0 */
#define ARDUINO_PIN_17 GPIO_PIN(PA, 5) /* A1 */
#define ARDUINO_PIN_18 GPIO_PIN(PA, 6) /* A2 */
#define ARDUINO_PIN_19 GPIO_PIN(PA, 4) /* A3 */
#define ARDUINO_PIN_20 GPIO_PIN(PB, 8) /* A4 */
#define ARDUINO_PIN_21 GPIO_PIN(PB, 9) /* A5 */

#define ARDUINO_PIN_LAST 21
/** @} */

/**
* @name Aliases for non-digital pins as digital pins
* @{
*/
#define ARDUINO_PIN_SDA ARDUINO_PIN_14
#define ARDUINO_PIN_SCL ARDUINO_PIN_15
#define ARDUINO_PIN_A0 ARDUINO_PIN_16
#define ARDUINO_PIN_A1 ARDUINO_PIN_17
#define ARDUINO_PIN_A2 ARDUINO_PIN_18
#define ARDUINO_PIN_A3 ARDUINO_PIN_19
#define ARDUINO_PIN_A4 ARDUINO_PIN_20
#define ARDUINO_PIN_A5 ARDUINO_PIN_21
/** @} */

/**
* @name Mapping of Arduino analog pins to RIOT ADC lines
* @{
*/
#define ARDUINO_A0 ADC_LINE(0)
#define ARDUINO_A1 ADC_LINE(1)
#define ARDUINO_A2 ADC_LINE(2)
#define ARDUINO_A3 ADC_LINE(3)
#define ARDUINO_A4 ADC_LINE(4)
#define ARDUINO_A5 ADC_LINE(5)

#define ARDUINO_ANALOG_PIN_LAST 5
/** @} */

/**
* @name Arduino's default SPI device
* @{
*/
/**
* @brief SPI_DEV(0) is connected to the ISP header
*/
#define ARDUINO_SPI_ISP SPI_DEV(0)

/**
* @brief SPI_DEV(1) is connected to D11/D12/D13
*
* The SPI on D11/D12/D13 is only available when `periph_uart` is not used due
* to a conflicting use of the same SERCOM. If it is available, it is the last
* SPI bus.
*/
#if !MODULE_PERIPH_UART
# define ARDUINO_SPI_D11D12D13 SPI_DEV(1)
#endif
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* ARDUINO_IOMAP_H */
/** @} */
Loading
Loading