add nuttx for develop

This commit is contained in:
Wang_Weigen 2021-06-17 15:07:37 +08:00
commit 36f3e40c55
6759 changed files with 1528143 additions and 182 deletions

View File

@ -1,7 +1,7 @@
SRC_DIR := switch_api posix_support
SRC_DIR := posix_support
# # ifeq ($(CONFIG_SEPARATE_COMPILE),y)
# SRC_DIR += switch_api
# # endif
ifeq ($(CONFIG_SEPARATE_COMPILE),y)
SRC_DIR += switch_api
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,4 +0,0 @@
config POSIX_API
bool "support posix api"
default n

View File

@ -1,21 +1,3 @@
# ifeq ($(CONFIG_POSIX_API),y)
# SRC_FILES += pthread.c
# ifeq ($(CONFIG_KERNEL_SEMAPHORE),y)
# SRC_FILES += semaphore.c
# endif
# ifeq ($(CONFIG_KERNEL_MUTEX),y)
# SRC_FILES += pthread_mutex.c
# endif
# ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
# SRC_FILES += mqueue.c
# endif
# else
# SRC_FILES :=
# endif
SRC_FILES := pthread.c semaphore.c pthread_mutex.c mqueue.c

View File

@ -1,3 +1,3 @@
SRC_FILES := stdio.c fs_syscalls.c mem_syscalls.c
SRC_FILES := fs_syscalls.c mem_syscalls.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
/**
* @file stdio.c
* @brief support newlib stdio
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-25
*/
/*************************************************
File name: stdio.c
Description: support newlib stdio
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/stdio.c for references
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
History:
1. Date: 2021-04-25
Author: AIIT XUOS Lab
Modification: Use set and get console functions
*************************************************/
#include <libc.h>
#include <stdio.h>
#include <stdlib.h>
#define STDIO_DEVICE_NAME_MAX 32
static FILE* std_console = NULL;
/**
* This function will set system console device.
*
* @param device_name the name of device
* @param mode the mode
*
* @return file number on success; or -1 on failure
*/
int LibcStdioSetConsole(const char* device_name, int mode)
{
FILE *fp;
char name[STDIO_DEVICE_NAME_MAX];
char *file_mode;
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
switch (mode)
{
case O_RDWR:
file_mode = "r+";
break;
case O_WRONLY:
file_mode = "wb";
break;
default:
file_mode = "rb";
break;
}
/* try to open file */
fp = fopen(name, file_mode);
if (fp)
{
/* set the fp buffer */
setvbuf(fp, NULL, _IONBF, 0);
if (std_console)
/* try to close console device */
fclose(std_console);
std_console = fp;
if (mode == O_RDWR)
{
/* set _stdin as std_console */
_GLOBAL_REENT->_stdin = std_console;
}
else
{
/* set NULL */
_GLOBAL_REENT->_stdin = NULL;
}
if (mode == O_RDONLY)
{
/* set the _stdout as NULL */
_GLOBAL_REENT->_stdout = NULL;
/* set the _stderr as NULL */
_GLOBAL_REENT->_stderr = NULL;
}
else
{
/* set the _stdout as std_console */
_GLOBAL_REENT->_stdout = std_console;
/* set the _stderr as std_console */
_GLOBAL_REENT->_stderr = std_console;
}
/* set the __sdidinit as 1 */
_GLOBAL_REENT->__sdidinit = 1;
}
if (std_console)
/* return the file number */
return fileno(std_console);
/* failure and return -1 */
return -1;
}
/**
* This function will get system console device.
*
* @return file number on success; or -1 on failure
*/
int LibcStdioGetConsole(void) {
if (std_console)
/* return the file number */
return fileno(std_console);
else
/* failure and return -1 */
return -1;
}
/**
* This function will initialize the c library system.
*
* @return 0
*/
int LibcSystemInit(void)
{
#if defined(KERNEL_CONSOLE)
HardwareDevType console;
/* try to get console device */
console = ObtainConsole();
if (console)
{
#if defined(LIB_POSIX)
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_RDWR);
#else
/* set console device mode */
LibcStdioSetConsole(console->dev_name, O_WRONLY);
#endif
}
#endif
return 0;
}

View File

@ -0,0 +1 @@
this is readme

View File

@ -0,0 +1,8 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_ARDUINO_M0
endif

View File

@ -0,0 +1,149 @@
README
======
This README discusses issues unique to NuttX configurations for the
Arduino M0. I used a compatible board called Wemos SAMD21 M0 board,
but there are other equivalent boards, like the RobotDyn SAMD21 M0.
Unfortunately because the Arduino.cc vs Arduino.org conflict in the past,
we have three types of boards: Arduino Zero, Arduino M0 and Arduino M0 Pro.
The Wemos SAMD21 M0 is compatible with Arduino M0, but not exactly a clone.
You have two options to program it: using the SWD (EDBG) connector that
comes in the board or the Arduino M0 bootloader that comes flashed on it.
Currently only SWD programming is supported. Bootloader skip area should be
implemented to avoid overwriting the bootloader area.
The board uses the ATSAMD21G18A MCU and can work over the Native USB Port.
Contents
========
- STATUS/ISSUES
- LEDs
- Serial Consoles
- Configurations
STATUS/ISSUES
=============
Because the Arduino M0 doesn't have a 12MHz crystal, it uses the internal
RC oscillator.
LEDs
====
There is one yellow LED available on the Arduino M0 and it can be turned
on and off. The LED can be activated by driving the connected
PA17 I/O line to high level.
When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
control the LED as follows:
SYMBOL Meaning LED0
------------------- ----------------------- ------
LED_STARTED NuttX has been started OFF
LED_HEAPALLOCATE Heap has been allocated OFF
LED_IRQSENABLED Interrupts enabled OFF
LED_STACKCREATED Idle stack created ON
LED_INIRQ In an interrupt N/C
LED_SIGNAL In a signal handler N/C
LED_ASSERTION An assertion failed N/C
LED_PANIC The system has crashed FLASH
Thus is LED is statically on, NuttX has successfully booted and is,
apparently, running normally. If LED is flashing at approximately
2Hz, then a fatal error has been detected and the system has halted.
Serial Consoles
===============
SERCOM5
------
SERCOM5 is available on pins PB22 (TXD) and PB23 (RXD). You will need to
solder a two pins header to RXD and TXD labels, near to ICSP pin header.
PIN GPIO Function
---- ---- ------------------
37 PB22 SERCOM5 / USART RX
38 PB23 SERCOM5 / USART TX
If you have a 3.3V USB/Serial adapter then this is the most convenient
serial console to use (because you don't lose the console device each time
you lose the USB connection). It is the default in all of these
configurations. An option is to use the virtual COM port.
Native USB Port
---------------
You can access the NSH shell directly using the USB connector. All you need
to do is use the "usbnsh" board profile.
Configurations
==============
Each Arduino M0 configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh arduino-m0:<subdir>
Before building, make sure the PATH environment variable include the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of the following.
NOTE: These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES above
and below:
NOTES:
1. This configuration is set up to build on Windows using the Cygwin
environment using the ARM EABI toolchain. This can be easily
changed as described above under "Configurations."
2. By default, this configuration provides a serial console on SERCOM5
at 115200 8N1 via RXD/TXD pads:
PIN EXT3 GPIO Function
---- ---- ------------------
37 PB22 SERCOM5 / USART RX
38 PB23 SERCOM5 / USART TX
usbnsh:
This configuration directory will build the NuttShell to work over USB.
It uses the internal SAMD21 USB port working as CDC/ACM Serial/Modem.
Using the configuration you don't need to solder the header pins RXD/TXD
to get access the NSH terminal.

View File

@ -0,0 +1,64 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_POSIX_TIMERS is not set
# CONFIG_NSH_DISABLEBG is not set
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_CMP is not set
# CONFIG_NSH_DISABLE_DD is not set
# CONFIG_NSH_DISABLE_EXEC is not set
# CONFIG_NSH_DISABLE_EXIT is not set
# CONFIG_NSH_DISABLE_GET is not set
# CONFIG_NSH_DISABLE_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
# CONFIG_NSH_DISABLE_LOSETUP is not set
# CONFIG_NSH_DISABLE_MKRD is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_SEMICOLON is not set
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="arduino-m0"
CONFIG_ARCH_BOARD_ARDUINO_M0=y
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_SAMD21G18A=y
CONFIG_ARCH_CHIP_SAMD2X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=3410
CONFIG_BUILTIN=y
CONFIG_DEFAULT_SMALL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=32768
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMD2L2_SERCOM3=y
CONFIG_SAMD2L2_SERCOM4=y
CONFIG_SAMD2L2_SERCOM5=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=21
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2015
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USART4_RXBUFSIZE=64
CONFIG_USART4_TXBUFSIZE=64
CONFIG_USART5_SERIAL_CONSOLE=y
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,62 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_POSIX_TIMERS is not set
# CONFIG_NSH_DISABLEBG is not set
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_CMP is not set
# CONFIG_NSH_DISABLE_DD is not set
# CONFIG_NSH_DISABLE_EXEC is not set
# CONFIG_NSH_DISABLE_EXIT is not set
# CONFIG_NSH_DISABLE_GET is not set
# CONFIG_NSH_DISABLE_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
# CONFIG_NSH_DISABLE_LOSETUP is not set
# CONFIG_NSH_DISABLE_MKRD is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_SEMICOLON is not set
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="arduino-m0"
CONFIG_ARCH_BOARD_ARDUINO_M0=y
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_SAMD21G18A=y
CONFIG_ARCH_CHIP_SAMD2X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LOOPSPERMSEC=3410
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_DEFAULT_SMALL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=32768
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMD2L2_SERCOM5=y
CONFIG_SAMD2L2_USB=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=22
CONFIG_START_MONTH=9
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USBDEV=y
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,535 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_ARDUINO_M0_INCLUDE_BOARD_H
#define __BOARDS_ARM_SAMD2L2_ARDUINO_M0_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
# ifdef CONFIG_SAMD2L2_GPIOIRQ
# include <arch/irq.h>
# endif
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Clocking *****************************************************************/
/* Overview
*
* OSC8M Output = 8MHz
* `- GCLK1 Input = 8MHz Prescaler = 1 output = 8MHz
* `- DFLL Input = 8MHz Multiplier = 6 output = 48MHz
* `- GCLK0 Input = 48MHz Prescaler = 1 output = 48MHz
* `- PM Input = 48Mhz CPU divider = 1 CPU frequency = 48MHz
* APBA divider = 1 APBA frequency = 48MHz
* APBB divider = 1 APBB frequency = 48MHz
* APBC divider = 1 APBC frequency = 48MHz
*
* The Arduino M0 has one on-board crystal:
*
* XC101 32.768KHz XOSC32
*
* REVISIT: Not currently used, may want to use as GCLK1 source with
* DFLL multiplier of ((48000000+16384)/32768) = 1465 which would yield
* a clock of 48,005,120 MHz.
*/
/* XOSC Configuration -- Not available
*
* BOARD_XOSC_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC_FREQUENCY - In Hz
* BOARD_XOSC_STARTUPTIME - See SYSCTRL_XOSC_STARTUP_* definitions
* BOARD_XOSC_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC_AMPGC - Boolean (defined / not defined)
* BOARD_XOSC_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC_ENABLE
#define BOARD_XOSC_FREQUENCY 12000000UL
#define BOARD_XOSC_STARTUPTIME SYSCTRL_XOSC_STARTUP_1S
#define BOARD_XOSC_ISCRYSTAL 1
#define BOARD_XOSC_AMPGC 1
#define BOARD_XOSC_ONDEMAND 1
#undef BOARD_XOSC_RUNINSTANDBY
/* XOSC32 Configuration -- Not used
*
* BOARD_XOSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC32K_FREQUENCY - In Hz
* BOARD_XOSC32K_STARTUPTIME - See SYSCTRL_XOSC32K_STARTUP_* definitions
* BOARD_XOSC32K_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC32K_AAMPEN - Boolean (defined / not defined)
* BOARD_XOSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC32K_ENABLE
#define BOARD_XOSC32K_FREQUENCY 32768 /* 32.768KHz XTAL */
#define BOARD_XOSC32K_STARTUPTIME SYSCTRL_XOSC32K_STARTUP_2S
#define BOARD_XOSC32K_ISCRYSTAL 1
#define BOARD_XOSC32K_AAMPEN 1
#undef BOARD_XOSC32K_EN1KHZ
#define BOARD_XOSC32K_EN32KHZ 1
#define BOARD_XOSC32K_ONDEMAND 1
#undef BOARD_XOSC32K_RUNINSTANDBY
/* OSC32 Configuration -- not used
*
* BOARD_OSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_OSC32K_FREQUENCY - In Hz
* BOARD_OSC32K_STARTUPTIME - See SYSCTRL_OSC32K_STARTUP_* definitions
* BOARD_OSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_OSC32K_ENABLE
#define BOARD_OSC32K_FREQUENCY 32768 /* 32.768kHz internal oscillator */
#define BOARD_OSC32K_STARTUPTIME SYSCTRL_OSC32K_STARTUP_4MS
#define BOARD_OSC32K_EN1KHZ 1
#define BOARD_OSC32K_EN32KHZ 1
#define BOARD_OSC32K_ONDEMAND 1
#undef BOARD_OSC32K_RUNINSTANDBY
/* OSC8M Configuration -- always enabled
*
* BOARD_OSC8M_PRESCALER - See SYSCTRL_OSC8M_PRESC_DIV* definitions
* BOARD_OSC8M_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC8M_RUNINSTANDBY - Boolean (defined / not defined)
*/
#define BOARD_OSC8M_PRESCALER SYSCTRL_OSC8M_PRESC_DIV1
#define BOARD_OSC8M_ONDEMAND 1
#undef BOARD_OSC8M_RUNINSTANDBY
#define BOARD_OSC8M_FREQUENCY 8000000 /* 8MHz high-accuracy internal oscillator */
/* OSCULP32K Configuration -- not used. */
#define BOARD_OSCULP32K_FREQUENCY 32000 /* 32kHz ultra-low-power internal oscillator */
/* Digital Frequency Locked Loop configuration. In closed-loop mode, the
* DFLL output frequency (Fdfll) is given by:
*
* Fdfll = DFLLmul * Frefclk
* = 6 * 8000000 = 48MHz
*
* Where the reference clock is Generic Clock Channel 0 output of GLCK1.
* GCLCK1 provides OSC8M, undivided.
*
* When operating in open-loop mode, the output frequency of the DFLL will
* be determined by the values written to the DFLL Coarse Value bit group
* and the DFLL Fine Value bit group in the DFLL Value register.
*
* BOARD_DFLL_OPENLOOP - Boolean (defined / not defined)
* BOARD_DFLL_TRACKAFTERFINELOCK - Boolean (defined / not defined)
* BOARD_DFLL_KEEPLOCKONWAKEUP - Boolean (defined / not defined)
* BOARD_DFLL_ENABLECHILLCYCLE - Boolean (defined / not defined)
* BOARD_DFLL_QUICKLOCK - Boolean (defined / not defined)
* BOARD_DFLL_ONDEMAND - Boolean (defined / not defined)
*
* Closed loop mode only:
* BOARD_DFLL_GCLKGEN - GCLK index
* BOARD_DFLL_MULTIPLIER - Value
* BOARD_DFLL_MAXCOARSESTEP - Value
* BOARD_DFLL_MAXFINESTEP - Value
*
* BOARD_DFLL_FREQUENCY - The resulting frequency
*/
#define BOARD_DFLL_ENABLE 1
#define BOARD_DFLL_OPENLOOP 1
#undef BOARD_DFLL_ONDEMAND
#undef BOARD_DFLL_RUNINSTANDBY
/* DFLL closed loop mode configuration */
#define BOARD_DFLL_SRCGCLKGEN 1
#define BOARD_DFLL_MULTIPLIER 6
#define BOARD_DFLL_QUICKLOCK 1
#define BOARD_DFLL_TRACKAFTERFINELOCK 1
#define BOARD_DFLL_KEEPLOCKONWAKEUP 1
#define BOARD_DFLL_ENABLECHILLCYCLE 1
#define BOARD_DFLL_MAXCOARSESTEP (0x1f / 4)
#define BOARD_DFLL_MAXFINESTEP (0xff / 4)
#define BOARD_DFLL_FREQUENCY (48000000)
/* GCLK Configuration
*
* Global enable/disable.
*
* BOARD_GCLK_ENABLE - Boolean (defined / not defined)
*
* For n=1-7:
* BOARD_GCLKn_ENABLE - Boolean (defined / not defined)
*
* For n=0-8:
* BOARD_GCLKn_RUN_IN_STANDBY - Boolean (defined / not defined)
* BOARD_GCLKn_CLOCK_SOURCE - See GCLK_GENCTRL_SRC_* definitions
* BOARD_GCLKn_PRESCALER - Value
* BOARD_GCLKn_OUTPUT_ENABLE - Boolean (defined / not defined)
*/
#define BOARD_GCLK_ENABLE 1
/* GCLK generator 0 (Main Clock) - Source is the DFLL */
#undef BOARD_GCLK0_RUN_IN_STANDBY
#define BOARD_GCLK0_CLOCK_SOURCE GCLK_GENCTRL_SRC_DFLL48M
#define BOARD_GCLK0_PRESCALER 1
#undef BOARD_GCLK0_OUTPUT_ENABLE
#define BOARD_GCLK0_FREQUENCY (BOARD_DFLL_FREQUENCY / BOARD_GCLK0_PRESCALER)
/* Configure GCLK generator 1 - Drives the DFLL */
#define BOARD_GCLK1_ENABLE 1
#undef BOARD_GCLK1_RUN_IN_STANDBY
#define BOARD_GCLK1_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK1_PRESCALER 1
#undef BOARD_GCLK1_OUTPUT_ENABLE
#define BOARD_GCLK1_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK1_PRESCALER)
/* Configure GCLK generator 2 (RTC) */
#undef BOARD_GCLK2_ENABLE
#undef BOARD_GCLK2_RUN_IN_STANDBY
#define BOARD_GCLK2_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC32K
#define BOARD_GCLK2_PRESCALER 32
#undef BOARD_GCLK2_OUTPUT_ENABLE
#define BOARD_GCLK2_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK2_PRESCALER)
/* Configure GCLK generator 3 */
#undef BOARD_GCLK3_ENABLE
#undef BOARD_GCLK3_RUN_IN_STANDBY
#define BOARD_GCLK3_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK3_PRESCALER 1
#undef BOARD_GCLK3_OUTPUT_ENABLE
#define BOARD_GCLK3_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK3_PRESCALER)
/* Configure GCLK generator 4 */
#undef BOARD_GCLK4_ENABLE
#undef BOARD_GCLK4_RUN_IN_STANDBY
#define BOARD_GCLK4_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK4_PRESCALER 1
#undef BOARD_GCLK4_OUTPUT_ENABLE
#define BOARD_GCLK4_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK4_PRESCALER)
/* Configure GCLK generator 5 */
#undef BOARD_GCLK5_ENABLE
#undef BOARD_GCLK5_RUN_IN_STANDBY
#define BOARD_GCLK5_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK5_PRESCALER 1
#undef BOARD_GCLK5_OUTPUT_ENABLE
#define BOARD_GCLK5_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK5_PRESCALER)
/* Configure GCLK generator 6 */
#undef BOARD_GCLK6_ENABLE
#undef BOARD_GCLK6_RUN_IN_STANDBY
#define BOARD_GCLK6_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK6_PRESCALER 1
#undef BOARD_GCLK6_OUTPUT_ENABLE
#define BOARD_GCLK6_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK6_PRESCALER)
/* Configure GCLK generator 7 */
#undef BOARD_GCLK7_ENABLE
#undef BOARD_GCLK7_RUN_IN_STANDBY
#define BOARD_GCLK7_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK7_PRESCALER 1
#undef BOARD_GCLK7_OUTPUT_ENABLE
#define BOARD_GCLK7_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK7_PRESCALER)
/* The source of the main clock is always GCLK_MAIN. Also called GCLKGEN[0],
* this is the clock feeding the Power Manager.
* The Power Manager, in turn, generates main clock which is divided down to
* produce the CPU, AHB, and APB clocks.
*
* The main clock is initially OSC8M divided by 8.
*/
#define BOARD_GCLK_MAIN_FREQUENCY BOARD_GCLK0_FREQUENCY
/* Main clock dividers
*
* BOARD_CPU_DIVIDER - See PM_CPUSEL_CPUDIV_* definitions
* BOARD_CPU_FRQUENCY - In Hz
* BOARD_CPU_FAILDECT - Boolean (defined / not defined)
* BOARD_APBA_DIVIDER - See M_APBASEL_APBADIV_* definitions
* BOARD_APBA_FRQUENCY - In Hz
* BOARD_APBB_DIVIDER - See M_APBBSEL_APBBDIV_* definitions
* BOARD_APBB_FRQUENCY - In Hz
* BOARD_APBC_DIVIDER - See M_APBCSEL_APBCDIV_* definitions
* BOARD_APBC_FRQUENCY - In Hz
*/
#define BOARD_CPU_FAILDECT 1
#define BOARD_CPU_DIVIDER PM_CPUSEL_CPUDIV_1
#define BOARD_APBA_DIVIDER PM_APBASEL_APBADIV_1
#define BOARD_APBB_DIVIDER PM_APBBSEL_APBBDIV_1
#define BOARD_APBC_DIVIDER PM_APBCSEL_APBCDIV_1
/* Resulting frequencies */
#define BOARD_MCK_FREQUENCY (BOARD_GCLK_MAIN_FREQUENCY)
#define BOARD_CPU_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBA_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBB_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBC_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBD_FREQUENCY (BOARD_MCK_FREQUENCY)
/* FLASH wait states
*
* Vdd Range Wait states Maximum Operating Frequency
* ------------- -------------- ---------------------------
* 1.62V to 2.7V 0 14 MHz
* 1 28 MHz
* 2 42 MHz
* 3 48 MHz
* 2.7V to 3.63V 0 24 MHz
* 1 48 MHz
*/
#if 0 /* REVISIT -- should not be necessary */
# define BOARD_FLASH_WAITSTATES 1
#else
# define BOARD_FLASH_WAITSTATES 2
#endif
/* SERCOM definitions *******************************************************/
/* This is the source clock generator for the GCLK_SERCOM_SLOW clock that is
* common to all SERCOM modules.
*/
#define BOARD_SERCOM05_SLOW_GCLKGEN 0
/* SERCOM0 SPI is available on EXT1
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA5 SERCOM0 PAD1 SPI SS
* 16 PA6 SERCOM0 PAD2 SPI MOSI
* 17 PA4 SERCOM0 PAD0 SPI MISO
* 18 PA7 SERCOM0 PAD3 SPI SCK
*/
#define BOARD_SERCOM0_GCLKGEN 0
#define BOARD_SERCOM0_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM0_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMAP_PAD0 PORT_SERCOM0_PAD0_2 /* SPI_MISO */
#define BOARD_SERCOM0_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM0_PINMAP_PAD2 PORT_SERCOM0_PAD2_2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMAP_PAD3 PORT_SERCOM0_PAD3_2 /* SPI_SCK */
#define BOARD_SERCOM0_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM1 SPI is available on EXT2
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA17 SERCOM1 PAD1 SPI SS
* 16 PA18 SERCOM1 PAD2 SPI MOSI
* 17 PA16 SERCOM1 PAD0 SPI MISO
* 18 PA19 SERCOM1 PAD3 SPI SCK
*/
#define BOARD_SERCOM1_GCLKGEN 0
#define BOARD_SERCOM1_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM1_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM1_PINMAP_PAD0 PORT_SERCOM1_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM1_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM1_PINMAP_PAD2 PORT_SERCOM1_PAD2_1 /* SPI_MOSI */
#define BOARD_SERCOM1_PINMAP_PAD3 PORT_SERCOM1_PAD3_1 /* SPI_SCK */
#define BOARD_SERCOM1_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The Arduino M0 contains an Embedded Debugger (EDBG) that can be
* used to program and debug the ATSAMD21J18A using Serial Wire Debug (SWD).
* The Embedded debugger also include a Virtual COM port interface over
* SERCOM3. Virtual COM port connections:
*
* PA22 SERCOM3 PAD[0] / USART TXD
* PA23 SERCOM3 PAD[1] / USART RXD
*/
#define BOARD_SERCOM3_GCLKGEN 0
#define BOARD_SERCOM3_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM3_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0_1)
#define BOARD_SERCOM3_PINMAP_PAD0 PORT_SERCOM3_PAD0_1 /* USART TX */
#define BOARD_SERCOM3_PINMAP_PAD1 PORT_SERCOM3_PAD1_1 /* USART RX */
#define BOARD_SERCOM3_PINMAP_PAD2 0
#define BOARD_SERCOM3_PINMAP_PAD3 0
#define BOARD_SERCOM3_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SERCOM4 USART is available on connectors EXT1, EXT2, and EXT3
*
* PIN EXT1 EXT2 EXT3 GPIO Function
* ---- ---- ---- ---- ------------------
* 13 PB09 PB10 PB10 SERCOM4 / USART RX
* 14 PB08 PB11 PB11 SERCOM4 / USART TX
* 19 GND GND GND N/A
* 20 VCC VCC VCC N/A
*
* If you have a TTL to RS-232 converter then this is the most convenient
* serial console to use (because you don't lose the console device each time
* you lose the USB connection). It is the default in all of the SAMD21
* configurations.
*/
#define BOARD_SERCOM4_GCLKGEN 0
#define BOARD_SERCOM4_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#if defined(CONFIG_ARDUINO_M0_USART4_EXT1)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0)
# define BOARD_SERCOM4_PINMAP_PAD0 PORT_SERCOM4_PAD0_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD1 PORT_SERCOM4_PAD1_3 /* USART RX */
# define BOARD_SERCOM4_PINMAP_PAD2 0
# define BOARD_SERCOM4_PINMAP_PAD3 0
#elif defined(CONFIG_ARDUINO_M0_USART4_EXT2)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
# define BOARD_SERCOM4_PINMAP_PAD0 0
# define BOARD_SERCOM4_PINMAP_PAD1 0
# define BOARD_SERCOM4_PINMAP_PAD2 PORT_SERCOM4_PAD2_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD3 PORT_SERCOM4_PAD3_3 /* USART RX */
#else /* if defined(CONFIG_ARDUINO_M0_USART4_EXT3) */
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
# define BOARD_SERCOM4_PINMAP_PAD0 0
# define BOARD_SERCOM4_PINMAP_PAD1 0
# define BOARD_SERCOM4_PINMAP_PAD2 PORT_SERCOM4_PAD2_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD3 PORT_SERCOM4_PAD3_3 /* USART RX */
#endif
#define BOARD_SERCOM4_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM5 USART used to Serial Console
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 31 PB02 SERCOM5 PAD0 USART TXD
* 32 PB03 SERCOM5 PAD1 USART RXD
*/
#define BOARD_SERCOM5_GCLKGEN 0
#define BOARD_SERCOM5_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM5_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
#define BOARD_SERCOM5_PINMAP_PAD0 0
#define BOARD_SERCOM5_PINMAP_PAD1 0
#define BOARD_SERCOM5_PINMAP_PAD2 PORT_SERCOM5_PAD2_4 /* USART 5 TXD */
#define BOARD_SERCOM5_PINMAP_PAD3 PORT_SERCOM5_PAD3_4 /* USART 5 RXD */
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK0_FREQUENCY
/* ADC definitions **********************************************************/
#define BOARD_ADC_GCLKGEN 0
/* We are using PA3 as Analog Input */
#define PORT_AIN1 PORT_AIN1_1
#define BOARD_ADC_INPUT1 1
#define BOARD_ADC_NUM_CHANNELS 1
/* The negative input is the internal GND */
#define BOARD_ADC_NEG ADC_INPUTCTRL_MUXNEG_GND
/* The VREF is the INTVCC1 = 1/2 VDDANA */
#define BOARD_ADC_REF ADC_REFCTRL_REFSEL_INTVCC1
/* USB definitions **********************************************************/
/* This is the source clock generator for the GCLK_USB clock
*/
#define BOARD_USB_GCLKGEN 0
#define BOARD_USB_FREQUENCY BOARD_GCLK0_FREQUENCY
/* default USB Pad calibration (not used yet by USB driver) */
#define BOARD_USB_PADCAL_P 29
#define BOARD_USB_PADCAL_N 5
#define BOARD_USB_PADCAL_TRIM 3
/* LED definitions **********************************************************/
/* There are three LEDs on board the Arduino M0 board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD21
* USB connector.
*
* This LED is controlled by PC07 and the LED can be activated by driving
* the PB30 to GND.
*/
/* LED index values for use with board_userled() */
#define BOARD_STATUS_LED 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_STATUS LED_BIT (1 << BOARD_STATUS_LED)
/* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as defined below. Thus if the LED is statically on, NuttX
* has successfully booted and is, apparently, running normally.
* If the LED is flashing at approximately 2Hz, then a fatal error
* has been detected and the system has halted.
*/
#define LED_STARTED 0 /* STATUS LED=OFF */
#define LED_HEAPALLOCATE 0 /* STATUS LED=OFF */
#define LED_IRQSENABLED 0 /* STATUS LED=OFF */
#define LED_STACKCREATED 1 /* STATUS LED=ON */
#define LED_INIRQ 2 /* STATUS LED=no change */
#define LED_SIGNAL 2 /* STATUS LED=no change */
#define LED_ASSERTION 2 /* STATUS LED=no change */
#define LED_PANIC 3 /* STATUS LED=flashing */
/* Button definitions *******************************************************/
/* Mechanical buttons:
*
* The Arduino M0 doesn't contain mechanical buttons.
*/
#define NUM_BUTTONS 0
#endif /* __BOARDS_ARM_SAMD2L2_ARDUINO_M0_INCLUDE_BOARD_H */

View File

@ -0,0 +1,63 @@
############################################################################
# boards/arm/samd2l2/arduino-m0/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv6-m/Toolchain.defs
LDSCRIPT = flash.ld
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif

View File

@ -0,0 +1,111 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/scripts/flash.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAMD21J18A has 256KB of FLASH beginning at address 0x0000:0000 and
* 32KB of SRAM beginning at address 0x2000:0000
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
ENTRY(_stext)
SECTIONS
{
.text : {
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section : {
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > flash
.ARM.extab : {
*(.ARM.extab*)
} >flash
.ARM.exidx : {
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >flash
.data : {
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
_eronly = LOADADDR(.data);
.ramfunc ALIGN(4): {
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > flash
_framfuncs = LOADADDR(.ramfunc);
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,51 @@
############################################################################
# boards/arm/samd2l2/arduino-m0/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = sam_boot.c sam_bringup.c
ifeq ($(CONFIG_SAMD2L2_SERCOM0),y)
CSRCS += sam_spi.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
CSRCS += sam_userleds.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sam_buttons.c
endif
ifeq ($(CONFIG_SAMD2L2_ADC),y)
CSRCS += sam_adc.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sam_appinit.c
endif
ifeq ($(CONFIG_USBDEV),y)
CSRCS += sam_usb.c
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,122 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/arduino_m0.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_ARDUINO_M0_SRC_ARDUINO_M0_H
#define __BOARDS_ARM_SAMD2L2_ARDUINO_M0_SRC_ARDUINO_M0_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <arch/irq.h>
#include <nuttx/irq.h>
#include "sam_config.h"
#include "sam_pinmap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* LEDs:
* There is a LED on board the Arduino M0 board.
*
* This LED is controlled by PA17 and the LED can be activated by driving
* PA17 to High.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
#define PORT_STATUS_LED (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: sam_bringup
*
* Description:
* Perform architecture-specific initialization
*
* CONFIG_BOARD_LATE_INITIALIZE=y :
* Called from board_late_initialize().
*
* CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_LIB_BOARDCTL=y :
* Called from the NSH library
*
****************************************************************************/
int sam_bringup(void);
/****************************************************************************
* Name: sam_adc_setup
*
* Description:
* Initialize ADC and register the ADC driver.
*
****************************************************************************/
int sam_adc_setup(void);
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAM3U-EK board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void);
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_SAMD2L2_ARDUINO_M0_SRC_ARDUINO_M0_H */

View File

@ -0,0 +1,89 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_adc.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/analog/adc.h>
#include <arch/board/board.h>
#include "chip.h"
#include "sam_adc.h"
#include "arduino_m0.h"
#ifdef CONFIG_ADC
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_adc_setup
*
* Description:
* Initialize ADC and register the ADC driver.
*
****************************************************************************/
int sam_adc_setup(void)
{
static bool initialized = false;
struct adc_dev_s *adc;
int ret;
/* Check if we have already initialized */
if (!initialized)
{
/* Call sam_adcinitialize() to get an instance of the ADC interface */
adc = sam_adcinitialize(0);
if (adc == NULL)
{
aerr("ERROR: Failed to get ADC interface\n");
return -ENODEV;
}
/* Register the ADC driver at "/dev/adc0" */
ret = adc_register("/dev/adc0", adc);
if (ret < 0)
{
aerr("ERROR: adc_register failed: %d\n", ret);
return ret;
}
/* Now we are initialized */
initialized = true;
}
return OK;
}
#endif /* CONFIG_ADC */

View File

@ -0,0 +1,71 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "arduino_m0.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
return OK;
}

View File

@ -0,0 +1,143 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_autoleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There is a LED on board the Arduino M0 board.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt** N/C
* LED_SIGNAL In a signal handler*** N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "arduino_m0.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
bool ledstate = false;
switch (led)
{
case 0: /* LED_STARTED: NuttX has been started STATUS LED=ON
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=ON
* LED_IRQSENABLED: Interrupts enabled STATUS LED=ON
*/
break; /* Leave ledstate == true to turn OFF */
default:
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
ledstate = true; /* Set ledstate == false to turn OFF */
break;
}
sam_portwrite(PORT_STATUS_LED, ledstate);
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
/* These should not happen and are ignored */
default:
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
/* These result in no-change */
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
/* Turn STATUS LED off set driving the output high */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
sam_portwrite(PORT_STATUS_LED, false);
break;
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,99 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_boot.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "arduino_m0.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_boardinitialize
*
* Description:
* All SAMD21 architectures must provide the following entry point.
* This entry point is called early in the initialization -- after all
* memory has been configured and mapped but before any devices have been
* initialized.
*
****************************************************************************/
void sam_boardinitialize(void)
{
/* Configure SPI chip selects if
* 1) SPI is not disabled, and
* 2) the weak function
* sam_spidev_initialize() has been brought into the link.
*/
#ifdef SAMD2L2_HAVE_SPI
if (sam_spidev_initialize)
{
sam_spidev_initialize();
}
#endif
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
}
/****************************************************************************
* Name: board_late_initialize
*
* Description:
* If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_late_initialize(). board_late_initialize() will be
* called immediately after up_intitialize() is called and just before the
* initial application is started. This additional initialization phase
* may be used, for example, to initialize board-specific device drivers.
*
****************************************************************************/
#ifdef CONFIG_BOARD_LATE_INITIALIZE
void board_late_initialize(void)
{
/* Perform board initialization */
(void)sam_bringup();
}
#endif /* CONFIG_BOARD_LATE_INITIALIZE */

View File

@ -0,0 +1,71 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_bringup.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <debug.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "arduino_m0.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_bringup
*
* Description:
* Bring up board features
*
****************************************************************************/
int sam_bringup(void)
{
int ret = OK;
/* Configure the ADC driver */
#ifdef CONFIG_SAMD2L2_ADC
ret = sam_adc_setup();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize the ADC driver: %d\n", ret);
return ret;
}
#endif
return ret;
}

View File

@ -0,0 +1,289 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_spi.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include "sam_config.h"
#include "sam_port.h"
#include "sam_spi.h"
#include "arduino_m0.h"
#ifdef SAMD2L2_HAVE_SPI
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAMD21 Xplained
* Pro board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void)
{
}
/****************************************************************************
* Name: sam_spi[n]select, sam_spi[n]status, and sam_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic. They
* include:
*
* o sam_spi[n]select is a functions to manage the board-specific chip
* selects
* o sam_spi[n]status and sam_spi[n]cmddata: Implementations of the status
* and cmddata methods of the SPI interface defined by struct spi_ops_
* (see include/nuttx/spi/spi.h). All other methods including
* sam_spibus_initialize()) are provided by common SAMD/L logic.
*
* Where [n] is the SERCOM number for the SPI module.
*
* To use this common SPI logic on your board:
*
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide sam_spi[n]select() and sam_spi[n]status() functions in your
* board-specific logic. These functions will perform chip selection
* and status operations using GPIOs in the way your board is
* configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* sam_spi[n]cmddata() functions in your board-specific logic. This
* function will perform cmd/data selection operations using GPIOs in
* the way your board is configured.
* 3. Add a call to sam_spibus_initialize() in your low level application
* initialization logic
* 4. The handle returned by sam_spibus_initialize() may then be used to
* bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
/****************************************************************************
* Name: sam_spi[n]select
*
* Description:
* PIO chip select pins may be programmed by the board specific logic in
* one of two different ways. First, the pins may be programmed as SPI
* peripherals. In that case, the pins are completely controlled by the
* SPI driver. This method still needs to be provided, but it may be only
* a stub.
*
* An alternative way to program the PIO chip select pins is as a normal
* GPIO output. In that case, the automatic control of the CS pins is
* bypassed and this function must provide control of the chip select.
* NOTE: In this case, the GPIO output pin does *not* have to be the
* same as the NPCS pin normal associated with the chip select number.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
* selected - TRUE:Select the device, FALSE:De-select the device
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
void sam_spi0select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
void sam_spi1select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
void sam_spi2select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
void sam_spi3select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
void sam_spi4select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
void sam_spi5select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
/****************************************************************************
* Name: sam_spi[n]status
*
* Description:
* Return status information associated with the SPI device.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
uint8_t sam_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
uint8_t sam_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
uint8_t sam_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
uint8_t sam_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
uint8_t sam_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
return ret;
}
#endif
/****************************************************************************
* Name: sam_spi[n]cmddata
*
* Description:
* Some SPI devices require an additional control to determine if the SPI
* data being sent is a command or is data. If CONFIG_SPI_CMDDATA then
* this function will be called to different be command and data transfers.
*
* This is often needed, for example, by LCD drivers. Some LCD hardware
* may be configured to use 9-bit data transfers with the 9th bit
* indicating command or data. That same hardware may be configurable,
* instead, to use 8-bit data but to require an additional, board-
* specific GPIO control to distinguish command and data. This function
* would be needed in that latter case.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Zero on success; a negated errno on failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA
#ifdef SAMD2L2_HAVE_SPI0
int sam_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
int sam_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
int sam_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
int sam_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
int sam_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
int sam_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#endif /* CONFIG_SPI_CMDDATA */
#endif /* SAMD2L2_HAVE_SPI */

View File

@ -0,0 +1,110 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_usb.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <sched.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbhost.h>
#include <nuttx/usb/usbdev_trace.h>
#include "debug.h"
#include "chip.h"
#include "sam_port.h"
#include "saml_periphclks.h"
#include "arduino_m0.h"
#if defined(CONFIG_SAMD2L2_USB)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_usbinitialize
*
* Description:
* Called from sam_boot very early in initialization to setup
* USB-related GPIO pins for the SAML21-Xplained board.
*
* USB Ports
* The SAML21 features USB device and host:
*
*
****************************************************************************/
void weak_function sam_usbinitialize(void)
{
#ifdef HAVE_USBDEV
/* Detect when a target USB cable is connected in self-powered mode */
/* The Engie CE0035 doesn't have VBUS SENSE support */
/* sam_configport(PORT_USB_VBUS_SENSE); */
/* TODO: Configure an interrupt on VBUS sense */
#endif
#ifdef HAVE_USBHOST
/* In USB host mode VBUS voltage is provided by the kit and can thus not
* identify a connected device, so another GPIO is used to detect
* the USB ID of the device.
*/
/* The Engie CE0035 doesn't have the USB ID pin connected */
/* sam_configport(PORT_USB_ID_DETECT); */ /* ID detect */
#endif
}
/****************************************************************************
* Name: sam_usbsuspend
*
* Description:
* Board logic must provide the sam_usbsuspend logic if the USBDEV driver
* is used.
* This function is called whenever the USB enters or leaves suspend mode.
* This is an opportunity for the board logic to shutdown clocks, power,
* etc. while the USB is suspended.
*
****************************************************************************/
#ifdef CONFIG_USBDEV
void sam_usb_suspend(FAR struct usbdev_s *dev, bool resume)
{
uinfo("board: resume: %d\n", resume);
}
#endif
#endif /* CONFIG_SAMDL_USB */

View File

@ -0,0 +1,104 @@
/****************************************************************************
* boards/arm/samd2l2/arduino-m0/src/sam_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There is a LED on board the Arduino M0.
*
* This LED is controlled by PA17 and the LED can be activated by driving
* PA17 to High.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED. Otherwise, the LED can be controlled from user
* applications using the logic in this file.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "arduino_m0.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the
* board_userled_initialize() is available to initialize the LED from user
* application logic.
*
****************************************************************************/
uint32_t board_userled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
return BOARD_NLEDS;
}
/****************************************************************************
* Name: board_userled
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is
* available to control the LED from user application logic.
*
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_STATUS_LED)
{
sam_portwrite(PORT_STATUS_LED, !ledon);
}
}
/****************************************************************************
* Name: board_userled_all
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs.
* If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() is
* available to control the LED from user application logic. NOTE: since
* there is only a single LED on-board, this is function isn't very useful.
*
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
board_userled(BOARD_STATUS_LED, (ledset & BOARD_STATUS_LED_BIT) != 0);
}
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,82 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_SAMD20_XPLAINED
menu "SAMD20 Xplained Pro Modules"
config SAMD20_XPLAINED_IOMODULE
bool "I/O1 Module"
default n
---help---
The I/O 1 module is attached. This module provides an MMC/SD card
slot.
if SAMD20_XPLAINED_IOMODULE
choice
prompt "I/O1 Module Location"
default SAMD20_XPLAINED_IOMODULE_EXT1
config SAMD20_XPLAINED_IOMODULE_EXT1
bool "EXT1"
config SAMD20_XPLAINED_IOMODULE_EXT2
bool "EXT2"
endchoice
endif
config SAMD20_XPLAINED_OLED1MODULE
bool "OLED1 Module"
default n
---help---
The OLED 1 module is attached. This module provides an OLED plus 3
additional switches and 3 additional LEDs.
if SAMD20_XPLAINED_OLED1MODULE
choice
prompt "OLED1 Module Location"
default SAMD20_XPLAINED_OLED1MODULE_EXT1
config SAMD20_XPLAINED_OLED1MODULE_EXT1
bool "EXT1"
config SAMD20_XPLAINED_OLED1MODULE_EXT2
bool "EXT2"
endchoice
endif
endmenu
if USART4_SERIAL_CONSOLE
choice
prompt "USART 4 Connection"
default SAMD20_XPLAINED_USART4_EXT3
config SAMD20_XPLAINED_USART4_EXT1
bool "EXT1"
depends on !SAMD20_XPLAINED_OLED1MODULE_EXT1 && !SAMD20_XPLAINED_IOMODULE_EXT1
---help---
Select this option if the serial console is on SERCOM4 connected via
EXT1. The RX will be on PB9 and TX signal will be on PB8.
config SAMD20_XPLAINED_USART4_EXT2
bool "EXT2"
depends on !SAMD20_XPLAINED_OLED1MODULE_EXT2 && !SAMD20_XPLAINED_IOMODULE_EXT2
---help---
Select this option if the serial console is on SERCOM4 connected via
EXT2. The RX will be on PB13 and TX signal will be on PB12.
config SAMD20_XPLAINED_USART4_EXT3
bool "EXT3"
---help---
Select this option if the serial console is on SERCOM4 connect via
EXT3. The RX will be on PB11 and TX signal will be on PB10.
endchoice
endif
endif

View File

@ -0,0 +1,873 @@
README
======
This README discusses issues unique to NuttX configurations for the
Atmel SAMD20 Xplained Pro development board. This board features the
ATSAMD20J18A MCU.
The SAMD20 Xplained Pro Starter Kit may be bundled with three modules:
1) I/O1 - An MMC/SD card slot, PWM LED control, ADC light sensor, USART
loopback, TWI AT30TSE758 Temperature sensor.
2) OLED1 - An OLED plus 3 additional switches and 3 additional LEDs
3) PROTO1 - A prototyping board with logic on board (other than power-related
logic).
Contents
========
- STATUS/ISSUES
- Modules
- Development Environment
- GNU Toolchain Options
- IDEs
- NuttX EABI "buildroot" Toolchain
- LEDs
- Serial Consoles
- Atmel Studio 6.1
- SAMD20 Xplained Pro-specific Configuration Options
- Configurations
STATUS/ISSUES
=============
1. The FLASH wait states is set to 2 (see include/board.h). According to
the data sheet, it should work at 1 but I sometimes see crashes when
the wait states are set to one (about half of the time) (2014-2-18).
2. Garbage appears on the display sometimes after a reset (maybe 20% of
the time) or after a power cycle (less after a power cycle). I don't
understand the cause of this but most of this can be eliminated by
simply holding the reset button longer and releasing it cleanly
(then it fails maybe 5-10% of the time, maybe because of button
chatter?) (2014-2-18).
- The garbage is not random: It is always the same.
- This is not effected by BAUD rate. Curiously, the same garbage
appears at different BAUD settings implying that this may not even
be clock related???
- The program seems to be running normally, just producing bad output.
3. SPI current hangs so not much progress has been made testing the I/O1
module. The hang occurs because the SPI is waiting for SYNCBUSY to
be cleared after enabling the SPI. This even does not happen and so
causes the hang.
Another note: Enabling the SPI on SERCOM0 also seems to interfere
with the USART output on SERCOM4. Both symptoms imply some clock-
related issue.
The configuration suggests CONFIG_MMCSD_HAVE_CARDDETECT=y, but as of
this writing, there is no support for EIC pin interrupts.
4. OLED1 module is untested. These instructions were just lifted from
the SAM4L Xplained Pro README.txt file.
Modules
=======
The SAMD20 Xplained Pro Starter Kit is bundled with four modules:
I/O1
----
The primary function of this module is to provide SD card support, but
the full list of modules features include:
- microSD card connector (SPI interface)
- PWM (LED control)
- ADC (light sensor)
- USART loopback
- TWI AT30TSE758 Temperature sensor with EEPROM
SPI is available on two of the SAMD20 Xplained connectors, EXT1 and EXT2.
They mate with the I/O1 connector as indicated in this table.
I/O1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
I/O1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 LIGHT_SENSOR 3 PB00 AIN[8] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 LP_OUT 4 PB01 AIN[9] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 GPIO1 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 GPIO2 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED 7 PB02 TC6/WO[0] 7 PA22 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LP_IN 8 PB03 TC6/WO[1] 8 PA23 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 TEMP_ALERT 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 microSD_DETECT 10 PB05 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 TWI SDA 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 TWI SCL 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 USART RX 13 PB09 SERCOM4 PAD[1] 13 PB13 SERCOM4 PAD[1] The SERCOM4 module is shared between
USART RX USART RX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
14 USART TX 14 PB08 SERCOM4 PAD[0] 14 PB12 SERCOM4 PAD[0] The SERCOM4 module is shared between
USART TX USART TX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
15 microSD_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
SPI SS SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 SPI_MISO 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
The mapping between the I/O1 pins and the SD connector are shown in the
following table.
SD Card Connection
------------------
I/O1 SD PIN Description
---- ---- --- -------------------------------------------------
D2 1 Data line 2 (not used)
15 D3 2 Data line 3. Active low chip select, pulled high
16 CMD 3 Command line, connected to SPI_MOSI.
20 VDD 4
18 CLK 5 Clock line, connected to SPI_SCK.
2/19 GND 6
17 D0 7 Data line 0, connected to SPI_MISO.
D1 8 Data line 1 (not used)
10 SW_A 9 Card detect
2/19 SW_B 10 GND
Card Detect
-----------
When a microSD card is put into the connector SW_A and SW_B are short-
circuited. SW_A is connected to the microSD_DETECT signal. To use this
as a card indicator remember to enable internal pullup in the target
device.
GPIOs
-----
So all that is required to connect the SD is configure the SPI
--- ------------------ ---------------------- -------------------------------------
PIN EXT1 EXT2 Description
--- ------------------ ---------------------- -------------------------------------
15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1] Active low chip select OUTPUT, pulled
SPI SS SPI SS high on board.
--- ------------------ ---------------------- -------------------------------------
10 PB05 GPIO 10 PB15 GPIO Active low card detect INPUT, must
use internal pull-up.
--- ------------------ ---------------------- -------------------------------------
Configuration Options:
----------------------
CONFIG_SAMD20_XPLAINED_IOMODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
NOTE: As of this writing, only the SD card slot is supported in the I/O1
module.
OLED1
-----
This module provides an OLED plus 3 additional switches and 3 additional
LEDs.
OLED1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
OLED1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 BUTTON2 3 PB00 AIN[8] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 BUTTON3 4 PB01 AIN[9] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 DATA_CMD_SEL 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 LED3 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED1 7 PB02 TC6/WO[0] 7 PA22 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LED2 8 PB03 TC6/WO[1] 8 PA23 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 DISPLAY_RESET 10 PB05 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 N/C 13 PB09 SERCOM4 PAD[1] 13 PB13 SERCOM4 PAD[1] The SERCOM4 module is shared between
USART RX USART RX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
14 N/C 14 PB08 SERCOM4 PAD[0] 14 PB12 SERCOM4 PAD[0] The SERCOM4 module is shared between
USART TX USART TX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
SPI SS SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 N/C 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
Configuration Options:
----------------------
CONFIG_SAMD20_XPLAINED_OLED1MODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
PROTO1
------
A prototyping board with logic on board (other than power-related logic).
There is no built-in support for the PROTO1 module.
Development Environment
=======================
Either Linux or Cygwin on Windows can be used for the development environment.
The source has been built only using the GNU toolchain (see below). Other
toolchains will likely cause problems. Testing was performed using the Cygwin
environment.
GNU Toolchain Options
=====================
The NuttX make system can be configured to support the various different
toolchain options. All testing has been conducted using the NuttX buildroot
toolchain. To use alternative toolchain, you simply need to add change of
the following configuration options to your .config (or defconfig) file:
CONFIG_ARMV6M_TOOLCHAIN_BUILDROOT=y : NuttX buildroot under Linux or Cygwin (default)
CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIL=y : Generic GCC ARM EABI toolchain for Linux
CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIW=y : Generic GCC ARM EABI toolchain for Windows
NOTE about Windows native toolchains
------------------------------------
There are basically three kinds of GCC toolchains that can be used:
1. A Linux native toolchain in a Linux environment,
2. The buildroot Cygwin tool chain built in the Cygwin environment,
3. A Windows native toolchain.
There are several limitations to using a Windows based toolchain (#3) in a
Cygwin environment. The three biggest are:
1. The Windows toolchain cannot follow Cygwin paths. Path conversions are
performed automatically in the Cygwin makefiles using the 'cygpath'
utility but you might easily find some new path problems. If so, check
out 'cygpath -w'
2. Windows toolchains cannot follow Cygwin symbolic links. Many symbolic
links are used in NuttX (e.g., include/arch). The make system works
around these problems for the Windows tools by copying directories
instead of linking them. But this can also cause some confusion for
you: For example, you may edit a file in a "linked" directory and find
that your changes had no effect. That is because you are building the
copy of the file in the "fake" symbolic directory. If you use a
Windows toolchain, you should get in the habit of making like this:
make clean_context all
An alias in your .bashrc file might make that less painful.
IDEs
====
NuttX is built using command-line make. It can be used with an IDE, but some
effort will be required to create the project.
Makefile Build
--------------
Under Eclipse, it is pretty easy to set up an "empty makefile project" and
simply use the NuttX makefile to build the system. That is almost for free
under Linux. Under Windows, you will need to set up the "Cygwin GCC" empty
makefile project in order to work with Windows (Google for "Eclipse Cygwin" -
there is a lot of help on the internet).
Native Build
------------
Here are a few tips before you start that effort:
1) Select the toolchain that you will be using in your .config file
2) Start the NuttX build at least one time from the Cygwin command line
before trying to create your project. This is necessary to create
certain auto-generated files and directories that will be needed.
3) Set up include paths: You will need include/, arch/arm/src/sam34,
arch/arm/src/common, arch/arm/src/armv7-m, and sched/.
4) All assembly files need to have the definition option -D __ASSEMBLY__
on the command line.
Startup files will probably cause you some headaches. The NuttX startup file
is arch/arm/src/sam34/sam_vectors.S. You may need to build NuttX
one time from the Cygwin command line in order to obtain the pre-built
startup object needed by an IDE.
NuttX EABI "buildroot" Toolchain
================================
A GNU GCC-based toolchain is assumed. The PATH environment variable should
be modified to point to the correct path to the Cortex-M0 GCC toolchain (if
different from the default in your PATH variable).
If you have no Cortex-M0 toolchain, one can be downloaded from the NuttX
Bitbucket download site (https://bitbucket.org/nuttx/buildroot/downloads/).
This GNU toolchain builds and executes in the Linux or Cygwin environment.
1. You must have already configured NuttX in <some-dir>/nuttx.
tools/configure.sh samd20-xplained:<sub-dir>
2. Download the latest buildroot package into <some-dir>
3. unpack the buildroot tarball. The resulting directory may
have versioning information on it like buildroot-x.y.z. If so,
rename <some-dir>/buildroot-x.y.z to <some-dir>/buildroot.
4. cd <some-dir>/buildroot
5. cp boards/cortexm0-eabi-defconfig-4.6.3 .config
6. make oldconfig
7. make
8. Make sure that the PATH variable includes the path to the newly built
binaries.
See the file boards/README.txt in the buildroot source tree. That has more
details PLUS some special instructions that you will need to follow if you are
building a Cortex-M0 toolchain for Cygwin under Windows.
LEDs
====
There is one yellow LED available on the SAM D20 Xplained Pro board that
can be turned on and off. The LED can be activated by driving the connected
PA14 I/O line to GND.
When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
control the LED as follows:
SYMBOL Meaning LED0
------------------- ----------------------- ------
LED_STARTED NuttX has been started OFF
LED_HEAPALLOCATE Heap has been allocated OFF
LED_IRQSENABLED Interrupts enabled OFF
LED_STACKCREATED Idle stack created ON
LED_INIRQ In an interrupt N/C
LED_SIGNAL In a signal handler N/C
LED_ASSERTION An assertion failed N/C
LED_PANIC The system has crashed FLASH
Thus is LED is statically on, NuttX has successfully booted and is,
apparently, running normally. If LED is flashing at approximately
2Hz, then a fatal error has been detected and the system has halted.
Serial Consoles
===============
SERCOM4
------
SERCOM4 is available on connectors EXT1, EXT2, and EXT3, but using
different PORT pins:
PIN EXT1 EXT2 EXT3 GPIO Function
---- ---- ---- ---- ------------------
13 PB09 PB13 PB11 SERCOM4 / USART RX
14 PB08 PB12 PB12 SERCOM4 / USART TX
19 GND GND GND N/A
20 VCC VCC VCC N/A
There are options available in the NuttX configuration to select which
connector SERCOM4 is on: SAMD20_XPLAINED_USART4_EXTn, where n=1, 2, or 3.
If you have a TTL to RS-232 converter then this is the most convenient
serial console to use (because you don't lose the console device each time
you lose the USB connection). It is the default in all of these
configurations. An option is to use the virtual COM port.
Virtual COM Port
----------------
The SAMD20 Xplained Pro contains an Embedded Debugger (EDBG) that can be
used to program and debug the ATSAMD20J18A using Serial Wire Debug (SWD).
The Embedded debugger also include a Virtual COM port interface over
SERCOM3. Virtual COM port connections:
PA24 SERCOM3 / USART TXD
PA25 SERCOM3 / USART RXD
Atmel Studio 6.1
================
Loading Code into FLASH:
-----------------------
Tools menus: Tools -> Device Programming.
Debugging the NuttX Object File
-------------------------------
1) Rename object file from nutt to nuttx.elf. That is an extension that
will be recognized by the file menu.
2) File menu: File -> Open -> Open object file for debugging
- Select nuttx.elf object file
- Select AT91SAMD20J18
- Select files for symbols as desired
- Select debugger
3) Debug menu: Debug -> Start debugging and break
- This will reload the nuttx.elf file into FLASH
SAMD20 Xplained Pro-specific Configuration Options
==================================================
CONFIG_ARCH - Identifies the arch/ subdirectory. This should
be set to:
CONFIG_ARCH=arm
CONFIG_ARCH_family - For use in C code:
CONFIG_ARCH_ARM=y
CONFIG_ARCH_architecture - For use in C code:
CONFIG_ARCH_CORTEXM0=y
CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_name - For use in C code to identify the exact
chip:
CONFIG_ARCH_CHIP_SAMD2X
CONFIG_ARCH_CHIP_SAMD20
CONFIG_ARCH_CHIP_ATSAMD20J18
CONFIG_ARCH_BOARD - Identifies the boards/ subdirectory and
hence, the board that supports the particular chip or SoC.
CONFIG_ARCH_BOARD=samd20-xplained (for the SAMD20 Xplained Pro development board)
CONFIG_ARCH_BOARD_name - For use in C code
CONFIG_ARCH_BOARD_SAMD20_XPLAINED=y
CONFIG_ARCH_LOOPSPERMSEC - Must be calibrated for correct operation
of delay loops
CONFIG_ENDIAN_BIG - define if big endian (default is little
endian)
CONFIG_RAM_SIZE - Describes the installed DRAM (SRAM in this case):
CONFIG_RAM_SIZE=0x00010000 (64KB)
CONFIG_RAM_START - The start address of installed DRAM
CONFIG_RAM_START=0x20000000
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to boards that
have LEDs
CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
stack. If defined, this symbol is the size of the interrupt
stack in bytes. If not defined, the user task stacks will be
used during interrupt handling.
CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to board architecture.
Individual subsystems can be enabled:
CONFIG_SAMD2L2_WDT - Watchdog Timer"
CONFIG_SAMD2L2_RTC - Real Time Counter"
CONFIG_SAMD2L2_NVMCTRL - Non-Volatile Memory Controller"
CONFIG_SAMD2L2_EVSYS - Event System"
CONFIG_SAMD2L2_SERCOM0 - Serial Communication Interface 0"
CONFIG_SAMD2L2_SERCOM1 - Serial Communication Interface 1"
CONFIG_SAMD2L2_SERCOM2 - Serial Communication Interface 2"
CONFIG_SAMD2L2_SERCOM3 - Serial Communication Interface 3"
CONFIG_SAMD2L2_SERCOM4 - Serial Communication Interface 4"
CONFIG_SAMD2L2_SERCOM5 - Serial Communication Interface 5"
CONFIG_SAMD2L2_TC0 - Timer/Counter 0"
CONFIG_SAMD2L2_TC1 - Timer/Counter 1"
CONFIG_SAMD2L2_TC2 - Timer/Counter 2"
CONFIG_SAMD2L2_TC3 - Timer/Counter 3"
CONFIG_SAMD2L2_TC4 - Timer/Counter 4"
CONFIG_SAMD2L2_TC5 - Timer/Counter 5"
CONFIG_SAMD2L2_TC6 - Timer/Counter 6"
CONFIG_SAMD2L2_TC7 - Timer/Counter 6"
CONFIG_SAMD2L2_ADC - Analog-to-Digital Converter"
CONFIG_SAMD2L2_AC - Analog Comparator"
CONFIG_SAMD2L2_DAC - Digital-to-Analog Converter"
CONFIG_SAMD2L2_PTC - Peripheral Touch Controller"
Some subsystems can be configured to operate in different ways. The drivers
need to know how to configure the subsystem.
CONFIG_SAMD2L2_SERCOM0_ISI2C, CONFIG_SAMD2L2_SERCOM0_ISSPI, or CONFIG_SAMD2L2_SERCOM0_ISUSART
CONFIG_SAMD2L2_SERCOM1_ISI2C, CONFIG_SAMD2L2_SERCOM1_ISSPI, or CONFIG_SAMD2L2_SERCOM1_ISUSART
CONFIG_SAMD2L2_SERCOM2_ISI2C, CONFIG_SAMD2L2_SERCOM2_ISSPI, or CONFIG_SAMD2L2_SERCOM2_ISUSART
CONFIG_SAMD2L2_SERCOM3_ISI2C, CONFIG_SAMD2L2_SERCOM3_ISSPI, or CONFIG_SAMD2L2_SERCOM3_ISUSART
CONFIG_SAMD2L2_SERCOM4_ISI2C, CONFIG_SAMD2L2_SERCOM4_ISSPI, or CONFIG_SAMD2L2_SERCOM4_ISUSART
CONFIG_SAMD2L2_SERCOM5_ISI2C, CONFIG_SAMD2L2_SERCOM5_ISSPI, or CONFIG_SAMD2L2_SERCOM5_ISUSART
SAMD20 specific device driver settings
CONFIG_USARTn_SERIAL_CONSOLE - selects the USARTn (n=0,1,2,..5) for the
console and ttys0 (default is the USART4).
CONFIG_USARTn_RXBUFSIZE - Characters are buffered as received.
This specific the size of the receive buffer
CONFIG_USARTn_TXBUFSIZE - Characters are buffered before
being sent. This specific the size of the transmit buffer
CONFIG_USARTn_BAUD - The configure BAUD of the USART. Must be
CONFIG_USARTn_BITS - The number of bits. Must be either 7 or 8.
CONFIG_USARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity
CONFIG_USARTn_2STOP - Two stop bits
Configurations
==============
Each SAMD20 Xplained Pro configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh samd20-xplained:<subdir>
Before building, make sure that the PATH environment variable include the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of the following.
NOTE: These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output of on SERCOM4 which is available on EXT1, EXT2, or EXT3 (see
the section "Serial Consoles" above). The virtual COM port could
be used, instead, by reconfiguring to use SERCOM3 instead of
SERCOM4:
System Type -> SAMD/L Peripheral Support
CONFIG_SAMD2L2_SERCOM3=y : Enable one or both
CONFIG_SAMD2L2_SERCOM4=n
Device Drivers -> Serial Driver Support -> Serial Console
CONFIG_USART4_SERIAL_CONSOLE=y : Select only one for the console
CONFIG_USART4_SERIAL_CONSOLE=n
Device Drivers -> Serial Driver Support -> SERCOM3 Configuration
CONFIG_USART3_2STOP=0
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_RXBUFSIZE=256
CONFIG_USART3_TXBUFSIZE=256
Device Drivers -> Serial Driver Support -> SERCOM4 Configuration
CONFIG_USART4_2STOP=0
CONFIG_USART4_BAUD=115200
CONFIG_USART4_BITS=8
CONFIG_USART4_PARITY=0
CONFIG_USART4_RXBUFSIZE=256
CONFIG_USART4_TXBUFSIZE=256
Board Selection -> USART4 Connection
CONFIG_SAMD20_XPLAINED_USART4_EXT1=n : Pick on if USART4 used
CONFIG_SAMD20_XPLAINED_USART4_EXT2=n
CONFIG_SAMD20_XPLAINED_USART4_EXT3=y
3. Unless otherwise stated, the configurations are setup for
Cygwin under Windows:
Build Setup:
CONFIG_HOST_WINDOWS=y : Windows Host
CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on windows
4. These configurations use the GNU EABI toolchain. But
that is easily reconfigured:
System Type -> Toolchain:
CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIW=y
Any re-configuration should be done before making NuttX or else the
subsequent 'make' will fail. If you have already attempted building
NuttX then you will have to 1) 'make distclean' to remove the old
configuration, 2) 'tools/configure.sh sam3u-ek/ksnh' to start
with a fresh configuration, and 3) perform the configuration changes
above.
Also, make sure that your PATH variable has the new path to your
Atmel tools. Try 'which arm-none-eabi-gcc' to make sure that you
are selecting the right tool.
See also the "NOTE about Windows native toolchains" in the section
called "GNU Toolchain Options" above.
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES above
and below:
NOTES:
1. This configuration is set up to build on Windows using the Cygwin
environment using the ARM EABI toolchain. This can be easily
changed as described above under "Configurations."
2. By default, this configuration provides a serial console on SERCOM4
at 115200 8N1 via EXT3:
PIN EXT3 GPIO Function
---- ---- ------------------
13 PB11 SERCOM4 / USART RX
14 PB12 SERCOM4 / USART TX
19 GND N/A
20 VCC N/A
If you would prefer to use the EDBG serial COM port or would prefer
to use SERCOM4 on EXT1 or EXT2, you will need to reconfigure the
SERCOM as described under "Configurations". See also the section
entitled "Serial Consoles" above.
3. NOTE: If you get a compilation error like:
libxx_new.cxx:74:40: error: 'operator new' takes type 'size_t'
('unsigned int') as first parameter [-fper
Sometimes NuttX and your toolchain will disagree on the underlying
type of size_t; sometimes it is an 'unsigned int' and sometimes it is
an 'unsigned long int'. If this error occurs, then you may need to
toggle the value of CONFIG_ARCH_SIZET_LONG.
4. If the I/O1 module is connected to the SAMD20 Xplained Pro, then
support for the SD card slot can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
File Systems:
CONFIG_FS_FAT=y : Enable the FAT file system
CONFIG_FAT_LCNAMES=y : Enable upper/lower case 8.3 file names (Optional, see below)
CONFIG_FAT_LFN=y : Enable long file named (Optional, see below)
CONFIG_FAT_MAXFNAME=32 : Maximum supported file name length
There are issues related to patents that Microsoft holds on FAT long
file name technologies. See the top level NOTICE file for further
details.
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM0=y : Use SERCOM0 if the I/O is in EXT1
CONFIG_SAMD2L2_SERCOM0_ISSPI=y : Configure SERCOM0 as an SPI master
Device Drivers
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_MMCSD=y : Enable MMC/SD support
CONFIG_MMCSD_NSLOTS=1 : Only one MMC/SD card slot
CONFIG_MMCSD_MULTIBLOCK_DISABLE=n : Should not need to disable multi-block transfers
CONFIG_MMCSD_MMCSUPPORT=n : May interfere with some SD cards
CONFIG_MMCSD_HAVE_CARDDETECT=y : I/O1 module as a card detect GPIO
CONFIG_MMCSD_SPI=y : Use the SPI interface to the MMC/SD card
CONFIG_MMCSD_SPICLOCK=20000000 : This is a guess for the optimal MMC/SD frequency
CONFIG_MMCSD_SPIMODE=0 : Mode 0 is required
Board Selection -> Common Board Options
CONFIG_NSH_MMCSDSLOTNO=0 : Only one MMC/SD slot, slot 0
CONFIG_NSH_MMCSDSPIPORTNO=0 : Use port=0 -> SERCOM0 if the I/O1 is in EXT1
Board Selection -> SAMD20 Xplained Pro Modules
CONFIG_SAMD20_XPLAINED_IOMODULE=y : I/O1 module is connected
CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1=y : I/O1 modules is in EXT1
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : Board has architecture-specific initialization
NOTE: If you enable the I/O1 this configuration with SERCOM4 as the
console and with the I/O1 module in EXT1, you *must* remove USART
jumper. Otherwise, you have lookpack on SERCOM4 and NSH will *not*
behave very well (since its outgoing prompts also appear as incoming
commands).
STATUS: As of 2013-6-18, this configuration appears completely
functional. Testing, however, has been very light. Example:
NuttShell (NSH) NuttX-6.34
nsh> mount -t vfat /dev/mmcsd0 /mnt/stuff
nsh> ls /mnt/stuff
/mnt/stuff:
nsh> echo "This is a test" >/mnt/stuff/atest.txt
nsh> ls /mnt/stuff
/mnt/stuff:
atest.txt
nsh> cat /mnt/stuff/atest.txt
This is a test
nsh>
5. If the OLED1 module is connected to the SAMD20 Xplained Pro, then
support for the OLED display can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM1=y : Use SERCOM1 if the I/O is in EXT2
CONFIG_SAMD2L2_SERCOM1_ISSPI=y : Configure SERCOM1 as an SPI master
Device Drivers -> SPI
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_SPI_CMDDATA=y : CMD/DATA support is required
Device Drivers -> LCDs
CONFIG_LCD=y : Enable LCD support
CONFIG_LCD_MAXCONTRAST=255 : Maximum contrast value
CONFIG_LCD_LANDSCAPE=y : Landscape orientation (see below*)
CONFIG_LCD_UG2832HSWEG04=y : Enable support for the OLED
CONFIG_LCD_SSD1306_SPIMODE=0 : SPI Mode 0
CONFIG_LCD_SSD1306_SPIMODE=3500000 : Pick an SPI frequency
Board Selection -> SAMD20 Xplained Pro Modules
CONFIG_SAMD20_XPLAINED_OLED1MODULE=y : OLED1 module is connected
CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2=y : OLED1 modules is in EXT2
The NX graphics subsystem also needs to be configured:
CONFIG_NX=y : Enable graphics support
CONFIG_NX_LCDDRIVER=y : Using an LCD driver
CONFIG_NX_NPLANES=1 : With a single color plane
CONFIG_NX_WRITEONLY=n : You can read from the LCD (see below**)
CONFIG_NX_DISABLE_2BPP=y : Disable all resolutions except 1BPP
CONFIG_NX_DISABLE_4BPP=y
CONFIG_NX_DISABLE_8BPP=y
CONFIG_NX_DISABLE_16BPP=y
CONFIG_NX_DISABLE_24BPP=y
CONFIG_NX_DISABLE_32BPP=y
CONFIG_NX_PACKEDMSFIRST=y : LSB packed first (shouldn't matter)
CONFIG_NXSTART_EXTERNINIT=y : We have board_graphics_setup()
CONFIG_NXTK_BORDERWIDTH=2 : Use a small border
CONFIG_NXTK_DEFAULT_BORDERCOLORS=y : Default border colors
CONFIG_NXFONTS_CHARBITS=7 : 7-bit fonts
CONFIG_NXFONT_SANS17X23B=y : Pick a font (any that will fit)
* This orientation will put the buttons "above" the LCD. The
reverse landscape configuration (CONFIG_LCD_RLANDSCAPE) will
"flip" the display so that the buttons are "below" the LCD.
** The hardware is write only, but the driver maintains a frame buffer
to support read and read-write-modiry operations on the LCD.
Reading from the frame buffer is, however, untested.
Then, in order to use the OLED, you will need to build some kind of
graphics application or use one of the NuttX graphics examples.
Here, for example, is the setup for the graphic "Hello, World!"
example:
CONFIG_EXAMPLES_NXHELLO=y : Enables the example
CONFIG_EXAMPLES_NXHELLO_DEFAULT_COLORS=y : Use default colors (see below *)
CONFIG_EXAMPLES_NXHELLO_DEFAULT_FONT=y : Use the default font
CONFIG_EXAMPLES_NXHELLO_BPP=1 : One bit per pixel
CONFIG_EXAMPLES_NXHELLO_EXTERNINIT=y : Special initialization is required.
* The OLED is monochrome so the only "colors" are blacka nd white.
The default "colors" will give you while text on a black background.
You can override the faults it you want black text on a while background.
NOTE: One issue that I have seen with the NXHello example when
running as an NSH command is that it only works the first time.
So, after you run the 'nxhello' command one time, you will have to
reset the board before you run it again.
This is clearly some issue with initializing, un-initializing, and
then re-initializing. If you want to fix this, patches are quite
welcome.

View File

@ -0,0 +1,65 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_POSIX_TIMERS is not set
# CONFIG_NSH_DISABLEBG is not set
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_CMP is not set
# CONFIG_NSH_DISABLE_DD is not set
# CONFIG_NSH_DISABLE_EXEC is not set
# CONFIG_NSH_DISABLE_EXIT is not set
# CONFIG_NSH_DISABLE_GET is not set
# CONFIG_NSH_DISABLE_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
# CONFIG_NSH_DISABLE_LOSETUP is not set
# CONFIG_NSH_DISABLE_MKRD is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_SEMICOLON is not set
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="samd20-xplained"
CONFIG_ARCH_BOARD_SAMD20_XPLAINED=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_SAMD20J18=y
CONFIG_ARCH_CHIP_SAMD2X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=3410
CONFIG_BUILTIN=y
CONFIG_DEFAULT_SMALL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=32768
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMD2L2_SERCOM3=y
CONFIG_SAMD2L2_SERCOM4=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=12
CONFIG_START_MONTH=2
CONFIG_START_YEAR=2014
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USART4_RXBUFSIZE=64
CONFIG_USART4_SERIAL_CONSOLE=y
CONFIG_USART4_TXBUFSIZE=64
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,515 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_INCLUDE_BOARD_H
#define __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
# ifdef CONFIG_SAMD2L2_GPIOIRQ
# include <arch/irq.h>
# endif
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Clocking *****************************************************************/
/* Overview
*
* OSC8M Output = 8MHz
* `- GCLK1 Input = 8MHz Prescaler = 1 output = 8MHz
* `- DFLL Input = 8MHz Multiplier = 6 output = 48MHz
* `- GCLK0 Input = 48MHz Prescaler = 1 output = 48MHz
* `- PM Input = 48Mhz CPU divider = 1 CPU frequency = 48MHz
* APBA divider = 1 APBA frequency = 48MHz
* APBB divider = 1 APBB frequency = 48MHz
* APBC divider = 1 APBC frequency = 48MHz
*
* The SAMD20 Xplained Pro has one on-board crystal:
*
* XC101 32.768KHz XOSC32
*
* REVISIT: Not currently used, may want to use as GCLK1 source with
* DFLL multiplier of ((48000000+16384)/32768) = 1465 which would yield
* a clock of 48,005,120 MHz.
*/
/* XOSC Configuration -- Not available
*
* BOARD_XOSC_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC_FREQUENCY - In Hz
* BOARD_XOSC_STARTUPTIME - See SYSCTRL_XOSC_STARTUP_* definitions
* BOARD_XOSC_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC_AMPGC - Boolean (defined / not defined)
* BOARD_XOSC_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC_ENABLE
#define BOARD_XOSC_FREQUENCY 12000000UL
#define BOARD_XOSC_STARTUPTIME SYSCTRL_XOSC_STARTUP_1S
#define BOARD_XOSC_ISCRYSTAL 1
#define BOARD_XOSC_AMPGC 1
#define BOARD_XOSC_ONDEMAND 1
#undef BOARD_XOSC_RUNINSTANDBY
/* XOSC32 Configuration -- Not used
*
* BOARD_XOSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC32K_FREQUENCY - In Hz
* BOARD_XOSC32K_STARTUPTIME - See SYSCTRL_XOSC32K_STARTUP_* definitions
* BOARD_XOSC32K_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC32K_AAMPEN - Boolean (defined / not defined)
* BOARD_XOSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC32K_ENABLE
#define BOARD_XOSC32K_FREQUENCY 32768 /* 32.768KHz XTAL */
#define BOARD_XOSC32K_STARTUPTIME SYSCTRL_XOSC32K_STARTUP_2S
#define BOARD_XOSC32K_ISCRYSTAL 1
#define BOARD_XOSC32K_AAMPEN 1
#undef BOARD_XOSC32K_EN1KHZ
#define BOARD_XOSC32K_EN32KHZ 1
#define BOARD_XOSC32K_ONDEMAND 1
#undef BOARD_XOSC32K_RUNINSTANDBY
/* OSC32 Configuration -- not used
*
* BOARD_OSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_OSC32K_FREQUENCY - In Hz
* BOARD_OSC32K_STARTUPTIME - See SYSCTRL_OSC32K_STARTUP_* definitions
* BOARD_OSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_OSC32K_ENABLE
#define BOARD_OSC32K_FREQUENCY 32768 /* 32.768kHz internal oscillator */
#define BOARD_OSC32K_STARTUPTIME SYSCTRL_OSC32K_STARTUP_4MS
#define BOARD_OSC32K_EN1KHZ 1
#define BOARD_OSC32K_EN32KHZ 1
#define BOARD_OSC32K_ONDEMAND 1
#undef BOARD_OSC32K_RUNINSTANDBY
/* OSC8M Configuration -- always enabled
*
* BOARD_OSC8M_PRESCALER - See SYSCTRL_OSC8M_PRESC_DIV* definitions
* BOARD_OSC8M_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC8M_RUNINSTANDBY - Boolean (defined / not defined)
*/
#define BOARD_OSC8M_PRESCALER SYSCTRL_OSC8M_PRESC_DIV1
#define BOARD_OSC8M_ONDEMAND 1
#undef BOARD_OSC8M_RUNINSTANDBY
#define BOARD_OSC8M_FREQUENCY 8000000 /* 8MHz high-accuracy internal oscillator */
/* OSCULP32K Configuration -- not used. */
#define BOARD_OSCULP32K_FREQUENCY 32000 /* 32kHz ultra-low-power internal oscillator */
/* Digital Frequency Locked Loop configuration. In closed-loop mode, the
* DFLL output frequency (Fdfll) is given by:
*
* Fdfll = DFLLmul * Frefclk
* = 6 * 8000000 = 48MHz
*
* Where the reference clock is Generic Clock Channel 0 output of GLCK1.
* GCLCK1 provides OSC8M, undivided.
*
* When operating in open-loop mode, the output frequency of the DFLL will
* be determined by the values written to the DFLL Coarse Value bit group
* and the DFLL Fine Value bit group in the DFLL Value register.
*
* BOARD_DFLL_OPENLOOP - Boolean (defined / not defined)
* BOARD_DFLL_TRACKAFTERFINELOCK - Boolean (defined / not defined)
* BOARD_DFLL_KEEPLOCKONWAKEUP - Boolean (defined / not defined)
* BOARD_DFLL_ENABLECHILLCYCLE - Boolean (defined / not defined)
* BOARD_DFLL_QUICKLOCK - Boolean (defined / not defined)
* BOARD_DFLL_ONDEMAND - Boolean (defined / not defined)
*
* Closed loop mode only:
* BOARD_DFLL_GCLKGEN - GCLK index
* BOARD_DFLL_MULTIPLIER - Value
* BOARD_DFLL_MAXCOARSESTEP - Value
* BOARD_DFLL_MAXFINESTEP - Value
*
* BOARD_DFLL_FREQUENCY - The resulting frequency
*/
#define BOARD_DFLL_ENABLE 1
#define BOARD_DFLL_OPENLOOP 1
#undef BOARD_DFLL_ONDEMAND
#undef BOARD_DFLL_RUNINSTANDBY
/* DFLL closed loop mode configuration */
#define BOARD_DFLL_SRCGCLKGEN 1
#define BOARD_DFLL_MULTIPLIER 6
#define BOARD_DFLL_QUICKLOCK 1
#define BOARD_DFLL_TRACKAFTERFINELOCK 1
#define BOARD_DFLL_KEEPLOCKONWAKEUP 1
#define BOARD_DFLL_ENABLECHILLCYCLE 1
#define BOARD_DFLL_MAXCOARSESTEP (0x1f / 4)
#define BOARD_DFLL_MAXFINESTEP (0xff / 4)
#define BOARD_DFLL_FREQUENCY (48000000)
/* GCLK Configuration
*
* Global enable/disable.
*
* BOARD_GCLK_ENABLE - Boolean (defined / not defined)
*
* For n=1-7:
* BOARD_GCLKn_ENABLE - Boolean (defined / not defined)
*
* For n=0-8:
* BOARD_GCLKn_RUN_IN_STANDBY - Boolean (defined / not defined)
* BOARD_GCLKn_CLOCK_SOURCE - See GCLK_GENCTRL_SRC_* definitions
* BOARD_GCLKn_PRESCALER - Value
* BOARD_GCLKn_OUTPUT_ENABLE - Boolean (defined / not defined)
*/
#define BOARD_GCLK_ENABLE 1
/* GCLK generator 0 (Main Clock) - Source is the DFLL */
#undef BOARD_GCLK0_RUN_IN_STANDBY
#define BOARD_GCLK0_CLOCK_SOURCE GCLK_GENCTRL_SRC_DFLL48M
#define BOARD_GCLK0_PRESCALER 1
#undef BOARD_GCLK0_OUTPUT_ENABLE
#define BOARD_GCLK0_FREQUENCY (BOARD_DFLL_FREQUENCY / BOARD_GCLK0_PRESCALER)
/* Configure GCLK generator 1 - Drives the DFLL */
#define BOARD_GCLK1_ENABLE 1
#undef BOARD_GCLK1_RUN_IN_STANDBY
#define BOARD_GCLK1_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK1_PRESCALER 1
#undef BOARD_GCLK1_OUTPUT_ENABLE
#define BOARD_GCLK1_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK1_PRESCALER)
/* Configure GCLK generator 2 (RTC) */
#undef BOARD_GCLK2_ENABLE
#undef BOARD_GCLK2_RUN_IN_STANDBY
#define BOARD_GCLK2_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC32K
#define BOARD_GCLK2_PRESCALER 32
#undef BOARD_GCLK2_OUTPUT_ENABLE
#define BOARD_GCLK2_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK2_PRESCALER)
/* Configure GCLK generator 3 */
#undef BOARD_GCLK3_ENABLE
#undef BOARD_GCLK3_RUN_IN_STANDBY
#define BOARD_GCLK3_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK3_PRESCALER 1
#undef BOARD_GCLK3_OUTPUT_ENABLE
#define BOARD_GCLK3_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK3_PRESCALER)
/* Configure GCLK generator 4 */
#undef BOARD_GCLK4_ENABLE
#undef BOARD_GCLK4_RUN_IN_STANDBY
#define BOARD_GCLK4_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK4_PRESCALER 1
#undef BOARD_GCLK4_OUTPUT_ENABLE
#define BOARD_GCLK4_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK4_PRESCALER)
/* Configure GCLK generator 5 */
#undef BOARD_GCLK5_ENABLE
#undef BOARD_GCLK5_RUN_IN_STANDBY
#define BOARD_GCLK5_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK5_PRESCALER 1
#undef BOARD_GCLK5_OUTPUT_ENABLE
#define BOARD_GCLK5_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK5_PRESCALER)
/* Configure GCLK generator 6 */
#undef BOARD_GCLK6_ENABLE
#undef BOARD_GCLK6_RUN_IN_STANDBY
#define BOARD_GCLK6_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK6_PRESCALER 1
#undef BOARD_GCLK6_OUTPUT_ENABLE
#define BOARD_GCLK6_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK6_PRESCALER)
/* Configure GCLK generator 7 */
#undef BOARD_GCLK7_ENABLE
#undef BOARD_GCLK7_RUN_IN_STANDBY
#define BOARD_GCLK7_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK7_PRESCALER 1
#undef BOARD_GCLK7_OUTPUT_ENABLE
#define BOARD_GCLK7_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK7_PRESCALER)
/* The source of the main clock is always GCLK_MAIN.
* Also called GCLKGEN[0], this is the clock feeding the Power Manager.
* The Power Manager, in turn, generates main clock which is divided
* down to produce the CPU, AHB, and APB clocks.
*
* The main clock is initially OSC8M divided by 8.
*/
#define BOARD_GCLK_MAIN_FREQUENCY BOARD_GCLK0_FREQUENCY
/* Main clock dividers
*
* BOARD_CPU_DIVIDER - See PM_CPUSEL_CPUDIV_* definitions
* BOARD_CPU_FRQUENCY - In Hz
* BOARD_CPU_FAILDECT - Boolean (defined / not defined)
* BOARD_APBA_DIVIDER - See M_APBASEL_APBADIV_* definitions
* BOARD_APBA_FRQUENCY - In Hz
* BOARD_APBB_DIVIDER - See M_APBBSEL_APBBDIV_* definitions
* BOARD_APBB_FRQUENCY - In Hz
* BOARD_APBC_DIVIDER - See M_APBCSEL_APBCDIV_* definitions
* BOARD_APBC_FRQUENCY - In Hz
*/
#define BOARD_CPU_FAILDECT 1
#define BOARD_CPU_DIVIDER PM_CPUSEL_CPUDIV_1
#define BOARD_APBA_DIVIDER PM_APBASEL_APBADIV_1
#define BOARD_APBB_DIVIDER PM_APBBSEL_APBBDIV_1
#define BOARD_APBC_DIVIDER PM_APBCSEL_APBCDIV_1
/* Resulting frequencies */
#define BOARD_MCK_FREQUENCY (BOARD_GCLK_MAIN_FREQUENCY)
#define BOARD_CPU_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBA_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBB_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBC_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBD_FREQUENCY (BOARD_MCK_FREQUENCY)
/* FLASH wait states
*
* Vdd Range Wait states Maximum Operating Frequency
* ------------- -------------- ---------------------------
* 1.62V to 2.7V 0 14 MHz
* 1 28 MHz
* 2 42 MHz
* 3 48 MHz
* 2.7V to 3.63V 0 24 MHz
* 1 48 MHz
*/
#if 0 /* REVISIT -- should not be necessary */
# define BOARD_FLASH_WAITSTATES 1
#else
# define BOARD_FLASH_WAITSTATES 2
#endif
/* SERCOM definitions *******************************************************/
/* This is the source clock generator for the GCLK_SERCOM_SLOW clock that
* is common to all SERCOM modules.
*/
#define BOARD_SERCOM05_SLOW_GCLKGEN 0
/* SERCOM0 SPI is available on EXT1
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA5 SERCOM0 PAD1 SPI SS
* 16 PA6 SERCOM0 PAD2 SPI MOSI
* 17 PA4 SERCOM0 PAD0 SPI MISO
* 18 PA7 SERCOM0 PAD3 SPI SCK
*/
#define BOARD_SERCOM0_GCLKGEN 0
#define BOARD_SERCOM0_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM0_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMAP_PAD0 PORT_SERCOM0_PAD0_2 /* SPI_MISO */
#define BOARD_SERCOM0_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM0_PINMAP_PAD2 PORT_SERCOM0_PAD2_2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMAP_PAD3 PORT_SERCOM0_PAD3_2 /* SPI_SCK */
#define BOARD_SERCOM0_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM1 SPI is available on EXT2
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA17 SERCOM1 PAD1 SPI SS
* 16 PA18 SERCOM1 PAD2 SPI MOSI
* 17 PA16 SERCOM1 PAD0 SPI MISO
* 18 PA19 SERCOM1 PAD3 SPI SCK
*/
#define BOARD_SERCOM1_GCLKGEN 0
#define BOARD_SERCOM1_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM1_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM1_PINMAP_PAD0 PORT_SERCOM1_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM1_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM1_PINMAP_PAD2 PORT_SERCOM1_PAD2_1 /* SPI_MOSI */
#define BOARD_SERCOM1_PINMAP_PAD3 PORT_SERCOM1_PAD3_1 /* SPI_SCK */
#define BOARD_SERCOM1_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SAMD20 Xplained Pro contains an Embedded Debugger (EDBG) that can be
* used to program and debug the ATSAMD20J18A using Serial Wire Debug (SWD).
* The Embedded debugger also include a Virtual COM port interface over
* SERCOM3. Virtual COM port connections:
*
* PA24 SERCOM3 / USART TXD
* PA25 SERCOM3 / USART RXD
*/
#define BOARD_SERCOM3_GCLKGEN 0
#define BOARD_SERCOM3_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM3_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
#define BOARD_SERCOM3_PINMAP_PAD0 0
#define BOARD_SERCOM3_PINMAP_PAD1 0
#define BOARD_SERCOM3_PINMAP_PAD2 PORT_SERCOM3_PAD2_1 /* USART TX */
#define BOARD_SERCOM3_PINMAP_PAD3 PORT_SERCOM3_PAD3_1 /* USART RX */
#define BOARD_SERCOM3_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SERCOM4 USART is available on connectors EXT1, EXT2, and EXT3
*
* PIN EXT1 EXT2 EXT3 GPIO Function
* ---- ---- ---- ---- ------------------
* 13 PB09 PB13 PB11 SERCOM4 / USART RX
* 14 PB08 PB12 PB12 SERCOM4 / USART TX
* 19 GND GND GND N/A
* 20 VCC VCC VCC N/A
*
* If you have a TTL to RS-232 converter then this is the most convenient
* serial console to use (because you don't lose the console device each time
* you lose the USB connection). It is the default in all of the SAMD20
* configurations.
*/
#define BOARD_SERCOM4_GCLKGEN 0
#define BOARD_SERCOM4_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#if defined(CONFIG_SAMD20_XPLAINED_USART4_EXT1)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0)
# define BOARD_SERCOM4_PINMAP_PAD0 PORT_SERCOM4_PAD0_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD1 PORT_SERCOM4_PAD1_3 /* USART RX */
# define BOARD_SERCOM4_PINMAP_PAD2 0
# define BOARD_SERCOM4_PINMAP_PAD3 0
#elif defined(CONFIG_SAMD20_XPLAINED_USART4_EXT2)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0)
# define BOARD_SERCOM4_PINMAP_PAD0 PORT_SERCOM4_PAD0_1 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD1 PORT_SERCOM4_PAD1_1 /* USART RX */
# define BOARD_SERCOM4_PINMAP_PAD2 0
# define BOARD_SERCOM4_PINMAP_PAD3 0
#else /* if defined(CONFIG_SAMD20_XPLAINED_USART4_EXT3) */
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
# define BOARD_SERCOM4_PINMAP_PAD0 0
# define BOARD_SERCOM4_PINMAP_PAD1 0
# define BOARD_SERCOM4_PINMAP_PAD2 PORT_SERCOM4_PAD2_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD3 PORT_SERCOM4_PAD3_3 /* USART RX */
#endif
#define BOARD_SERCOM4_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM5 SPI is available on EXT3
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PB17 SERCOM5 PAD1 SPI SS
* 16 PB22 SERCOM5 PAD2 SPI MOSI
* 17 PB16 SERCOM5 PAD0 SPI MISO
* 18 PB23 SERCOM5 PAD3 SPI SCK
*/
#define BOARD_SERCOM5_GCLKGEN 0
#define BOARD_SERCOM5_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM5_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM5_PINMAP_PAD0 PORT_SERCOM5_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM5_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM5_PINMAP_PAD2 PORT_SERCOM5_PAD2_4 /* SPI_MOSI */
#define BOARD_SERCOM5_PINMAP_PAD3 PORT_SERCOM5_PAD3_4 /* SPI_SCK */
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK0_FREQUENCY
/* LED definitions **********************************************************/
/* There are three LEDs on board the SAMD20 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD20
* USB connector.
*
* This LED is controlled by PC07 and the LED can be activated by driving
* the PA14 to GND.
*/
/* LED index values for use with board_userled() */
#define BOARD_STATUS_LED 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_STATUS LED_BIT (1 << BOARD_STATUS_LED)
/* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as defined below. Thus if the LED is statically on,
* NuttX has successfully booted and is, apparently, running normally.
* If the LED is flashing at approximately 2Hz,
* then a fatal error has been detected and the system has halted.
*/
#define LED_STARTED 0 /* STATUS LED=OFF */
#define LED_HEAPALLOCATE 0 /* STATUS LED=OFF */
#define LED_IRQSENABLED 0 /* STATUS LED=OFF */
#define LED_STACKCREATED 1 /* STATUS LED=ON */
#define LED_INIRQ 2 /* STATUS LED=no change */
#define LED_SIGNAL 2 /* STATUS LED=no change */
#define LED_ASSERTION 2 /* STATUS LED=no change */
#define LED_PANIC 3 /* STATUS LED=flashing */
/* Button definitions *******************************************************/
/* Mechanical buttons:
*
* The SAMD20 Xplained Pro contains two mechanical buttons.
* One button is the RESET button connected to the SAMD20 reset line and
* the other is a generic user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA15 SW0
*/
/* The SAMD20 Xplained Pro supports one button: */
#define BUTTON_SW0 0
#define NUM_BUTTONS 1
#define BUTTON_SW0_BIT (1 << BUTTON_SW0)
#endif /* __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_INCLUDE_BOARD_H */

View File

@ -0,0 +1,63 @@
############################################################################
# boards/arm/samd2l2/samd20-xplained/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv6-m/Toolchain.defs
LDSCRIPT = flash.ld
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif

View File

@ -0,0 +1,110 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/scripts/flash.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAMD20J18A has 256KB of FLASH beginning at address 0x0000:0000 and
* 32KB of SRAM beginning at address 0x2000:0000
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
ENTRY(_stext)
SECTIONS
{
.text : {
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section : {
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > flash
.ARM.extab : {
*(.ARM.extab*)
} >flash
.ARM.exidx : {
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >flash
.data : {
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
_eronly = LOADADDR(.data);
.ramfunc ALIGN(4): {
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > flash
_framfuncs = LOADADDR(.ramfunc);
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,53 @@
############################################################################
# boards/arm/samd2l2/samd20-xplained/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = sam_boot.c
ifeq ($(CONFIG_SAMD2L2_SERCOM0),y)
CSRCS += sam_spi.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
CSRCS += sam_userleds.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sam_buttons.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sam_appinit.c
endif
ifeq ($(CONFIG_SAMD20_XPLAINED_IOMODULE),y)
CSRCS += sam_mmcsd.c
endif
ifeq ($(CONFIG_SAMD20_XPLAINED_OLED1MODULE),y)
ifeq ($(CONFIG_LCD_UG2832HSWEG04),y)
CSRCS += sam_ug2832hsweg04.c
endif
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,123 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "samd20-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Some configuration checks */
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1
# ifndef SAMD2L2_HAVE_SPI0
# error I/O1 module on EXT1 requires SERCOM SPI0
# undef CONFIG_SAMD20_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 0
#endif
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2
# ifndef SAMD2L2_HAVE_SPI1
# error I/O1 module on EXT2 requires SERCOM SPI1
# undef CONFIG_SAMD20_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 1
#endif
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/* Support for the SD card slot on the I/O1 module */
/* Verify NSH PORT and SLOT settings */
# define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAMD2L2_MMCSDSLOTNO
# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO)
# endif
# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SPI_PORTNO
# error CONFIG_NSH_MMCSDSPIPORTNO must have the same value as SPI_PORTNO
# endif
/* Default MMC/SD minor number */
# ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
# endif
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
#if defined(SAMD2L2_HAVE_SPI0) && defined(CONFIG_SAMD20_XPLAINED_IOMODULE)
/* Initialize the SPI-based MMC/SD slot */
int ret = sam_sdinitialize(SPI_PORTNO, CONFIG_NSH_MMCSDMINOR);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize MMC/SD slot: %d\n",
ret);
return ret;
}
#endif
return OK;
}

View File

@ -0,0 +1,151 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_autoleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAMD20 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD20
* USB connector.
*
* This LED is controlled by PA14 and the LED can be activated by driving
* PA14 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt** N/C
* LED_SIGNAL In a signal handler*** N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd20-xplained.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
bool ledstate = true;
switch (led)
{
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
break; /* Leave ledstate == true to turn OFF */
default:
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
ledstate = false; /* Set ledstate == false to turn ON */
break;
}
sam_portwrite(PORT_STATUS_LED, ledstate);
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
/* These should not happen and are ignored */
default:
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
/* These result in no-change */
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
/* Turn STATUS LED off set driving the output high */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
sam_portwrite(PORT_STATUS_LED, true);
break;
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,76 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_boot.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "samd20-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_boardinitialize
*
* Description:
* All SAM3U architectures must provide the following entry point.
* This entry point is called early in the initialization -- after all
* memory has been configured and mapped but before any devices have been
* initialized.
*
****************************************************************************/
void sam_boardinitialize(void)
{
/* Configure SPI chip selects if
* 1) SPI is not disabled, and 2) the weak function
* sam_spidev_initialize() has been brought into the link.
*/
#ifdef SAMD2L2_HAVE_SPI
if (sam_spidev_initialize)
{
sam_spidev_initialize();
}
#endif
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
}

View File

@ -0,0 +1,127 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_buttons.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/irq.h>
#include <nuttx/irq.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd20-xplained.h"
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_button_initialize
*
* Description:
* board_button_initialize() must be called to initialize button resources.
* After that, board_buttons() may be called to collect the current state
* of all buttons or board_button_irq() may be called to register button
* interrupt handlers.
*
****************************************************************************/
uint32_t board_button_initialize(void)
{
sam_configport(PORT_SW0);
return NUM_BUTTONS;
}
/****************************************************************************
* Name: board_buttons
*
* Description:
* After board_button_initialize() has been called, board_buttons()
* may be called to collect the state of all buttons.
* board_buttons() returns an 32-bit bit set with each bit
* associated with a button.
* See the BUTTON* definitions above for the meaning of
* each bit in the returned value.
*
****************************************************************************/
uint32_t board_buttons(void)
{
return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT;
}
/****************************************************************************
* Name: board_button_irq
*
* Description:
* This function may be called to register an interrupt handler that will
* be called when a button is depressed or released. The ID value is one
* of the BUTTON* definitions provided above.
*
* Configuration Notes:
* Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the
* overall PORT IRQ feature and CONFIG_AVR32_PORTIRQSETA and/or
* CONFIG_AVR32_PORTIRQSETB must be enabled to select PORTs to support
* interrupts on. For button support, bits 2 and 3 must be set in
* CONFIG_AVR32_PORTIRQSETB (PB2 and PB3).
*
****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{
int ret = -EINVAL;
if (id == BUTTON_SW0)
{
irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the
* following operations are atomic.
*/
flags = enter_critical_section();
/* Configure the interrupt */
sam_portirq(IRQ_SW0);
irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0);
leave_critical_section(flags);
ret = OK;
}
return oldhandler;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */

View File

@ -0,0 +1,114 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_mmcsd.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h>
#include "sam_config.h"
#include "sam_spi.h"
#include "samd20-xplained.h"
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y)
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error SERCOM0 SPI support is required
#endif
#ifndef CONFIG_MMCSD
# error MMC/SD support is required (CONFIG_MMCSD)
#endif
#define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card. Requires
* - CONFIG_SAMD20_XPLAINED_IOMODULE=y,
* - CONFIG_DISABLE_MOUNTPOINT=n,
* - CONFIG_MMCSD=y, and
* - SAMD2L2_HAVE_SPI0=y
* (CONFIG_SAMD2L2_SERCOM0 && CONFIG_SAMD2L2_SERCOM0_ISSPI)
*
****************************************************************************/
int sam_sdinitialize(int port, int minor)
{
FAR struct spi_dev_s *spi;
int ret;
/* Get the SPI driver instance for the SD chip select */
finfo("Initializing SERCOM SPI%d\n", port);
spi = sam_spibus_initialize(port);
if (!spi)
{
ferr("ERROR: Failed to initialize SPI%d\n", port);
return -ENODEV;
}
finfo("Successfully initialized SPI%d\n", port);
/* Bind the SPI device for the chip select to the slot */
finfo("Binding SPI%d to MMC/SD slot %d\n", port, SAMD2L2_MMCSDSLOTNO);
ret = mmcsd_spislotinitialize(minor, SAMD2L2_MMCSDSLOTNO, spi);
if (ret < 0)
{
ferr("ERROR: Failed to bind SPI%d to MMC/SD slot %d: %d\n",
port, SAMD2L2_MMCSDSLOTNO, ret);
return ret;
}
finfo("Successfully bound SPI%d to MMC/SD slot %d\n",
port, SAMD2L2_MMCSDSLOTNO);
return OK;
}
#endif /* CONFIG_SAMD20_XPLAINED_IOMODULE */

View File

@ -0,0 +1,406 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_spi.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include "sam_config.h"
#include "sam_port.h"
#include "sam_spi.h"
#include "samd20-xplained.h"
#ifdef SAMD2L2_HAVE_SPI
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAMD20 Xplained
* Pro board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void)
{
/* The I/O module containing the SD connector may or may not be installed.
* And, if it is installed, it may be in connector EXT1 or EXT2.
*/
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
/* TODO: enable interrupt on card detect */
sam_configport(PORT_SD_CD); /* Card detect input */
sam_configport(PORT_SD_CS); /* Chip select output */
#endif
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE
sam_configport(PORT_OLED_DATA); /* Command/data */
sam_configport(PORT_OLED_CS); /* Card detect input */
#endif
}
/****************************************************************************
* Name: sam_spi[n]select, sam_spi[n]status, and sam_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic.
* They include:
*
* o sam_spi[n]select is a functions to manage the board-specific chip
* selects
* o sam_spi[n]status and sam_spi[n]cmddata: Implementations of the status
* and cmddata methods of the SPI interface defined by struct spi_ops_
* (see include/nuttx/spi/spi.h). All other methods including
* sam_spibus_initialize()) are provided by common SAMD/L logic.
*
* Where [n] is the SERCOM number for the SPI module.
*
* To use this common SPI logic on your board:
*
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide sam_spi[n]select() and sam_spi[n]status() functions in your
* board-specific logic. These functions will perform chip selection
* and status operations using GPIOs in the way your board is
* configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* sam_spi[n]cmddata() functions in your board-specific logic. This
* function will perform cmd/data selection operations using GPIOs in
* the way your board is configured.
* 3. Add a call to sam_spibus_initialize() in your low level application
* initialization logic
* 4. The handle returned by sam_spibus_initialize() may then be used to
* bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
/****************************************************************************
* Name: sam_spi[n]select
*
* Description:
* PIO chip select pins may be programmed by the board specific logic in
* one of two different ways. First, the pins may be programmed as SPI
* peripherals. In that case, the pins are completely controlled by the
* SPI driver. This method still needs to be provided, but it may be only
* a stub.
*
* An alternative way to program the PIO chip select pins is as a normal
* GPIO output. In that case, the automatic control of the CS pins is
* bypassed and this function must provide control of the chip select.
* NOTE: In this case, the GPIO output pin does *not* have to be the
* same as the NPCS pin normal associated with the chip select number.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
* selected - TRUE:Select the device, FALSE:De-select the device
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
void sam_spi0select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
void sam_spi1select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
void sam_spi2select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
void sam_spi3select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
void sam_spi4select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
void sam_spi5select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
/****************************************************************************
* Name: sam_spi[n]status
*
* Description:
* Return status information associated with the SPI device.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
uint8_t sam_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
uint8_t sam_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
uint8_t sam_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
uint8_t sam_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
uint8_t sam_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
return ret;
}
#endif
/****************************************************************************
* Name: sam_spi[n]cmddata
*
* Description:
* Some SPI devices require an additional control to determine if the SPI
* data being sent is a command or is data. If CONFIG_SPI_CMDDATA then
* this function will be called to different be command and data transfers.
*
* This is often needed, for example, by LCD drivers. Some LCD hardware
* may be configured to use 9-bit data transfers with the 9th bit
* indicating command or data. That same hardware may be configurable,
* instead, to use 8-bit data but to require an additional, board-
* specific GPIO control to distinguish command and data. This function
* would be needed in that latter case.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Zero on success; a negated errno on failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA
#ifdef SAMD2L2_HAVE_SPI0
int sam_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
int sam_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
int sam_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
int sam_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
int sam_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
int sam_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#endif /* CONFIG_SPI_CMDDATA */
#endif /* SAMD2L2_HAVE_SPI */

View File

@ -0,0 +1,191 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_ug2832hsweg04.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* OLED1 Connector:
*
* OLED1 CONNECTOR
* ----------------- ---------------------- ----------------------
* OLED1 EXT1 EXT2
* ----------------- ---------------------- ----------------------
* 1 ID 1 1
* ----------------- ---------------------- ----------------------
* 2 GND 2 GND 2 GND
* ----------------- ---------------------- ----------------------
* 3 BUTTON2 3 PB00 AIN[8] 3 PA10 AIN[18]
* ----------------- ---------------------- ----------------------
* 4 BUTTON3 4 PB01 AIN[9] 4 PA11 AIN[19]
* ----------------- ---------------------- ----------------------
* 5 DATA_CMD_SEL 5 PB06 PORT 5 PA20 PORT
* ----------------- ---------------------- ----------------------
* 6 LED3 6 PB07 PORT 6 PA21 PORT
* ----------------- ---------------------- ----------------------
* 7 LED1 7 PB02 TC6/WO[0] 7 PA22 TC4/WO[0]
* ----------------- ---------------------- ----------------------
* 8 LED2 8 PB03 TC6/WO[1] 8 PA23 TC4/WO[1]
* ----------------- ---------------------- ----------------------
* 9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
* ----------------- ---------------------- ----------------------
* 10 DISPLAY_RESET 10 PB05 PORT 10 PB15 PORT
* ----------------- ---------------------- ----------------------
* 11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0]
* I²C SDA I²C SDA
* ----------------- ---------------------- ----------------------
* 12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1]
* I²C SCL I²C SCL
* ----------------- ---------------------- ----------------------
* 13 N/C 13 PB09 SERCOM4 PAD[1] 13 PB13 SERCOM4 PAD[1]
* USART RX USART RX
* ----------------- ---------------------- ----------------------
* 14 N/C 14 PB08 SERCOM4 PAD[0] 14 PB12 SERCOM4 PAD[0]
* USART TX USART TX
* ----------------- ---------------------- ----------------------
* 15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
* SPI SS SPI SS
* ----------------- ---------------------- ----------------------
* 16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
* SPI MOSI SPI MOSI
* ----------------- ---------------------- ----------------------
* 17 N/C 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
* SPI MISO SPI MISO
* ----------------- ---------------------- ----------------------
* 18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
* SPI SCK SPI SCK
* ----------------- ---------------------- ----------------------
* 19 GND 19 GND GND
* ----------------- ---------------------- ----------------------
* 20 VCC 20 VCC VCC
* ----------------- ---------------------- ----------------------
*
* OLED1 signals
*
* DATA_CMD_SEL - Data/command select. Used to choose whether the
* communication is data to the display memory or a command to the LCD
* controller. High = data, low = command
* DISPLAY_RESET - Reset signal to the OLED display, active low. Used during
* initialization of the display.
* DISPLAY_SS - SPI slave select signal, must be held low during SPI
* communication.
* SPI_MOSI - SPI master out, slave in signal. Used to write data to the
* display
* SPI_SCK SPI - clock signal, generated by the master.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
#include "sam_port.h"
#include "sam_spi.h"
#include "samd20-xplained.h"
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* The pin configurations here require that SPI1 is selected */
#ifndef CONFIG_LCD_SSD1306
# error "The OLED driver requires CONFIG_LCD_SSD1306 in the configuration"
#endif
#ifndef CONFIG_LCD_UG2832HSWEG04
# error "The OLED driver requires CONFIG_LCD_UG2832HSWEG04 in the configuration"
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error "The OLED driver requires SAMD2L2_HAVE_SPI0 in the configuration"
#endif
#ifndef CONFIG_SPI_CMDDATA
# error "The OLED driver requires CONFIG_SPI_CMDDATA in the configuration"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_graphics_setup
*
* Description:
* Called by NX initialization logic to configure the OLED.
*
****************************************************************************/
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
{
FAR struct spi_dev_s *spi;
FAR struct lcd_dev_s *dev;
/* Configure the OLED PORTs. This initial configuration is RESET low,
* putting the OLED into reset state.
*/
sam_configport(PORT_OLED_RST);
/* Wait a bit then release the OLED from the reset state */
up_mdelay(20);
sam_portwrite(PORT_OLED_RST, true);
/* Get the SPI1 port interface */
spi = sam_spibus_initialize(OLED_CSNO);
if (!spi)
{
lcderr("ERROR: Failed to initialize SPI port 1\n");
}
else
{
/* Bind the SPI port to the OLED */
dev = ssd1306_initialize(spi, NULL, devno);
if (!dev)
{
lcderr("ERROR: Failed to bind SPI port 1 to OLED %d\n", devno);
}
else
{
lcdinfo("Bound SPI port 1 to OLED %d\n", devno);
/* And turn the OLED on */
dev->setpower(dev, CONFIG_LCD_MAXPOWER);
return dev;
}
}
return NULL;
}
#endif /* CONFIG_SAMD20_XPLAINED_OLED1MODULE */

View File

@ -0,0 +1,107 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/sam_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAMD20 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labeled STATUS near the SAMD20 USB
* connector.
*
* This LED is controlled by PA14 and the LED can be activated by driving
* PA14 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED. Otherwise, the LED can be controlled from user
* applications using the logic in this file.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd20-xplained.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the
* board_userled_initialize() is available to initialize the LED from user
* application logic.
*
****************************************************************************/
uint32_t board_userled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
return BOARD_NLEDS;
}
/****************************************************************************
* Name: board_userled
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is
* available to control the LED from user application logic.
*
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_STATUS_LED)
{
sam_portwrite(PORT_STATUS_LED, !ledon);
}
}
/****************************************************************************
* Name: board_userled_all
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled_all()
* is available to control the LED from user application logic.
* NOTE: since there is only a single LED on-board,
* this is function is not very useful.
*
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
board_userled(BOARD_STATUS_LED, (ledset & BOARD_STATUS_LED_BIT) != 0);
}
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,255 @@
/****************************************************************************
* boards/arm/samd2l2/samd20-xplained/src/samd20-xplained.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_SRC_SAMD20_XPLAINED_H
#define __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_SRC_SAMD20_XPLAINED_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <arch/irq.h>
#include <nuttx/irq.h>
#include "sam_config.h"
#include "sam_pinmap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* LEDs: There are three LEDs on board the SAMD20 Xplained Pro board:
* The EDBG controls two of the LEDs, a power LED and a status LED.
* There is only one user controllable LED, a yellow LED labelled STATIS
* near the SAMD20 USB connector.
*
* This LED is controlled by PA14 and the LED can be activated by driving
* PA14 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
#define PORT_STATUS_LED (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN14)
/* Mechanical buttons:
*
* The SAMD20 Xplained Pro contains two mechanical buttons. One button is the
* RESET button connected to the SAMD20 reset line and the other is a generic
* user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA15 SW0
*/
#define PORT_SW0 (PORT_INTERRUPT | PORT_PULL_UP | PORTA | PORT_PIN15)
#define IRQ_SW0 SAM_IRQ_PA15
/* I/O1
*
* Support for the microSD card slot on the I/O1 module.
* The I/O1 requires SPI support and two PORTs.
* These the PORTs will vary if the I/O1 is installed on the EXT1 or
* EXT2 connector:
*
* --- ------------------ ---------------------- --------------------------
* PIN EXT1 EXT2 Description
* --- ------------------ ---------------------- --------------------------
* 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1] Active low chip select
* SPI SS SPI SS OUTPUT, pulled high on
* board.
* --- ------------------ ---------------------- --------------------------
* 10 PB05 PORT 10 PB15 PORT Active low card detect
* INPUT, must use internal
* pull-up.
* --- ------------------ ---------------------- --------------------------
*/
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the I/O1 module
# endif
# if defined(CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1)
# if defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1)
# error I/O1 and OLED1 modules cannot both reside in EXT1
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN5)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2)
# if defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2)
# error I/O1 and OLED1 modules cannot both reside in EXT2
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN15)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the I/O1 module installed in?
# endif
#endif
/* OLED1
*
* Support for the microSD card slot on the I/O1 module.
* The I/O1 requires SPI support and three output PORTs.
* These the PORTs will vary if the OLED1is installed on the EXT1 or
* EXT2 connector:
*
* PIN EXT1 EXT2 Description
* --- ------------------- -------------------- ---------------------------
* 5 PB06 PORT PA20 PORT DATA_CMD_SEL
* 10 PB05 PORT PB15 PORT DISPLAY_RESET. Active low.
* 15 PA05 SERCOM0 PAD[1] PA17 SERCOM1 PAD[1] DISPLAY_SS. Active low.
* SPI SS SPI SS
*/
#ifdef CONFIG_SAMD20_XPLAINED_OLED1MODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the OLED1 module
# endif
# ifndef CONFIG_SPI_CMDDATA
# error CONFIG_SPI_CMDDATA is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_SSD1306
# error CONFIG_LCD_SSD1306 is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_UG2832HSWEG04
# error CONFIG_LCD_UG2832HSWEG04 is required to use the OLED1 module
# endif
# if defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT1)
# if defined(CONFIG_SAMD20_XPLAINED_IOMODULE) && \
defined(CONFIG_SAMD20_XPLAINED_IOMODULE_EXT1)
# error OLED1 and I/O1 modules cannot both reside in EXT1
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN6)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN5)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAMD20_XPLAINED_OLED1MODULE_EXT2)
# if defined(CONFIG_SAMD20_XPLAINED_IOMODULE) && \
defined(CONFIG_SAMD20_XPLAINED_IOMODULE_EXT2)
# error OLED1 and I/O1 modules cannot both reside in EXT2
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTA | PORT_PIN20)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN15)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the OLED1 module installed in?
# endif
#endif
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTB | PORT_PIN11) /* REVISIT */
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAM3U-EK board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void);
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card.
* Requires CONFIG_SAMD20_XPLAINED_IOMODULE=y,
* CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y,
* and the appropriate SERCOM SPI
* port enabled.
*
****************************************************************************/
#ifdef CONFIG_SAMD20_XPLAINED_IOMODULE
int sam_sdinitialize(int port, int minor);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_SAMD2L2_SAMD20_XPLAINED_SRC_SAMD20_XPLAINED_H */

View File

@ -0,0 +1,82 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_SAMD21_XPLAINED
menu "SAMD21 Xplained Pro Modules"
config SAMD21_XPLAINED_IOMODULE
bool "I/O1 Module"
default n
---help---
The I/O 1 module is attached. This module provides an MMC/SD card
slot.
if SAMD21_XPLAINED_IOMODULE
choice
prompt "I/O1 Module Location"
default SAMD21_XPLAINED_IOMODULE_EXT1
config SAMD21_XPLAINED_IOMODULE_EXT1
bool "EXT1"
config SAMD21_XPLAINED_IOMODULE_EXT2
bool "EXT2"
endchoice
endif
config SAMD21_XPLAINED_OLED1MODULE
bool "OLED1 Module"
default n
---help---
The OLED 1 module is attached. This module provides an OLED plus 3
additional switches and 3 additional LEDs.
if SAMD21_XPLAINED_OLED1MODULE
choice
prompt "OLED1 Module Location"
default SAMD21_XPLAINED_OLED1MODULE_EXT1
config SAMD21_XPLAINED_OLED1MODULE_EXT1
bool "EXT1"
config SAMD21_XPLAINED_OLED1MODULE_EXT2
bool "EXT2"
endchoice
endif
endmenu
if USART4_SERIAL_CONSOLE
choice
prompt "USART 4 Connection"
default SAMD21_XPLAINED_USART4_EXT3
config SAMD21_XPLAINED_USART4_EXT1
bool "EXT1"
depends on !SAMD21_XPLAINED_OLED1MODULE_EXT1 && !SAMD21_XPLAINED_IOMODULE_EXT1
---help---
Select this option if the serial console is on SERCOM4 connected via
EXT1. The RX will be on PB9 and TX signal will be on PB8.
config SAMD21_XPLAINED_USART4_EXT2
bool "EXT2"
depends on !SAMD21_XPLAINED_OLED1MODULE_EXT2 && !SAMD21_XPLAINED_IOMODULE_EXT2
---help---
Select this option if the serial console is on SERCOM4 connected via
EXT2. The RX will be on PB13 and TX signal will be on PB12.
config SAMD21_XPLAINED_USART4_EXT3
bool "EXT3"
---help---
Select this option if the serial console is on SERCOM4 connect via
EXT3. The RX will be on PB11 and TX signal will be on PB10.
endchoice
endif
endif

View File

@ -0,0 +1,744 @@
README
======
This README discusses issues unique to NuttX configurations for the
Atmel SAMD21 Xplained Pro development board. This board features the
ATSAMD21J18A MCU.
The SAMD21 Xplained Pro Starter Kit may be bundled with three modules:
1) I/O1 - An MMC/SD card slot, PWM LED control, ADC light sensor, USART
loopback, TWI AT30TSE758 Temperature sensor.
2) OLED1 - An OLED plus 3 additional switches and 3 additional LEDs
3) PROTO1 - A prototyping board with logic on board (other than power-related
logic).
Contents
========
- STATUS/ISSUES
- Modules
- LEDs
- Serial Consoles
- Atmel Studio 6.1
- SAMD21 Xplained Pro-specific Configuration Options
- Configurations
STATUS/ISSUES
=============
1. See boards/arm/samd2l2/samd20-xplained/README.txt.
This port derives from the SAMD20 Xplained board board and all issues
there should apply.
2. 2015-07-06: The basic NSH configuration is working properly, but
not at 115200 baud which is the default BAUD selection in the
configurations. It is necessary to drop the BAUD in the
configuration.
I suspect that this is an issue on my board and due to running the
system on uncalibrated OSC8M. My bet is that the issue would not
exist on many boards or if OSC8M were calibrated or if a more precise
clock source were used (like XOSC32K).
... After more experimentation, I am not sure this conclusion is
correct or not. Perhaps the board just comes up with a bad clocking
configuration at times????
Modules
=======
There are several I/O modules available that will work with the SAMD21
Xplained Pro Starter Kit:
1) I/O1 - An MMC/SD card slot, PWM LED control, ADC light sensor, USART
loopback, TWI AT30TSE758 Temperature sensor.
2) OLED1 - An OLED plus 3 additional switches and 3 additional LEDs
3) PROTO1 - A prototyping board with logic on board (other than power-
related logic).
4) And others. See http://www.atmel.com/products/microcontrollers/avr/xplained.aspx
Some of these are discussed further below.
I/O1
----
The primary function of this module is to provide SD card support, but
the full list of modules features include:
- microSD card connector (SPI interface)
- PWM (LED control)
- ADC (light sensor)
- USART loopback
- TWI AT30TSE758 Temperature sensor with EEPROM
SPI is available on two of the SAMD21 Xplained connectors, EXT1 and EXT2.
They mate with the I/O1 connector as indicated in this table.
I/O1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
I/O1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 LIGHT_SENSOR 3 PB00 AIN[8] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 LP_OUT 4 PB01 AIN[9] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 GPIO1 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 GPIO2 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED 7 PB02 TC6/WO[0] 7 PB12 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LP_IN 8 PB03 TC6/WO[1] 8 PB13 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 TEMP_ALERT 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 microSD_DETECT 10 PB05 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 TWI SDA 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 TWI SCL 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 USART RX 13 PB09 SERCOM4 PAD[1] 13 PB11 SERCOM4 PAD[1] EXT3
USART RX USART RX
----------------- ---------------------- ---------------------- ------------------------------------
14 USART TX 14 PB08 SERCOM4 PAD[0] 14 PB10 SERCOM4 PAD[0] EXT3
USART TX USART TX
----------------- ---------------------- ---------------------- ------------------------------------
15 microSD_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
SPI SS SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 SPI_MISO 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
The mapping between the I/O1 pins and the SD connector are shown in the
following table.
SD Card Connection
------------------
I/O1 SD PIN Description
---- ---- --- -------------------------------------------------
D2 1 Data line 2 (not used)
15 D3 2 Data line 3. Active low chip select, pulled high
16 CMD 3 Command line, connected to SPI_MOSI.
20 VDD 4
18 CLK 5 Clock line, connected to SPI_SCK.
2/19 GND 6
17 D0 7 Data line 0, connected to SPI_MISO.
D1 8 Data line 1 (not used)
10 SW_A 9 Card detect
2/19 SW_B 10 GND
Card Detect
-----------
When a microSD card is put into the connector SW_A and SW_B are short-
circuited. SW_A is connected to the microSD_DETECT signal. To use this
as a card indicator remember to enable internal pullup in the target
device.
GPIOs
-----
So all that is required to connect the SD is configure the SPI
--- ------------------ ---------------------- -------------------------------------
PIN EXT1 EXT2 Description
--- ------------------ ---------------------- -------------------------------------
15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1] Active low chip select OUTPUT, pulled
SPI SS SPI SS high on board.
--- ------------------ ---------------------- -------------------------------------
10 PB05 GPIO 10 PB15 GPIO Active low card detect INPUT, must
use internal pull-up.
--- ------------------ ---------------------- -------------------------------------
Configuration Options:
----------------------
CONFIG_SAMD21_XPLAINED_IOMODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
NOTE: As of this writing, only the SD card slot is supported in the I/O1
module.
OLED1
-----
This module provides an OLED plus 3 additional switches and 3 additional
LEDs.
OLED1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
OLED1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 BUTTON2 3 PB00 AIN[8] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 BUTTON3 4 PB01 AIN[9] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 DATA_CMD_SEL 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 LED3 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED1 7 PB02 TC6/WO[0] 7 PB12 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LED2 8 PB03 TC6/WO[1] 8 PB13 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 DISPLAY_RESET 10 PB05 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 N/C 13 PB09 SERCOM4 PAD[1] 13 PB11 SERCOM4 PAD[1] EXT3
USART RX USART RX
----------------- ---------------------- ---------------------- ------------------------------------
14 N/C 14 PB08 SERCOM4 PAD[0] 14 PB10 SERCOM4 PAD[0] EXT3
USART TX USART TX
----------------- ---------------------- ---------------------- ------------------------------------
15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
SPI SS SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 N/C 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
Configuration Options:
----------------------
CONFIG_SAMD21_XPLAINED_OLED1MODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
PROTO1
------
A prototyping board with logic on board (other than power-related logic).
There is no built-in support for the PROTO1 module.
LEDs
====
There is one yellow LED available on the SAM D20 Xplained Pro board that
can be turned on and off. The LED can be activated by driving the connected
PB30 I/O line to GND.
When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
control the LED as follows:
SYMBOL Meaning LED0
------------------- ----------------------- ------
LED_STARTED NuttX has been started OFF
LED_HEAPALLOCATE Heap has been allocated OFF
LED_IRQSENABLED Interrupts enabled OFF
LED_STACKCREATED Idle stack created ON
LED_INIRQ In an interrupt N/C
LED_SIGNAL In a signal handler N/C
LED_ASSERTION An assertion failed N/C
LED_PANIC The system has crashed FLASH
Thus is LED is statically on, NuttX has successfully booted and is,
apparently, running normally. If LED is flashing at approximately
2Hz, then a fatal error has been detected and the system has halted.
Serial Consoles
===============
SERCOM4
------
SERCOM4 is available on connectors EXT1, EXT2, and EXT3, but using
different PORT pins:
PIN EXT1 EXT2 EXT3 GPIO Function
---- ---- ---- ---- ------------------
13 PB09 PB10 PB10 SERCOM4 / USART RX
14 PB08 PB11 PB11 SERCOM4 / USART TX
19 GND GND GND N/A
20 VCC VCC VCC N/A
There are options available in the NuttX configuration to select which
connector SERCOM4 is on: SAMD21_XPLAINED_USART4_EXTn, where n=1, 2, or 3.
If you have a TTL to RS-232 converter then this is the most convenient
serial console to use (because you don't lose the console device each time
you lose the USB connection). It is the default in all of these
configurations. An option is to use the virtual COM port.
Virtual COM Port
----------------
The SAMD21 Xplained Pro contains an Embedded Debugger (EDBG) that can be
used to program and debug the ATSAMD21J18A using Serial Wire Debug (SWD).
The Embedded debugger also include a Virtual COM port interface over
SERCOM3. Virtual COM port connections:
PA22 SERCOM3 / USART TXD
PA23 SERCOM3 / USART RXD
Atmel Studio 6.1
================
Loading Code into FLASH:
-----------------------
Tools menus: Tools -> Device Programming.
Debugging the NuttX Object File
-------------------------------
1) Rename object file from nutt to nuttx.elf. That is an extension that
will be recognized by the file menu.
2) File menu: File -> Open -> Open object file for debugging
- Select nuttx.elf object file
- Select AT91SAMD21J18
- Select files for symbols as desired
- Select debugger
3) Debug menu: Debug -> Start debugging and break
- This will reload the nuttx.elf file into FLASH
SAMD21 Xplained Pro-specific Configuration Options
==================================================
CONFIG_ARCH - Identifies the arch/ subdirectory. This should
be set to:
CONFIG_ARCH=arm
CONFIG_ARCH_family - For use in C code:
CONFIG_ARCH_ARM=y
CONFIG_ARCH_architecture - For use in C code:
CONFIG_ARCH_CORTEXM0=y
CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_name - For use in C code to identify the exact
chip:
CONFIG_ARCH_CHIP_SAMD2X
CONFIG_ARCH_CHIP_SAMD21
CONFIG_ARCH_CHIP_ATSAMD21J18
CONFIG_ARCH_BOARD - Identifies the boards/ subdirectory and
hence, the board that supports the particular chip or SoC.
CONFIG_ARCH_BOARD=samd21-xplained (for the SAMD21 Xplained Pro development board)
CONFIG_ARCH_BOARD_name - For use in C code
CONFIG_ARCH_BOARD_SAMD21_XPLAINED=y
CONFIG_ARCH_LOOPSPERMSEC - Must be calibrated for correct operation
of delay loops
CONFIG_ENDIAN_BIG - define if big endian (default is little
endian)
CONFIG_RAM_SIZE - Describes the installed DRAM (SRAM in this case):
CONFIG_RAM_SIZE=0x00010000 (64KB)
CONFIG_RAM_START - The start address of installed DRAM
CONFIG_RAM_START=0x20000000
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to boards that
have LEDs
CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
stack. If defined, this symbol is the size of the interrupt
stack in bytes. If not defined, the user task stacks will be
used during interrupt handling.
CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to board architecture.
Individual subsystems can be enabled:
CONFIG_SAMD2L2_AC - Analog Comparator
CONFIG_SAMD2L2_ADC - Analog-to-Digital Converter
CONFIG_SAMD2L2_DAC - Digital-to-Analog Converter
CONFIG_SAMD2L2_DMAC - Analog Comparator
CONFIG_SAMD2L2_EVSYS - Event System
CONFIG_SAMD2L2_NVMCTRL - Non-Volatile Memory Controller
CONFIG_SAMD2L2_PTC - Peripheral Touch Controller
CONFIG_SAMD2L2_RTC - Real Time Counter
CONFIG_SAMD2L2_SERCOM0 - Serial Communication Interface 0
CONFIG_SAMD2L2_SERCOM1 - Serial Communication Interface 1
CONFIG_SAMD2L2_SERCOM2 - Serial Communication Interface 2
CONFIG_SAMD2L2_SERCOM3 - Serial Communication Interface 3
CONFIG_SAMD2L2_SERCOM4 - Serial Communication Interface 4
CONFIG_SAMD2L2_SERCOM5 - Serial Communication Interface 5
CONFIG_SAMD2L2_TCC0 - Timer/Counter 0 for Control
CONFIG_SAMD2L2_TCC1 - Timer/Counter 1 for Control
CONFIG_SAMD2L2_TCC2 - Timer/Counter 2 for Control
CONFIG_SAMD2L2_TC3 - Timer/Counter 3
CONFIG_SAMD2L2_TC4 - Timer/Counter 4
CONFIG_SAMD2L2_TC5 - Timer/Counter 5
CONFIG_SAMD2L2_TC6 - Timer/Counter 6
CONFIG_SAMD2L2_TC7 - Timer/Counter 6
CONFIG_SAMD2L2_USB - USB device or host
CONFIG_SAMD2L2_WDT - Watchdog Timer
Some subsystems can be configured to operate in different ways. The drivers
need to know how to configure the subsystem.
CONFIG_SAMD2L2_SERCOM0_ISI2C, CONFIG_SAMD2L2_SERCOM0_ISSPI, or CONFIG_SAMD2L2_SERCOM0_ISUSART
CONFIG_SAMD2L2_SERCOM1_ISI2C, CONFIG_SAMD2L2_SERCOM1_ISSPI, or CONFIG_SAMD2L2_SERCOM1_ISUSART
CONFIG_SAMD2L2_SERCOM2_ISI2C, CONFIG_SAMD2L2_SERCOM2_ISSPI, or CONFIG_SAMD2L2_SERCOM2_ISUSART
CONFIG_SAMD2L2_SERCOM3_ISI2C, CONFIG_SAMD2L2_SERCOM3_ISSPI, or CONFIG_SAMD2L2_SERCOM3_ISUSART
CONFIG_SAMD2L2_SERCOM4_ISI2C, CONFIG_SAMD2L2_SERCOM4_ISSPI, or CONFIG_SAMD2L2_SERCOM4_ISUSART
CONFIG_SAMD2L2_SERCOM5_ISI2C, CONFIG_SAMD2L2_SERCOM5_ISSPI, or CONFIG_SAMD2L2_SERCOM5_ISUSART
SAMD21 specific device driver settings
CONFIG_USARTn_SERIAL_CONSOLE - selects the USARTn (n=0,1,2,..5) for the
console and ttys0 (default is the USART4).
CONFIG_USARTn_RXBUFSIZE - Characters are buffered as received.
This specific the size of the receive buffer
CONFIG_USARTn_TXBUFSIZE - Characters are buffered before
being sent. This specific the size of the transmit buffer
CONFIG_USARTn_BAUD - The configure BAUD of the USART. Must be
CONFIG_USARTn_BITS - The number of bits. Must be either 7 or 8.
CONFIG_USARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity
CONFIG_USARTn_2STOP - Two stop bits
Configurations
==============
Each SAMD21 Xplained Pro configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh samd21-xplained:<subdir>
Before building, make sure the PATH environment variable include the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of the following.
NOTE: These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output of on SERCOM4 which is available on EXT1, EXT2, or EXT3 (see
the section "Serial Consoles" above). The virtual COM port could
be used, instead, by reconfiguring to use SERCOM3 instead of
SERCOM4:
System Type -> SAMD/L Peripheral Support
CONFIG_SAMD2L2_SERCOM3=y : Enable one or both
CONFIG_SAMD2L2_SERCOM4=n
Device Drivers -> Serial Driver Support -> Serial Console
CONFIG_USART4_SERIAL_CONSOLE=y : Select only one for the console
CONFIG_USART4_SERIAL_CONSOLE=n
Device Drivers -> Serial Driver Support -> SERCOM3 Configuration
CONFIG_USART3_2STOP=0
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_RXBUFSIZE=256
CONFIG_USART3_TXBUFSIZE=256
Device Drivers -> Serial Driver Support -> SERCOM4 Configuration
CONFIG_USART4_2STOP=0
CONFIG_USART4_BAUD=115200
CONFIG_USART4_BITS=8
CONFIG_USART4_PARITY=0
CONFIG_USART4_RXBUFSIZE=256
CONFIG_USART4_TXBUFSIZE=256
Board Selection -> USART4 Connection
CONFIG_SAMD21_XPLAINED_USART4_EXT1=n : Pick on if USART4 used
CONFIG_SAMD21_XPLAINED_USART4_EXT2=n
CONFIG_SAMD21_XPLAINED_USART4_EXT3=y
3. Unless otherwise stated, the configurations are setup for
Cygwin under Windows:
Build Setup:
CONFIG_HOST_WINDOWS=y : Windows Host
CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on windows
4. These configurations use the ARM EABI toolchain. But
that is easily reconfigured:
System Type -> Toolchain:
CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIW=y
Any re-configuration should be done before making NuttX or else the
subsequent 'make' will fail. If you have already attempted building
NuttX then you will have to 1) 'make distclean' to remove the old
configuration, 2) 'tools/configure.sh sam3u-ek/ksnh' to start
with a fresh configuration, and 3) perform the configuration changes
above.
Also, make sure that your PATH variable has the new path to your
Atmel tools. Try 'which arm-none-eabi-gcc' to make sure that you
are selecting the right tool.
See also the "NOTE about Windows native toolchains" in the section
called "GNU Toolchain Options" above.
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES above
and below:
NOTES:
1. This configuration is set up to build on Windows using the Cygwin
environment using the ARM EABI toolchain. This can be easily
changed as described above under "Configurations."
2. By default, this configuration provides a serial console on SERCOM4
at 115200 8N1 via EXT3:
PIN EXT3 GPIO Function
---- ---- ------------------
13 PB11 SERCOM4 / USART RX
14 PB10 SERCOM4 / USART TX
19 GND N/A
20 VCC N/A
If you would prefer to use the EDBG serial COM port or would prefer
to use SERCOM4 on EXT1 or EXT2, you will need to reconfigure the
SERCOM as described under "Configurations". See also the section
entitled "Serial Consoles" above.
3. NOTE: If you get a compilation error like:
libxx_new.cxx:74:40: error: 'operator new' takes type 'size_t'
('unsigned int') as first parameter [-fper
Sometimes NuttX and your toolchain will disagree on the underlying
type of size_t; sometimes it is an 'unsigned int' and sometimes it is
an 'unsigned long int'. If this error occurs, then you may need to
toggle the value of CONFIG_ARCH_SIZET_LONG.
4. If the I/O1 module is connected to the SAMD21 Xplained Pro, then
support for the SD card slot can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
File Systems:
CONFIG_FS_FAT=y : Enable the FAT file system
CONFIG_FAT_LCNAMES=y : Enable upper/lower case 8.3 file names (Optional, see below)
CONFIG_FAT_LFN=y : Enable long file named (Optional, see below)
CONFIG_FAT_MAXFNAME=32 : Maximum supported file name length
There are issues related to patents that Microsoft holds on FAT long
file name technologies. See the top level NOTICE file for further
details.
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM0=y : Use SERCOM0 if the I/O is in EXT1
CONFIG_SAMD2L2_SERCOM0_ISSPI=y : Configure SERCOM0 as an SPI master
Device Drivers
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_MMCSD=y : Enable MMC/SD support
CONFIG_MMCSD_NSLOTS=1 : Only one MMC/SD card slot
CONFIG_MMCSD_MULTIBLOCK_DISABLE=n : Should not need to disable multi-block transfers
CONFIG_MMCSD_MMCSUPPORT=n : May interfere with some SD cards
CONFIG_MMCSD_HAVE_CARDDETECT=y : I/O1 module as a card detect GPIO
CONFIG_MMCSD_SPI=y : Use the SPI interface to the MMC/SD card
CONFIG_MMCSD_SPICLOCK=20000000 : This is a guess for the optimal MMC/SD frequency
CONFIG_MMCSD_SPIMODE=0 : Mode 0 is required
Board Selection -> Common Board Options
CONFIG_NSH_MMCSDSLOTNO=0 : Only one MMC/SD slot, slot 0
CONFIG_NSH_MMCSDSPIPORTNO=0 : Use port=0 -> SERCOM0 if the I/O1 is in EXT1
Board Selection -> SAMD21 Xplained Pro Modules
CONFIG_SAMD21_XPLAINED_IOMODULE=y : I/O1 module is connected
CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1=y : I/O1 modules is in EXT1
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : Board has architecture-specific initialization
NOTE: If you enable the I/O1 this configuration with SERCOM4 as the
console and with the I/O1 module in EXT1, you *must* remove USART
jumper. Otherwise, you have lookpack on SERCOM4 and NSH will *not*
behave very well (since its outgoing prompts also appear as incoming
commands).
STATUS: As of 2013-6-18, this configuration appears completely
functional. Testing, however, has been very light. Example:
NuttShell (NSH) NuttX-6.34
nsh> mount -t vfat /dev/mmcsd0 /mnt/stuff
nsh> ls /mnt/stuff
/mnt/stuff:
nsh> echo "This is a test" >/mnt/stuff/atest.txt
nsh> ls /mnt/stuff
/mnt/stuff:
atest.txt
nsh> cat /mnt/stuff/atest.txt
This is a test
nsh>
5. If the OLED1 module is connected to the SAMD21 Xplained Pro, then
support for the OLED display can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM1=y : Use SERCOM1 if the I/O is in EXT2
CONFIG_SAMD2L2_SERCOM1_ISSPI=y : Configure SERCOM1 as an SPI master
Device Drivers -> SPI
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_SPI_CMDDATA=y : CMD/DATA support is required
Device Drivers -> LCDs
CONFIG_LCD=y : Enable LCD support
CONFIG_LCD_MAXCONTRAST=255 : Maximum contrast value
CONFIG_LCD_LANDSCAPE=y : Landscape orientation (see below*)
CONFIG_LCD_UG2832HSWEG04=y : Enable support for the OLED
CONFIG_LCD_SSD1306_SPIMODE=0 : SPI Mode 0
CONFIG_LCD_SSD1306_SPIMODE=3500000 : Pick an SPI frequency
Board Selection -> SAMD21 Xplained Pro Modules
CONFIG_SAMD21_XPLAINED_OLED1MODULE=y : OLED1 module is connected
CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2=y : OLED1 modules is in EXT2
The NX graphics subsystem also needs to be configured:
CONFIG_NX=y : Enable graphics support
CONFIG_NX_LCDDRIVER=y : Using an LCD driver
CONFIG_NX_NPLANES=1 : With a single color plane
CONFIG_NX_WRITEONLY=n : You can read from the LCD (see below**)
CONFIG_NX_DISABLE_2BPP=y : Disable all resolutions except 1BPP
CONFIG_NX_DISABLE_4BPP=y
CONFIG_NX_DISABLE_8BPP=y
CONFIG_NX_DISABLE_16BPP=y
CONFIG_NX_DISABLE_24BPP=y
CONFIG_NX_DISABLE_32BPP=y
CONFIG_NX_PACKEDMSFIRST=y : LSB packed first (shouldn't matter)
CONFIG_NXSTART_EXTERNINIT=y : We have board_graphics_setup()
CONFIG_NXTK_BORDERWIDTH=2 : Use a small border
CONFIG_NXTK_DEFAULT_BORDERCOLORS=y : Default border colors
CONFIG_NXFONTS_CHARBITS=7 : 7-bit fonts
CONFIG_NXFONT_SANS17X23B=y : Pick a font (any that will fit)
* This orientation will put the buttons "above" the LCD. The
reverse landscape configuration (CONFIG_LCD_RLANDSCAPE) will
"flip" the display so that the buttons are "below" the LCD.
** The hardware is write only, but the driver maintains a frame buffer
to support read and read-write-modiry operations on the LCD.
Reading from the frame buffer is, however, untested.
Then, in order to use the OLED, you will need to build some kind of
graphics application or use one of the NuttX graphics examples.
Here, for example, is the setup for the graphic "Hello, World!"
example:
CONFIG_EXAMPLES_NXHELLO=y : Enables the example
CONFIG_EXAMPLES_NXHELLO_DEFAULT_COLORS=y : Use default colors (see below *)
CONFIG_EXAMPLES_NXHELLO_DEFAULT_FONT=y : Use the default font
CONFIG_EXAMPLES_NXHELLO_BPP=1 : One bit per pixel
CONFIG_EXAMPLES_NXHELLO_EXTERNINIT=y : Special initialization is required.
* The OLED is monochrome so the only "colors" are blacka nd white.
The default "colors" will give you while text on a black background.
You can override the faults it you want black text on a while background.
NOTE: One issue that I have seen with the NXHello example when
running as an NSH command is that it only works the first time.
So, after you run the 'nxhello' command one time, you will have to
reset the board before you run it again.
This is clearly some issue with initializing, un-initializing, and
then re-initializing. If you want to fix this, patches are quite
welcome.

View File

@ -0,0 +1,65 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_POSIX_TIMERS is not set
# CONFIG_NSH_DISABLEBG is not set
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_CMP is not set
# CONFIG_NSH_DISABLE_DD is not set
# CONFIG_NSH_DISABLE_EXEC is not set
# CONFIG_NSH_DISABLE_EXIT is not set
# CONFIG_NSH_DISABLE_GET is not set
# CONFIG_NSH_DISABLE_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
# CONFIG_NSH_DISABLE_LOSETUP is not set
# CONFIG_NSH_DISABLE_MKRD is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_SEMICOLON is not set
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="samd21-xplained"
CONFIG_ARCH_BOARD_SAMD21_XPLAINED=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_SAMD21J18A=y
CONFIG_ARCH_CHIP_SAMD2X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=3410
CONFIG_BUILTIN=y
CONFIG_DEFAULT_SMALL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=32768
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SAMD2L2_SERCOM3=y
CONFIG_SAMD2L2_SERCOM4=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=21
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2015
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USART4_RXBUFSIZE=64
CONFIG_USART4_SERIAL_CONSOLE=y
CONFIG_USART4_TXBUFSIZE=64
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,529 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_INCLUDE_BOARD_H
#define __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
# ifdef CONFIG_SAMD2L2_GPIOIRQ
# include <arch/irq.h>
# endif
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Clocking *****************************************************************/
/* Overview
*
* OSC8M Output = 8MHz
* `- GCLK1 Input = 8MHz Prescaler = 1 output = 8MHz
* `- DFLL Input = 8MHz Multiplier = 6 output = 48MHz
* `- GCLK0 Input = 48MHz Prescaler = 1 output = 48MHz
* `- PM Input = 48Mhz CPU divider = 1 CPU frequency = 48MHz
* APBA divider = 1 APBA frequency = 48MHz
* APBB divider = 1 APBB frequency = 48MHz
* APBC divider = 1 APBC frequency = 48MHz
*
* The SAMD21 Xplained Pro has one on-board crystal:
*
* XC101 32.768KHz XOSC32
*
* REVISIT: Not currently used, may want to use as GCLK1 source with
* DFLL multiplier of ((48000000+16384)/32768) = 1465 which would yield
* a clock of 48,005,120 MHz.
*/
/* XOSC Configuration -- Not available
*
* BOARD_XOSC_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC_FREQUENCY - In Hz
* BOARD_XOSC_STARTUPTIME - See SYSCTRL_XOSC_STARTUP_* definitions
* BOARD_XOSC_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC_AMPGC - Boolean (defined / not defined)
* BOARD_XOSC_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC_ENABLE
#define BOARD_XOSC_FREQUENCY 12000000UL
#define BOARD_XOSC_STARTUPTIME SYSCTRL_XOSC_STARTUP_1S
#define BOARD_XOSC_ISCRYSTAL 1
#define BOARD_XOSC_AMPGC 1
#define BOARD_XOSC_ONDEMAND 1
#undef BOARD_XOSC_RUNINSTANDBY
/* XOSC32 Configuration -- Not used
*
* BOARD_XOSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC32K_FREQUENCY - In Hz
* BOARD_XOSC32K_STARTUPTIME - See SYSCTRL_XOSC32K_STARTUP_* definitions
* BOARD_XOSC32K_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC32K_AAMPEN - Boolean (defined / not defined)
* BOARD_XOSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC32K_ENABLE
#define BOARD_XOSC32K_FREQUENCY 32768 /* 32.768KHz XTAL */
#define BOARD_XOSC32K_STARTUPTIME SYSCTRL_XOSC32K_STARTUP_2S
#define BOARD_XOSC32K_ISCRYSTAL 1
#define BOARD_XOSC32K_AAMPEN 1
#undef BOARD_XOSC32K_EN1KHZ
#define BOARD_XOSC32K_EN32KHZ 1
#define BOARD_XOSC32K_ONDEMAND 1
#undef BOARD_XOSC32K_RUNINSTANDBY
/* OSC32 Configuration -- not used
*
* BOARD_OSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_OSC32K_FREQUENCY - In Hz
* BOARD_OSC32K_STARTUPTIME - See SYSCTRL_OSC32K_STARTUP_* definitions
* BOARD_OSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC32K_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_OSC32K_ENABLE
#define BOARD_OSC32K_FREQUENCY 32768 /* 32.768kHz internal oscillator */
#define BOARD_OSC32K_STARTUPTIME SYSCTRL_OSC32K_STARTUP_4MS
#define BOARD_OSC32K_EN1KHZ 1
#define BOARD_OSC32K_EN32KHZ 1
#define BOARD_OSC32K_ONDEMAND 1
#undef BOARD_OSC32K_RUNINSTANDBY
/* OSC8M Configuration -- always enabled
*
* BOARD_OSC8M_PRESCALER - See SYSCTRL_OSC8M_PRESC_DIV* definitions
* BOARD_OSC8M_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC8M_RUNINSTANDBY - Boolean (defined / not defined)
*/
#define BOARD_OSC8M_PRESCALER SYSCTRL_OSC8M_PRESC_DIV1
#define BOARD_OSC8M_ONDEMAND 1
#undef BOARD_OSC8M_RUNINSTANDBY
#define BOARD_OSC8M_FREQUENCY 8000000 /* 8MHz high-accuracy internal oscillator */
/* OSCULP32K Configuration -- not used. */
#define BOARD_OSCULP32K_FREQUENCY 32000 /* 32kHz ultra-low-power internal oscillator */
/* Digital Frequency Locked Loop configuration. In closed-loop mode, the
* DFLL output frequency (Fdfll) is given by:
*
* Fdfll = DFLLmul * Frefclk
* = 6 * 8000000 = 48MHz
*
* Where the reference clock is Generic Clock Channel 0 output of GLCK1.
* GCLCK1 provides OSC8M, undivided.
*
* When operating in open-loop mode, the output frequency of the DFLL will
* be determined by the values written to the DFLL Coarse Value bit group
* and the DFLL Fine Value bit group in the DFLL Value register.
*
* BOARD_DFLL_OPENLOOP - Boolean (defined / not defined)
* BOARD_DFLL_TRACKAFTERFINELOCK - Boolean (defined / not defined)
* BOARD_DFLL_KEEPLOCKONWAKEUP - Boolean (defined / not defined)
* BOARD_DFLL_ENABLECHILLCYCLE - Boolean (defined / not defined)
* BOARD_DFLL_QUICKLOCK - Boolean (defined / not defined)
* BOARD_DFLL_ONDEMAND - Boolean (defined / not defined)
*
* Closed loop mode only:
* BOARD_DFLL_GCLKGEN - GCLK index
* BOARD_DFLL_MULTIPLIER - Value
* BOARD_DFLL_MAXCOARSESTEP - Value
* BOARD_DFLL_MAXFINESTEP - Value
*
* BOARD_DFLL_FREQUENCY - The resulting frequency
*/
#define BOARD_DFLL_ENABLE 1
#define BOARD_DFLL_OPENLOOP 1
#undef BOARD_DFLL_ONDEMAND
#undef BOARD_DFLL_RUNINSTANDBY
/* DFLL closed loop mode configuration */
#define BOARD_DFLL_SRCGCLKGEN 1
#define BOARD_DFLL_MULTIPLIER 6
#define BOARD_DFLL_QUICKLOCK 1
#define BOARD_DFLL_TRACKAFTERFINELOCK 1
#define BOARD_DFLL_KEEPLOCKONWAKEUP 1
#define BOARD_DFLL_ENABLECHILLCYCLE 1
#define BOARD_DFLL_MAXCOARSESTEP (0x1f / 4)
#define BOARD_DFLL_MAXFINESTEP (0xff / 4)
#define BOARD_DFLL_FREQUENCY (48000000)
/* GCLK Configuration
*
* Global enable/disable.
*
* BOARD_GCLK_ENABLE - Boolean (defined / not defined)
*
* For n=1-7:
* BOARD_GCLKn_ENABLE - Boolean (defined / not defined)
*
* For n=0-8:
* BOARD_GCLKn_RUN_IN_STANDBY - Boolean (defined / not defined)
* BOARD_GCLKn_CLOCK_SOURCE - See GCLK_GENCTRL_SRC_* definitions
* BOARD_GCLKn_PRESCALER - Value
* BOARD_GCLKn_OUTPUT_ENABLE - Boolean (defined / not defined)
*/
#define BOARD_GCLK_ENABLE 1
/* GCLK generator 0 (Main Clock) - Source is the DFLL */
#undef BOARD_GCLK0_RUN_IN_STANDBY
#define BOARD_GCLK0_CLOCK_SOURCE GCLK_GENCTRL_SRC_DFLL48M
#define BOARD_GCLK0_PRESCALER 1
#undef BOARD_GCLK0_OUTPUT_ENABLE
#define BOARD_GCLK0_FREQUENCY (BOARD_DFLL_FREQUENCY / BOARD_GCLK0_PRESCALER)
/* Configure GCLK generator 1 - Drives the DFLL */
#define BOARD_GCLK1_ENABLE 1
#undef BOARD_GCLK1_RUN_IN_STANDBY
#define BOARD_GCLK1_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK1_PRESCALER 1
#undef BOARD_GCLK1_OUTPUT_ENABLE
#define BOARD_GCLK1_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK1_PRESCALER)
/* Configure GCLK generator 2 (RTC) */
#undef BOARD_GCLK2_ENABLE
#undef BOARD_GCLK2_RUN_IN_STANDBY
#define BOARD_GCLK2_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC32K
#define BOARD_GCLK2_PRESCALER 32
#undef BOARD_GCLK2_OUTPUT_ENABLE
#define BOARD_GCLK2_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK2_PRESCALER)
/* Configure GCLK generator 3 */
#undef BOARD_GCLK3_ENABLE
#undef BOARD_GCLK3_RUN_IN_STANDBY
#define BOARD_GCLK3_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK3_PRESCALER 1
#undef BOARD_GCLK3_OUTPUT_ENABLE
#define BOARD_GCLK3_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK3_PRESCALER)
/* Configure GCLK generator 4 */
#undef BOARD_GCLK4_ENABLE
#undef BOARD_GCLK4_RUN_IN_STANDBY
#define BOARD_GCLK4_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK4_PRESCALER 1
#undef BOARD_GCLK4_OUTPUT_ENABLE
#define BOARD_GCLK4_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK4_PRESCALER)
/* Configure GCLK generator 5 */
#undef BOARD_GCLK5_ENABLE
#undef BOARD_GCLK5_RUN_IN_STANDBY
#define BOARD_GCLK5_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK5_PRESCALER 1
#undef BOARD_GCLK5_OUTPUT_ENABLE
#define BOARD_GCLK5_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK5_PRESCALER)
/* Configure GCLK generator 6 */
#undef BOARD_GCLK6_ENABLE
#undef BOARD_GCLK6_RUN_IN_STANDBY
#define BOARD_GCLK6_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK6_PRESCALER 1
#undef BOARD_GCLK6_OUTPUT_ENABLE
#define BOARD_GCLK6_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK6_PRESCALER)
/* Configure GCLK generator 7 */
#undef BOARD_GCLK7_ENABLE
#undef BOARD_GCLK7_RUN_IN_STANDBY
#define BOARD_GCLK7_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC8M
#define BOARD_GCLK7_PRESCALER 1
#undef BOARD_GCLK7_OUTPUT_ENABLE
#define BOARD_GCLK7_FREQUENCY (BOARD_OSC8M_FREQUENCY / BOARD_GCLK7_PRESCALER)
/* The source of the main clock is always GCLK_MAIN. Also called GCLKGEN[0],
* this is the clock feeding the Power Manager.
* The Power Manager, in turn, generates main clock which is divided down to
* produce the CPU, AHB, and APB clocks.
*
* The main clock is initially OSC8M divided by 8.
*/
#define BOARD_GCLK_MAIN_FREQUENCY BOARD_GCLK0_FREQUENCY
/* Main clock dividers
*
* BOARD_CPU_DIVIDER - See PM_CPUSEL_CPUDIV_* definitions
* BOARD_CPU_FRQUENCY - In Hz
* BOARD_CPU_FAILDECT - Boolean (defined / not defined)
* BOARD_APBA_DIVIDER - See M_APBASEL_APBADIV_* definitions
* BOARD_APBA_FRQUENCY - In Hz
* BOARD_APBB_DIVIDER - See M_APBBSEL_APBBDIV_* definitions
* BOARD_APBB_FRQUENCY - In Hz
* BOARD_APBC_DIVIDER - See M_APBCSEL_APBCDIV_* definitions
* BOARD_APBC_FRQUENCY - In Hz
*/
#define BOARD_CPU_FAILDECT 1
#define BOARD_CPU_DIVIDER PM_CPUSEL_CPUDIV_1
#define BOARD_APBA_DIVIDER PM_APBASEL_APBADIV_1
#define BOARD_APBB_DIVIDER PM_APBBSEL_APBBDIV_1
#define BOARD_APBC_DIVIDER PM_APBCSEL_APBCDIV_1
/* Resulting frequencies */
#define BOARD_MCK_FREQUENCY (BOARD_GCLK_MAIN_FREQUENCY)
#define BOARD_CPU_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBA_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBB_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBC_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_PBD_FREQUENCY (BOARD_MCK_FREQUENCY)
/* FLASH wait states
*
* Vdd Range Wait states Maximum Operating Frequency
* ------------- -------------- ---------------------------
* 1.62V to 2.7V 0 14 MHz
* 1 28 MHz
* 2 42 MHz
* 3 48 MHz
* 2.7V to 3.63V 0 24 MHz
* 1 48 MHz
*/
#if 0 /* REVISIT -- should not be necessary */
# define BOARD_FLASH_WAITSTATES 1
#else
# define BOARD_FLASH_WAITSTATES 2
#endif
/* SERCOM definitions *******************************************************/
/* This is the source clock generator for the GCLK_SERCOM_SLOW clock that is
* common to all SERCOM modules.
*/
#define BOARD_SERCOM05_SLOW_GCLKGEN 0
/* SERCOM0 SPI is available on EXT1
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA5 SERCOM0 PAD1 SPI SS
* 16 PA6 SERCOM0 PAD2 SPI MOSI
* 17 PA4 SERCOM0 PAD0 SPI MISO
* 18 PA7 SERCOM0 PAD3 SPI SCK
*/
#define BOARD_SERCOM0_GCLKGEN 0
#define BOARD_SERCOM0_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM0_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMAP_PAD0 PORT_SERCOM0_PAD0_2 /* SPI_MISO */
#define BOARD_SERCOM0_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM0_PINMAP_PAD2 PORT_SERCOM0_PAD2_2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMAP_PAD3 PORT_SERCOM0_PAD3_2 /* SPI_SCK */
#define BOARD_SERCOM0_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM1 SPI is available on EXT2
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA17 SERCOM1 PAD1 SPI SS
* 16 PA18 SERCOM1 PAD2 SPI MOSI
* 17 PA16 SERCOM1 PAD0 SPI MISO
* 18 PA19 SERCOM1 PAD3 SPI SCK
*/
#define BOARD_SERCOM1_GCLKGEN 0
#define BOARD_SERCOM1_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM1_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM1_PINMAP_PAD0 PORT_SERCOM1_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM1_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM1_PINMAP_PAD2 PORT_SERCOM1_PAD2_1 /* SPI_MOSI */
#define BOARD_SERCOM1_PINMAP_PAD3 PORT_SERCOM1_PAD3_1 /* SPI_SCK */
#define BOARD_SERCOM1_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SAMD21 Xplained Pro contains an Embedded Debugger (EDBG) that can be
* used to program and debug the ATSAMD21J18A using Serial Wire Debug (SWD).
* The Embedded debugger also include a Virtual COM port interface over
* SERCOM3. Virtual COM port connections:
*
* PA22 SERCOM3 PAD[0] / USART TXD
* PA23 SERCOM3 PAD[1] / USART RXD
*/
#define BOARD_SERCOM3_GCLKGEN 0
#define BOARD_SERCOM3_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM3_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0_1)
#define BOARD_SERCOM3_PINMAP_PAD0 PORT_SERCOM3_PAD0_1 /* USART TX */
#define BOARD_SERCOM3_PINMAP_PAD1 PORT_SERCOM3_PAD1_1 /* USART RX */
#define BOARD_SERCOM3_PINMAP_PAD2 0
#define BOARD_SERCOM3_PINMAP_PAD3 0
#define BOARD_SERCOM3_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SERCOM4 USART is available on connectors EXT1, EXT2, and EXT3
*
* PIN EXT1 EXT2 EXT3 GPIO Function
* ---- ---- ---- ---- ------------------
* 13 PB09 PB10 PB10 SERCOM4 / USART RX
* 14 PB08 PB11 PB11 SERCOM4 / USART TX
* 19 GND GND GND N/A
* 20 VCC VCC VCC N/A
*
* If you have a TTL to RS-232 converter then this is the most convenient
* serial console to use (because you don't lose the console device each time
* you lose the USB connection). It is the default in all of the SAMD21
* configurations.
*/
#define BOARD_SERCOM4_GCLKGEN 0
#define BOARD_SERCOM4_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#if defined(CONFIG_SAMD21_XPLAINED_USART4_EXT1)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0)
# define BOARD_SERCOM4_PINMAP_PAD0 PORT_SERCOM4_PAD0_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD1 PORT_SERCOM4_PAD1_3 /* USART RX */
# define BOARD_SERCOM4_PINMAP_PAD2 0
# define BOARD_SERCOM4_PINMAP_PAD3 0
#elif defined(CONFIG_SAMD21_XPLAINED_USART4_EXT2)
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
# define BOARD_SERCOM4_PINMAP_PAD0 0
# define BOARD_SERCOM4_PINMAP_PAD1 0
# define BOARD_SERCOM4_PINMAP_PAD2 PORT_SERCOM4_PAD2_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD3 PORT_SERCOM4_PAD3_3 /* USART RX */
#else /* if defined(CONFIG_SAMD21_XPLAINED_USART4_EXT3) */
# define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD3 | USART_CTRLA_TXPAD2)
# define BOARD_SERCOM4_PINMAP_PAD0 0
# define BOARD_SERCOM4_PINMAP_PAD1 0
# define BOARD_SERCOM4_PINMAP_PAD2 PORT_SERCOM4_PAD2_3 /* USART TX */
# define BOARD_SERCOM4_PINMAP_PAD3 PORT_SERCOM4_PAD3_3 /* USART RX */
#endif
#define BOARD_SERCOM4_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM5 SPI is available on EXT3
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PB17 SERCOM5 PAD1 SPI SS
* 16 PB22 SERCOM5 PAD2 SPI MOSI
* 17 PB16 SERCOM5 PAD0 SPI MISO
* 18 PB23 SERCOM5 PAD3 SPI SCK
*/
#define BOARD_SERCOM5_GCLKGEN 0
#define BOARD_SERCOM5_SLOW_GCLKGEN BOARD_SERCOM05_SLOW_GCLKGEN
#define BOARD_SERCOM5_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM5_PINMAP_PAD0 PORT_SERCOM5_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM5_PINMAP_PAD1 0 /* microSD_SS */
#define BOARD_SERCOM5_PINMAP_PAD2 PORT_SERCOM5_PAD2_4 /* SPI_MOSI */
#define BOARD_SERCOM5_PINMAP_PAD3 PORT_SERCOM5_PAD3_4 /* SPI_SCK */
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK0_FREQUENCY
/* USB definitions **********************************************************/
/* This is the source clock generator for the GCLK_USB clock
*/
#define BOARD_USB_GCLKGEN 0
#define BOARD_USB_FREQUENCY BOARD_GCLK0_FREQUENCY
/* default USB Pad calibration (not used yet by USB driver) */
#define BOARD_USB_PADCAL_P 29
#define BOARD_USB_PADCAL_N 5
#define BOARD_USB_PADCAL_TRIM 3
/* LED definitions **********************************************************/
/* There are three LEDs on board the SAMD21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD21
* USB connector.
*
* This LED is controlled by PC07 and the LED can be activated by driving
* the PB30 to GND.
*/
/* LED index values for use with board_userled() */
#define BOARD_STATUS_LED 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_STATUS LED_BIT (1 << BOARD_STATUS_LED)
/* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as defined below. Thus if the LED is statically on, NuttX
* has successfully booted and is, apparently, running normally.
* If the LED is flashing at approximately 2Hz, then a fatal error
* has been detected and the system has halted.
*/
#define LED_STARTED 0 /* STATUS LED=OFF */
#define LED_HEAPALLOCATE 0 /* STATUS LED=OFF */
#define LED_IRQSENABLED 0 /* STATUS LED=OFF */
#define LED_STACKCREATED 1 /* STATUS LED=ON */
#define LED_INIRQ 2 /* STATUS LED=no change */
#define LED_SIGNAL 2 /* STATUS LED=no change */
#define LED_ASSERTION 2 /* STATUS LED=no change */
#define LED_PANIC 3 /* STATUS LED=flashing */
/* Button definitions *******************************************************/
/* Mechanical buttons:
*
* The SAMD21 Xplained Pro contains two mechanical buttons.
* One button is the RESET button connected to the SAMD21 reset line and the
* other is a generic user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA15 SW0
*/
/* The SAMD21 Xplained Pro supports one button: */
#define BUTTON_SW0 0
#define NUM_BUTTONS 1
#define BUTTON_SW0_BIT (1 << BUTTON_SW0)
#endif /* __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_INCLUDE_BOARD_H */

View File

@ -0,0 +1,63 @@
############################################################################
# boards/arm/samd2l2/samd21-xplained/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv6-m/Toolchain.defs
LDSCRIPT = flash.ld
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif

View File

@ -0,0 +1,110 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/scripts/flash.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAMD21J18A has 256KB of FLASH beginning at address 0x0000:0000 and
* 32KB of SRAM beginning at address 0x2000:0000
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
ENTRY(_stext)
SECTIONS
{
.text : {
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section : {
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > flash
.ARM.extab : {
*(.ARM.extab*)
} >flash
.ARM.exidx : {
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >flash
.data : {
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
_eronly = LOADADDR(.data);
.ramfunc ALIGN(4): {
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > flash
_framfuncs = LOADADDR(.ramfunc);
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,53 @@
############################################################################
# boards/arm/samd2l2/samd21-xplained/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = sam_boot.c
ifeq ($(CONFIG_SAMD2L2_SERCOM0),y)
CSRCS += sam_spi.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
CSRCS += sam_userleds.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sam_buttons.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sam_appinit.c
endif
ifeq ($(CONFIG_SAMD21_XPLAINED_IOMODULE),y)
CSRCS += sam_mmcsd.c
endif
ifeq ($(CONFIG_SAMD21_XPLAINED_OLED1MODULE),y)
ifeq ($(CONFIG_LCD_UG2832HSWEG04),y)
CSRCS += sam_ug2832hsweg04.c
endif
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,123 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "samd21-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Some configuration checks */
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1
# ifndef SAMD2L2_HAVE_SPI0
# error I/O1 module on EXT1 requires SERCOM SPI0
# undef CONFIG_SAMD21_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 0
#endif
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2
# ifndef SAMD2L2_HAVE_SPI1
# error I/O1 module on EXT2 requires SERCOM SPI1
# undef CONFIG_SAMD21_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 1
#endif
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE
/* Support for the SD card slot on the I/O1 module */
/* Verify NSH PORT and SLOT settings */
# define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAMD2L2_MMCSDSLOTNO
# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO)
# endif
# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SPI_PORTNO
# error CONFIG_NSH_MMCSDSPIPORTNO must have the same value as SPI_PORTNO
# endif
/* Default MMC/SD minor number */
# ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
# endif
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
#if defined(SAMD2L2_HAVE_SPI0) && defined(CONFIG_SAMD21_XPLAINED_IOMODULE)
/* Initialize the SPI-based MMC/SD slot */
int ret = sam_sdinitialize(SPI_PORTNO, CONFIG_NSH_MMCSDMINOR);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize MMC/SD slot: %d\n",
ret);
return ret;
}
#endif
return OK;
}

View File

@ -0,0 +1,149 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_autoleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAMD21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD21
* USB connector.
*
* This LED is controlled by PB30 and the LED can be activated by driving
* PB30 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt** N/C
* LED_SIGNAL In a signal handler*** N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd21-xplained.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
bool ledstate = true;
switch (led)
{
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
break; /* Leave ledstate == true to turn OFF */
default:
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
ledstate = false; /* Set ledstate == false to turn ON */
break;
}
sam_portwrite(PORT_STATUS_LED, ledstate);
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
/* These should not happen and are ignored */
default:
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
/* These result in no-change */
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
/* Turn STATUS LED off set driving the output high */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
sam_portwrite(PORT_STATUS_LED, true);
break;
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,77 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_boot.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "samd21-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_boardinitialize
*
* Description:
* All SAM3U architectures must provide the following entry point.
* This entry point is called early in the initialization -- after all
* memory has been configured and mapped but before any devices have been
* initialized.
*
****************************************************************************/
void sam_boardinitialize(void)
{
/* Configure SPI chip selects if
* 1) SPI is not disabled, and
* 2) the weak function
* sam_spidev_initialize() has been brought into the link.
*/
#ifdef SAMD2L2_HAVE_SPI
if (sam_spidev_initialize)
{
sam_spidev_initialize();
}
#endif
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
}

View File

@ -0,0 +1,127 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_buttons.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/irq.h>
#include <nuttx/irq.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd21-xplained.h"
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_button_initialize
*
* Description:
* board_button_initialize() must be called to initialize button resources.
* After that, board_buttons() may be called to collect the current state
* of all buttons or board_button_irq() may be called to register button
* interrupt handlers.
*
****************************************************************************/
uint32_t board_button_initialize(void)
{
sam_configport(PORT_SW0);
return NUM_BUTTONS;
}
/****************************************************************************
* Name: board_buttons
*
* Description:
* After board_button_initialize() has been called,
* board_buttons() may be called to collect the state of all buttons.
* board_buttons() returns an 32-bit bit set with each bit
* associated with a button.
* See the BUTTON* definitions above for the meaning of each bit
* in the returned value.
*
****************************************************************************/
uint32_t board_buttons(void)
{
return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT;
}
/****************************************************************************
* Name: board_button_irq
*
* Description:
* This function may be called to register an interrupt handler that will
* be called when a button is depressed or released. The ID value is one
* of the BUTTON* definitions provided above.
*
* Configuration Notes:
* Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the
* overall PORT IRQ feature and CONFIG_AVR32_PORTIRQSETA and/or
* CONFIG_AVR32_PORTIRQSETB must be enabled to select PORTs to support
* interrupts on. For button support, bits 2 and 3 must be set in
* CONFIG_AVR32_PORTIRQSETB (PB2 and PB3).
*
****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{
int ret = -EINVAL;
if (id == BUTTON_SW0)
{
irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the
* following operations are atomic.
*/
flags = enter_critical_section();
/* Configure the interrupt */
sam_portirq(IRQ_SW0);
irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0);
leave_critical_section(flags);
ret = OK;
}
return ret;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */

View File

@ -0,0 +1,114 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_mmcsd.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h>
#include "sam_config.h"
#include "sam_spi.h"
#include "samd21-xplained.h"
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y)
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error SERCOM0 SPI support is required
#endif
#ifndef CONFIG_MMCSD
# error MMC/SD support is required (CONFIG_MMCSD)
#endif
#define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card. Requires
* - CONFIG_SAMD21_XPLAINED_IOMODULE=y,
* - CONFIG_DISABLE_MOUNTPOINT=n,
* - CONFIG_MMCSD=y, and
* - SAMD2L2_HAVE_SPI0=y
* (CONFIG_SAMD2L2_SERCOM0 && CONFIG_SAMD2L2_SERCOM0_ISSPI)
*
****************************************************************************/
int sam_sdinitialize(int port, int minor)
{
FAR struct spi_dev_s *spi;
int ret;
/* Get the SPI driver instance for the SD chip select */
finfo("Initializing SERCOM SPI%d\n", port);
spi = sam_spibus_initialize(port);
if (!spi)
{
ferr("ERROR: Failed to initialize SPI%d\n", port);
return -ENODEV;
}
finfo("Successfully initialized SPI%d\n", port);
/* Bind the SPI device for the chip select to the slot */
finfo("Binding SPI%d to MMC/SD slot %d\n", port, SAMD2L2_MMCSDSLOTNO);
ret = mmcsd_spislotinitialize(minor, SAMD2L2_MMCSDSLOTNO, spi);
if (ret < 0)
{
ferr("ERROR: Failed to bind SPI%d to MMC/SD slot %d: %d\n",
port, SAMD2L2_MMCSDSLOTNO, ret);
return ret;
}
finfo("Successfully bound SPI%d to MMC/SD slot %d\n",
port, SAMD2L2_MMCSDSLOTNO);
return OK;
}
#endif /* CONFIG_SAMD21_XPLAINED_IOMODULE */

View File

@ -0,0 +1,406 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_spi.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include "sam_config.h"
#include "sam_port.h"
#include "sam_spi.h"
#include "samd21-xplained.h"
#ifdef SAMD2L2_HAVE_SPI
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAMD21 Xplained
* Pro board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void)
{
/* The I/O module containing the SD connector may or may not be installed.
* And, if it is installed, it may be in connector EXT1 or EXT2.
*/
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE
/* TODO: enable interrupt on card detect */
sam_configport(PORT_SD_CD); /* Card detect input */
sam_configport(PORT_SD_CS); /* Chip select output */
#endif
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE
sam_configport(PORT_OLED_DATA); /* Command/data */
sam_configport(PORT_OLED_CS); /* Card detect input */
#endif
}
/****************************************************************************
* Name: sam_spi[n]select, sam_spi[n]status, and sam_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic. They
* include:
*
* o sam_spi[n]select is a functions to manage the board-specific chip
* selects
* o sam_spi[n]status and sam_spi[n]cmddata: Implementations of the status
* and cmddata methods of the SPI interface defined by struct spi_ops_
* (see include/nuttx/spi/spi.h). All other methods including
* sam_spibus_initialize()) are provided by common SAMD/L logic.
*
* Where [n] is the SERCOM number for the SPI module.
*
* To use this common SPI logic on your board:
*
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide sam_spi[n]select() and sam_spi[n]status() functions in your
* board-specific logic. These functions will perform chip selection
* and status operations using GPIOs in the way your board is
* configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* sam_spi[n]cmddata() functions in your board-specific logic. This
* function will perform cmd/data selection operations using GPIOs in
* the way your board is configured.
* 3. Add a call to sam_spibus_initialize() in your low level application
* initialization logic
* 4. The handle returned by sam_spibus_initialize() may then be used to
* bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
/****************************************************************************
* Name: sam_spi[n]select
*
* Description:
* PIO chip select pins may be programmed by the board specific logic in
* one of two different ways. First, the pins may be programmed as SPI
* peripherals. In that case, the pins are completely controlled by the
* SPI driver. This method still needs to be provided, but it may be only
* a stub.
*
* An alternative way to program the PIO chip select pins is as a normal
* GPIO output. In that case, the automatic control of the CS pins is
* bypassed and this function must provide control of the chip select.
* NOTE: In this case, the GPIO output pin does *not* have to be the
* same as the NPCS pin normal associated with the chip select number.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
* selected - TRUE:Select the device, FALSE:De-select the device
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
void sam_spi0select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT1
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
void sam_spi1select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
void sam_spi2select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
void sam_spi3select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
void sam_spi4select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
void sam_spi5select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
/****************************************************************************
* Name: sam_spi[n]status
*
* Description:
* Return status information associated with the SPI device.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
uint8_t sam_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
uint8_t sam_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
uint8_t sam_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
uint8_t sam_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
uint8_t sam_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
return ret;
}
#endif
/****************************************************************************
* Name: sam_spi[n]cmddata
*
* Description:
* Some SPI devices require an additional control to determine if the SPI
* data being sent is a command or is data. If CONFIG_SPI_CMDDATA then
* this function will be called to different be command and data transfers.
*
* This is often needed, for example, by LCD drivers. Some LCD hardware
* may be configured to use 9-bit data transfers with the 9th bit
* indicating command or data. That same hardware may be configurable,
* instead, to use 8-bit data but to require an additional, board-
* specific GPIO control to distinguish command and data. This function
* would be needed in that latter case.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Zero on success; a negated errno on failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA
#ifdef SAMD2L2_HAVE_SPI0
int sam_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT1
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
int sam_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
int sam_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
int sam_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
int sam_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
int sam_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#endif /* CONFIG_SPI_CMDDATA */
#endif /* SAMD2L2_HAVE_SPI */

View File

@ -0,0 +1,191 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_ug2832hsweg04.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* OLED1 Connector:
*
* OLED1 CONNECTOR
* ----------------- ---------------------- ----------------------
* OLED1 EXT1 EXT2
* ----------------- ---------------------- ----------------------
* 1 ID 1 1
* ----------------- ---------------------- ----------------------
* 2 GND 2 GND 2 GND
* ----------------- ---------------------- ----------------------
* 3 BUTTON2 3 PB00 AIN[8] 3 PA10 AIN[18]
* ----------------- ---------------------- ----------------------
* 4 BUTTON3 4 PB01 AIN[9] 4 PA11 AIN[19]
* ----------------- ---------------------- ----------------------
* 5 DATA_CMD_SEL 5 PB06 PORT 5 PA20 PORT
* ----------------- ---------------------- ----------------------
* 6 LED3 6 PB07 PORT 6 PA21 PORT
* ----------------- ---------------------- ----------------------
* 7 LED1 7 PB02 TC6/WO[0] 7 PB12 TC4/WO[0]
* ----------------- ---------------------- ----------------------
* 8 LED2 8 PB03 TC6/WO[1] 8 PB13 TC4/WO[1]
* ----------------- ---------------------- ----------------------
* 9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
* ----------------- ---------------------- ----------------------
* 10 DISPLAY_RESET 10 PB05 PORT 10 PB15 PORT
* ----------------- ---------------------- ----------------------
* 11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0]
* I²C SDA I²C SDA
* ----------------- ---------------------- ----------------------
* 12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1]
* I²C SCL I²C SCL
* ----------------- ---------------------- ----------------------
* 13 N/C 13 PB09 SERCOM4 PAD[1] 13 PB11 SERCOM4 PAD[1]
* USART RX USART RX
* ----------------- ---------------------- ----------------------
* 14 N/C 14 PB08 SERCOM4 PAD[0] 14 PB10 SERCOM4 PAD[0]
* USART TX USART TX
* ----------------- ---------------------- ----------------------
* 15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
* SPI SS SPI SS
* ----------------- ---------------------- ----------------------
* 16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
* SPI MOSI SPI MOSI
* ----------------- ---------------------- ----------------------
* 17 N/C 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
* SPI MISO SPI MISO
* ----------------- ---------------------- ----------------------
* 18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
* SPI SCK SPI SCK
* ----------------- ---------------------- ----------------------
* 19 GND 19 GND GND
* ----------------- ---------------------- ----------------------
* 20 VCC 20 VCC VCC
* ----------------- ---------------------- ----------------------
*
* OLED1 signals
*
* DATA_CMD_SEL - Data/command select. Used to choose whether the
* communication is data to the display memory or a command to the LCD
* controller. High = data, low = command
* DISPLAY_RESET - Reset signal to the OLED display, active low. Used during
* initialization of the display.
* DISPLAY_SS - SPI slave select signal, must be held low during SPI
* communication.
* SPI_MOSI - SPI master out, slave in signal. Used to write data to the
* display
* SPI_SCK SPI - clock signal, generated by the master.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
#include "sam_port.h"
#include "sam_spi.h"
#include "samd21-xplained.h"
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* The pin configurations here require that SPI1 is selected */
#ifndef CONFIG_LCD_SSD1306
# error "The OLED driver requires CONFIG_LCD_SSD1306 in the configuration"
#endif
#ifndef CONFIG_LCD_UG2832HSWEG04
# error "The OLED driver requires CONFIG_LCD_UG2832HSWEG04 in the configuration"
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error "The OLED driver requires SAMD2L2_HAVE_SPI0 in the configuration"
#endif
#ifndef CONFIG_SPI_CMDDATA
# error "The OLED driver requires CONFIG_SPI_CMDDATA in the configuration"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_graphics_setup
*
* Description:
* Called by NX initialization logic to configure the OLED.
*
****************************************************************************/
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
{
FAR struct spi_dev_s *spi;
FAR struct lcd_dev_s *dev;
/* Configure the OLED PORTs. This initial configuration is RESET low,
* putting the OLED into reset state.
*/
sam_configport(PORT_OLED_RST);
/* Wait a bit then release the OLED from the reset state */
up_mdelay(20);
sam_portwrite(PORT_OLED_RST, true);
/* Get the SPI1 port interface */
spi = sam_spibus_initialize(OLED_CSNO);
if (!spi)
{
lcderr("ERROR: Failed to initialize SPI port 1\n");
}
else
{
/* Bind the SPI port to the OLED */
dev = ssd1306_initialize(spi, NULL, devno);
if (!dev)
{
lcderr("ERROR: Failed to bind SPI port 1 to OLED %d\n", devno);
}
else
{
lcdinfo("Bound SPI port 1 to OLED %d\n", devno);
/* And turn the OLED on */
dev->setpower(dev, CONFIG_LCD_MAXPOWER);
return dev;
}
}
return NULL;
}
#endif /* CONFIG_SAMD21_XPLAINED_OLED1MODULE */

View File

@ -0,0 +1,107 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/sam_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAMD21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAMD21
* USB connector.
*
* This LED is controlled by PB30 and the LED can be activated by driving
* PB30 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED. Otherwise, the LED can be controlled from user
* applications using the logic in this file.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "samd21-xplained.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the
* board_userled_initialize() is available to initialize the LED from user
* application logic.
*
****************************************************************************/
uint32_t board_userled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
return BOARD_NLEDS;
}
/****************************************************************************
* Name: board_userled
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is
* available to control the LED from user application logic.
*
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_STATUS_LED)
{
sam_portwrite(PORT_STATUS_LED, !ledon);
}
}
/****************************************************************************
* Name: board_userled_all
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs.
* If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() is
* available to control the LED from user application logic. NOTE: since
* there is only a single LED on-board, this is function isn't very useful.
*
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
board_userled(BOARD_STATUS_LED, (ledset & BOARD_STATUS_LED_BIT) != 0);
}
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,255 @@
/****************************************************************************
* boards/arm/samd2l2/samd21-xplained/src/samd21-xplained.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_SRC_SAMD21_XPLAINED_H
#define __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_SRC_SAMD21_XPLAINED_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <arch/irq.h>
#include <nuttx/irq.h>
#include "sam_config.h"
#include "sam_pinmap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* LEDs:
* There are three LEDs on board the SAMD21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATIS near the SAMD21
* USB connector.
*
* This LED is controlled by PB30 and the LED can be activated by driving
* PB30 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
#define PORT_STATUS_LED (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTB | PORT_PIN30)
/* Mechanical buttons:
*
* The SAMD21 Xplained Pro contains two mechanical buttons. One button is the
* RESET button connected to the SAMD21 reset line and the other is a generic
* user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA15 SW0
*/
#define PORT_SW0 (PORT_INTERRUPT | PORT_PULL_UP | PORTA | PORT_PIN15)
#define IRQ_SW0 SAM_IRQ_PA15
/* I/O1
*
* Support for the microSD card slot on the I/O1 module. The I/O1 requires
* SPI support and two PORTs. These the PORTs will vary if the I/O1
* is installed on the EXT1 or EXT2 connector:
*
* --- ------------------ ---------------------- --------------------------
* PIN EXT1 EXT2 Description
* --- ------------------ ---------------------- --------------------------
* 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1] Active low chip select
* SPI SS SPI SS OUTPUT, pulled high on
* board.
* --- ------------------ ---------------------- --------------------------
* 10 PB05 PORT 10 PB15 PORT Active low card detect
* INPUT, must use internal
* pull-up.
* --- ------------------ ---------------------- --------------------------
*/
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the I/O1 module
# endif
# if defined(CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1)
# if defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT1)
# error I/O1 and OLED1 modules cannot both reside in EXT1
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN5)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2)
# if defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2)
# error I/O1 and OLED1 modules cannot both reside in EXT2
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN15)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the I/O1 module installed in?
# endif
#endif
/* OLED1
*
* Support for the microSD card slot on the I/O1 module.
* The I/O1 requires SPI support and three output PORTs.
* These the PORTs will vary if the OLED1 is installed on the EXT1
* or EXT2 connector:
*
*
* PIN EXT1 EXT2 Description
* --- ------------------- -------------------- ---------------------------
* 5 PB06 PORT PA20 PORT DATA_CMD_SEL
* 10 PB05 PORT PB15 PORT DISPLAY_RESET. Active low.
* 15 PA05 SERCOM0 PAD[1] PA17 SERCOM1 PAD[1] DISPLAY_SS. Active low.
* SPI SS SPI SS
*/
#ifdef CONFIG_SAMD21_XPLAINED_OLED1MODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the OLED1 module
# endif
# ifndef CONFIG_SPI_CMDDATA
# error CONFIG_SPI_CMDDATA is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_SSD1306
# error CONFIG_LCD_SSD1306 is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_UG2832HSWEG04
# error CONFIG_LCD_UG2832HSWEG04 is required to use the OLED1 module
# endif
# if defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT1)
# if defined(CONFIG_SAMD21_XPLAINED_IOMODULE) && \
defined(CONFIG_SAMD21_XPLAINED_IOMODULE_EXT1)
# error OLED1 and I/O1 modules cannot both reside in EXT1
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN6)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN5)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAMD21_XPLAINED_OLED1MODULE_EXT2)
# if defined(CONFIG_SAMD21_XPLAINED_IOMODULE) && \
defined(CONFIG_SAMD21_XPLAINED_IOMODULE_EXT2)
# error OLED1 and I/O1 modules cannot both reside in EXT2
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTA | PORT_PIN20)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN15)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the OLED1 module installed in?
# endif
#endif
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTB | PORT_PIN11) /* REVISIT */
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAM3U-EK board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void);
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card.
* Requires CONFIG_SAMD21_XPLAINED_IOMODULE=y,
* CONFIG_DISABLE_MOUNTPOINT=n,
* CONFIG_MMCSD=y, and the appropriate SERCOM SPI port enabled.
*
****************************************************************************/
#ifdef CONFIG_SAMD21_XPLAINED_IOMODULE
int sam_sdinitialize(int port, int minor);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_SAMD2L2_SAMD21_XPLAINED_SRC_SAMD21_XPLAINED_H */

View File

@ -0,0 +1,115 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_SAML21_XPLAINED
menu "CPU Clock Configuration"
choice
prompt "OSC16M Frequency"
default SAML21_XPLAINED_OSC16M_4MHZ
config SAML21_XPLAINED_OSC16M_4MHZ
bool "4 MHz"
config SAML21_XPLAINED_OSC16M_8MHZ
bool "8 MHz"
config SAML21_XPLAINED_OSC16M_12MHZ
bool "12 MHz"
config SAML21_XPLAINED_OSC16M_16MHZ
bool "16 MHz"
endchoice # OSC16M Frequency
config SAML21_XPLAINED_XOSC32K
bool "Enable XOSC32K"
default n
config SAML21_XPLAINED_DFLL
bool "Use DFLL"
default n
choice
prompt "DFLL Clock Source"
default SAML21_XPLAINED_DFLL_OSC16MSRC
depends on SAML21_XPLAINED_DFLL
config SAML21_XPLAINED_DFLL_OSC16MSRC
bool "OSC16M"
config SAML21_XPLAINED_DFLL_XOSC32KSRC
bool "XOSCK32K"
select SAML21_XPLAINED_XOSC32K
endchoice # DFLL Clock Source
choice
prompt "DFLL Operating Mode"
default SAML21_XPLAINED_DFLL_OPENLOOP
depends on SAML21_XPLAINED_DFLL
config SAML21_XPLAINED_DFLL_OPENLOOP
bool "DFLL Open Loop Mode"
config SAML21_XPLAINED_DFLL_CLOSEDLOOP
bool "DFLL Closed Loop Mode"
config SAML21_XPLAINED_DFLL_RECOVERY
bool "DFLL USB Recovery Mode"
depends on EXPERIMENTAL
endchoice # DLL Operating Mode
endmenu # CPU Clock Configuration
menu "SAML21 Xplained Pro Modules"
config SAML21_XPLAINED_IOMODULE
bool "I/O1 Module"
default n
---help---
The I/O 1 module is attached. This module provides an MMC/SD card
slot.
if SAML21_XPLAINED_IOMODULE
choice
prompt "I/O1 Module Location"
default SAML21_XPLAINED_IOMODULE_EXT1
config SAML21_XPLAINED_IOMODULE_EXT1
bool "EXT1"
config SAML21_XPLAINED_IOMODULE_EXT2
bool "EXT2"
endchoice
endif
config SAML21_XPLAINED_OLED1MODULE
bool "OLED1 Module"
default n
---help---
The OLED 1 module is attached. This module provides an OLED plus 3
additional switches and 3 additional LEDs.
if SAML21_XPLAINED_OLED1MODULE
choice
prompt "OLED1 Module Location"
default SAML21_XPLAINED_OLED1MODULE_EXT1
config SAML21_XPLAINED_OLED1MODULE_EXT1
bool "EXT1"
config SAML21_XPLAINED_OLED1MODULE_EXT2
bool "EXT2"
endchoice
endif
endmenu
endif # ARCH_BOARD_SAML21_XPLAINED

View File

@ -0,0 +1,895 @@
README
======
This README discusses issues unique to NuttX configurations for the
Atmel SAML21 Xplained Pro development board. This board features the
ATSAML21J18A MCU.
Contents
========
- STATUS/ISSUES
- Modules
- Development Environment
- GNU Toolchain Options
- IDEs
- NuttX EABI "buildroot" Toolchain
- LEDs and Buttons
- Serial Consoles
- Atmel Studio 6.1
- JTAG
- SAML21 Xplained Pro-specific Configuration Options
- Configurations
STATUS/ISSUES
=============
- Since this port is a leverage of the SAMD20 Xplained port, some of the
STATUS/ISSUES in the SAMD20 Xplained README.txt may apply here as well.
- 2015-5-26: The basic port is running at 48MHz (using 32.768 XTAL input
and the digital frequency locked loop). The basic NuttShell (NSH)
configuration is working well with the serial console provided by
SERCOM4 as 115200 8N1.
- 2015-6-14: Added a DMAC driver. There is no way to verify it at present
and, hence, depends upon CONFIG_EXPERIMENTAL=y
Modules
=======
There are several I/O modules available that will work with the SAML21
Xplained Pro Starter Kit:
1) I/O1 - An MMC/SD card slot, PWM LED control, ADC light sensor, USART
loopback, TWI AT30TSE758 Temperature sensor.
2) OLED1 - An OLED plus 3 additional switches and 3 additional LEDs
3) PROTO1 - A prototyping board with logic on board (other than power-
related logic).
4) And others. See http://www.atmel.com/products/microcontrollers/avr/xplained.aspx
Some of these are discussed further below.
I/O1
----
The primary function of this module is to provide SD card support, but
the full list of modules features include:
- microSD card connector (SPI interface)
- PWM (LED control)
- ADC (light sensor)
- USART loopback
- TWI AT30TSE758 Temperature sensor with EEPROM
SPI is available on two of the SAML21 Xplained connectors, EXT1 and EXT2.
They mate with the I/O1 connector as indicated in this table.
I/O1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
I/O1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 LIGHT_SENSOR 3 PB05 AIN[13] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 LP_OUT 4 PA03 AIN[1] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 GPIO1 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 GPIO2 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED 7 PA12 TCC2/WO[0] 7 PB12 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LP_IN 8 PA13 TCC2/WO[1] 8 PB13 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 TEMP_ALERT 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 microSD_DETECT 10 PA02 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 TWI SDA 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 TWI SCL 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 USART RX 13 PB09 SERCOM4 PAD[1] 13 PA19 SERCOM1 PAD[3] The SERCOM4 module is shared between
USART RX USART RX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
14 USART TX 14 PB08 SERCOM4 PAD[0] 14 PA18 SERCOM1 PAD[2] The SERCOM4 module is shared between
USART TX USART TX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
15 microSD_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 GPIO
SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PB22 SERCOM5 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 SPI_MISO 17 PA04 SERCOM0 PAD[0] 17 PB16 SERCOM5 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PB23 SERCOM5 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
The mapping between the I/O1 pins and the SD connector are shown in the
following table.
SD Card Connection
------------------
I/O1 SD PIN Description
---- ---- --- -------------------------------------------------
D2 1 Data line 2 (not used)
15 D3 2 Data line 3. Active low chip select, pulled high
16 CMD 3 Command line, connected to SPI_MOSI.
20 VDD 4
18 CLK 5 Clock line, connected to SPI_SCK.
2/19 GND 6
17 D0 7 Data line 0, connected to SPI_MISO.
D1 8 Data line 1 (not used)
10 SW_A 9 Card detect
2/19 SW_B 10 GND
Card Detect
-----------
When a microSD card is put into the connector SW_A and SW_B are short-
circuited. SW_A is connected to the microSD_DETECT signal. To use this
as a card indicator remember to enable internal pullup in the target
device.
GPIOs
-----
So all that is required to connect the SD is configure the SPI
--- ------------------ ---------------------- -------------------------------------
PIN EXT1 EXT2 Description
--- ------------------ ---------------------- -------------------------------------
15 PA05 SERCOM0 PAD[1] 15 PA17 GPIO Active low chip select OUTPUT, pulled
SPI SS high on board.
--- ------------------ ---------------------- -------------------------------------
10 PA02 GPIO 10 PB15 GPIO Active low card detect INPUT, must
use internal pull-up.
--- ------------------ ---------------------- -------------------------------------
Configuration Options:
----------------------
CONFIG_SAML21_XPLAINED_IOMODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAML21_XPLAINED_IOMODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAML21_XPLAINED_IOMODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
NOTE: As of this writing, only the SD card slot is supported in the I/O1
module.
OLED1
-----
This module provides an OLED plus 3 additional switches and 3 additional
LEDs.
OLED1 CONNECTOR
----------------- ---------------------- ---------------------- ------------------------------------
OLED1 EXT1 EXT2 Other use of either pin
----------------- ---------------------- ---------------------- ------------------------------------
1 ID 1 1 Communication line to ID chip on
extension board.
----------------- ---------------------- ---------------------- ------------------------------------
2 GND 2 GND 2 GND
----------------- ---------------------- ---------------------- ------------------------------------
3 BUTTON2 3 PB05 AIN[13] 3 PA10 AIN[18]
----------------- ---------------------- ---------------------- ------------------------------------
4 BUTTON3 4 PA03 AIN[1] 4 PA11 AIN[19]
----------------- ---------------------- ---------------------- ------------------------------------
5 DATA_CMD_SEL 5 PB06 GPIO 5 PA20 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
6 LED3 6 PB07 GPIO 6 PA21 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
7 LED1 7 PA12 TCC2/WO[0] 7 PB12 TC4/WO[0]
----------------- ---------------------- ---------------------- ------------------------------------
8 LED2 8 PA13 TCC2/WO[1] 8 PB13 TC4/WO[1]
----------------- ---------------------- ---------------------- ------------------------------------
9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
----------------- ---------------------- ---------------------- ------------------------------------
10 DISPLAY_RESET 10 PA02 GPIO 10 PB15 GPIO
----------------- ---------------------- ---------------------- ------------------------------------
11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0] EXT1, EXT2, EXT3 and EDBG
I²C SDA I²C SDA
----------------- ---------------------- ---------------------- ------------------------------------
12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1] EXT2, EXT3 and EDBG
I²C SCL I²C SCL
----------------- ---------------------- ---------------------- ------------------------------------
13 N/C 13 PB09 SERCOM4 PAD[1] 13 PA19 SERCOM1 PAD[3] The SERCOM4 module is shared between
USART RX USART RX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
14 N/C 14 PB08 SERCOM4 PAD[0] 14 PA18 SERCOM1 PAD[2] The SERCOM4 module is shared between
USART TX USART TX EXT1, 2 and 3 USART's, but uses
different pins
----------------- ---------------------- ---------------------- ------------------------------------
15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 GPIO
SPI SS
----------------- ---------------------- ---------------------- ------------------------------------
16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PB22 SERCOM5 PAD[2]
SPI MOSI SPI MOSI
----------------- ---------------------- ---------------------- ------------------------------------
17 N/C 17 PA04 SERCOM0 PAD[0] 17 PB16 SERCOM5 PAD[0]
SPI MISO SPI MISO
----------------- ---------------------- ---------------------- ------------------------------------
18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PB23 SERCOM5 PAD[3]
SPI SCK SPI SCK
----------------- ---------------------- ---------------------- ------------------------------------
19 GND 19 GND GND
----------------- ---------------------- ---------------------- ------------------------------------
20 VCC 20 VCC VCC
----------------- ---------------------- ---------------------- ------------------------------------
Configuration Options:
----------------------
CONFIG_SAML21_XPLAINED_OLED1MODULE=y : Informs the system that the
I/O1 module is installed
CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT1=y : The module is installed in EXT1
CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2=y : The mdoule is installed in EXT2
See the set-up in the discussion of the nsh configuration below for other
required configuration options.
PROTO1
------
A prototyping board with logic on board (other than power-related logic).
There is no built-in support for the PROTO1 module.
Development Environment
=======================
Either Linux or Cygwin on Windows can be used for the development environment.
The source has been built only using the GNU toolchain (see below). Other
toolchains will likely cause problems. Testing was performed using the Cygwin
environment.
GNU Toolchain Options
=====================
The NuttX make system can be configured to support the various different
toolchain options. All testing has been conducted using the NuttX buildroot
toolchain. To use alternative toolchain, you simply need to add change of
the following configuration options to your .config (or defconfig) file:
CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y : NuttX buildroot under Linux or Cygwin (default)
CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y : Generic GCC ARM EABI toolchain for Linux
CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : Generic GCC ARM EABI toolchain for Windows
NOTE about Windows native toolchains
------------------------------------
There are basically three kinds of GCC toolchains that can be used:
1. A Linux native toolchain in a Linux environment,
2. The buildroot Cygwin tool chain built in the Cygwin environment,
3. A Windows native toolchain.
There are several limitations to using a Windows based toolchain (#3) in a
Cygwin environment. The three biggest are:
1. The Windows toolchain cannot follow Cygwin paths. Path conversions are
performed automatically in the Cygwin makefiles using the 'cygpath'
utility but you might easily find some new path problems. If so, check
out 'cygpath -w'
2. Windows toolchains cannot follow Cygwin symbolic links. Many symbolic
links are used in NuttX (e.g., include/arch). The make system works
around these problems for the Windows tools by copying directories
instead of linking them. But this can also cause some confusion for
you: For example, you may edit a file in a "linked" directory and find
that your changes had no effect. That is because you are building the
copy of the file in the "fake" symbolic directory. If you use a
Windows toolchain, you should get in the habit of making like this:
make clean_context all
An alias in your .bashrc file might make that less painful.
IDEs
====
NuttX is built using command-line make. It can be used with an IDE, but some
effort will be required to create the project.
Makefile Build
--------------
Under Eclipse, it is pretty easy to set up an "empty makefile project" and
simply use the NuttX makefile to build the system. That is almost for free
under Linux. Under Windows, you will need to set up the "Cygwin GCC" empty
makefile project in order to work with Windows (Google for "Eclipse Cygwin" -
there is a lot of help on the internet).
Native Build
------------
Here are a few tips before you start that effort:
1) Select the toolchain that you will be using in your .config file
2) Start the NuttX build at least one time from the Cygwin command line
before trying to create your project. This is necessary to create
certain auto-generated files and directories that will be needed.
3) Set up include paths: You will need include/, arch/arm/src/sam34,
arch/arm/src/common, arch/arm/src/armv7-m, and sched/.
4) All assembly files need to have the definition option -D __ASSEMBLY__
on the command line.
Startup files will probably cause you some headaches. The NuttX startup file
is arch/arm/src/sam34/sam_vectors.S. You may need to build NuttX
one time from the Cygwin command line in order to obtain the pre-built
startup object needed by an IDE.
NuttX EABI "buildroot" Toolchain
================================
A GNU GCC-based toolchain is assumed. The PATH environment variable should
be modified to point to the correct path to the Cortex-M0 GCC toolchain (if
different from the default in your PATH variable).
If you have no Cortex-M0 toolchain, one can be downloaded from the NuttX
Bitbucket download site (https://bitbucket.org/nuttx/buildroot/downloads/).
This GNU toolchain builds and executes in the Linux or Cygwin environment.
1. You must have already configured NuttX in <some-dir>/nuttx.
tools/configure.sh saml21-xplained:<sub-dir>
2. Download the latest buildroot package into <some-dir>
3. unpack the buildroot tarball. The resulting directory may
have versioning information on it like buildroot-x.y.z. If so,
rename <some-dir>/buildroot-x.y.z to <some-dir>/buildroot.
4. cd <some-dir>/buildroot
5. cp boards/cortexm0-eabi-defconfig-4.6.3 .config
6. make oldconfig
7. make
8. Make sure that the PATH variable includes the path to the newly built
binaries.
See the file boards/README.txt in the buildroot source tree. That has more
details PLUS some special instructions that you will need to follow if you are
building a Cortex-M0 toolchain for Cygwin under Windows.
LEDs and Buttons
================
LED
---
There is one yellow LED available on the SAML21 Xplained Pro board that
can be turned on and off. The LED can be activated by driving the connected
PB10 I/O line to GND.
When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
control the LED as follows:
SYMBOL Meaning LED0
------------------- ----------------------- ------
LED_STARTED NuttX has been started OFF
LED_HEAPALLOCATE Heap has been allocated OFF
LED_IRQSENABLED Interrupts enabled OFF
LED_STACKCREATED Idle stack created ON
LED_INIRQ In an interrupt N/C
LED_SIGNAL In a signal handler N/C
LED_ASSERTION An assertion failed N/C
LED_PANIC The system has crashed FLASH
Thus is LED is statically on, NuttX has successfully booted and is,
apparently, running normally. If LED is flashing at approximately
2Hz, then a fatal error has been detected and the system has halted.
Button
------
SAM L21 Xplained Pro contains one mechanical button on PA02 that can be
controlled by software. When a button is pressed it will drive the I/O
line to GND. Note: There is no pull-up resistor connected to the generic
user button. Remember to enable the internal pull-up in the SAM L21 to
use the button.
QTouch Button
-------------
To be provided
Serial Consoles
===============
SERCOM0
-------
SERCOM0 is dedicated for use with SPI at the EXT1 connector
SERCOM1
-------
SERCOM1 is available as a USART on EXT2 and EXT3
PIN EXT1 EXT2 EXT3 GPIO Function
---- ---- ---- ---- ------------------
13 --- PA19 PA19 SERCOM1 / USART RX
14 --- PA18 PA18 SERCOM1 / USART TX
19 GND GND GND N/A
20 VCC VCC VCC N/A
SERCOM2
-------
SERCOM0 is dedicated for use with I2C at the EXT1, EXT2, and EXT3
connectors.
SERCOM3
-------
SERCOM3 is not available on any EXT connector but is dedicated for
use with Virtual COM (see below).
SERCOM4
-------
SERCOM1 is available as a USART on EXT1
PIN EXT1 EXT2 EXT3 GPIO Function
---- ---- ---- ---- ------------------
13 PB09 --- --- SERCOM4 / USART RX
14 PB08 --- --- SERCOM4 / USART TX
19 GND GND GND N/A
20 VCC VCC VCC N/A
SERCOM5
-------
SERCOM5 is dedicated for use with SPI at the EXT2 and EXT3 connectors
Configuration
-------------
There are options available in the NuttX configuration to select which
connector SERCOM4 is on: SAML21_XPLAINED_USART4_EXTn, where n=1, 2, or 3.
If you have a TTL to RS-232 converter then this is the most convenient
serial console to use (because you don't lose the console device each time
you lose the USB connection). It is the default in all of these
configurations. An option is to use the virtual COM port.
Virtual COM Port
----------------
The SAML21 Xplained Pro contains an Embedded Debugger (EDBG) that can be
used to program and debug the ATSAML21J18A using Serial Wire Debug (SWD).
The Embedded debugger also include a Virtual COM port interface over
SERCOM3. Virtual COM port connections:
PA22 SERCOM3 / USART TXD
PA23 SERCOM3 / USART RXD
Atmel Studio 6.1
================
NOTE: These instructions are old. The SAML21 requires Atmel Studio 6.2.
They may still prove useful to you, however.
Loading Code into FLASH:
-----------------------
Tools menus: Tools -> Device Programming.
Debugging the NuttX Object File
-------------------------------
1) Rename object file from nutt to nuttx.elf. That is an extension that
will be recognized by the file menu.
2) File menu: File -> Open -> Open object file for debugging
- Select nuttx.elf object file
- Select AT91SAML21J18
- Select files for symbols as desired
- Select debugger
3) Debug menu: Debug -> Start debugging and break
- This will reload the nuttx.elf file into FLASH
JTAG
====
I did all of the debug of the SAML21 Xplained using a Segger J-Link
connected to the micro JTAG connector on board the SAML21 Xplained.
I used an Olimex ARM-JTAG 20-10 Adapter to connect the J-Link to
the SAML21 Xplained.
SAML21 Xplained Pro-specific Configuration Options
==================================================
CONFIG_ARCH - Identifies the arch/ subdirectory. This should
be set to:
CONFIG_ARCH=arm
CONFIG_ARCH_family - For use in C code:
CONFIG_ARCH_ARM=y
CONFIG_ARCH_architecture - For use in C code:
CONFIG_ARCH_CORTEXM0=y
CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_name - For use in C code to identify the exact
chip:
CONFIG_ARCH_CHIP_SAML2X
CONFIG_ARCH_CHIP_SAML21
CONFIG_ARCH_CHIP_ATSAML21J18
CONFIG_ARCH_BOARD - Identifies the boards/ subdirectory and
hence, the board that supports the particular chip or SoC.
CONFIG_ARCH_BOARD="saml21-xplained" (for the SAML21 Xplained Pro development board)
CONFIG_ARCH_BOARD_name - For use in C code
CONFIG_ARCH_BOARD_SAML21_XPLAINED=y
CONFIG_ARCH_LOOPSPERMSEC - Must be calibrated for correct operation
of delay loops
CONFIG_ENDIAN_BIG - define if big endian (default is little
endian)
CONFIG_RAM_SIZE - Describes the installed DRAM (SRAM in this case):
CONFIG_RAM_SIZE=0x00010000 (64KB)
CONFIG_RAM_START - The start address of installed DRAM
CONFIG_RAM_START=0x20000000
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to boards that
have LEDs
CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
stack. If defined, this symbol is the size of the interrupt
stack in bytes. If not defined, the user task stacks will be
used during interrupt handling.
CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to board architecture.
Individual subsystems can be enabled:
CONFIG_SAMD2L2_AC - Analog Comparator
CONFIG_SAMD2L2_ADC - Analog-to-Digital Converter
CONFIG_SAMD2L2_DAC - Digital-to-Analog Converter
CONFIG_SAMD2L2_DMAC - Analog Comparator
CONFIG_SAMD2L2_EVSYS - Event System
CONFIG_SAMD2L2_NVMCTRL - Non-Volatile Memory Controller
CONFIG_SAMD2L2_PTC - Peripheral Touch Controller
CONFIG_SAMD2L2_RTC - Real Time Counter
CONFIG_SAMD2L2_SERCOM0 - Serial Communication Interface 0
CONFIG_SAMD2L2_SERCOM1 - Serial Communication Interface 1
CONFIG_SAMD2L2_SERCOM2 - Serial Communication Interface 2
CONFIG_SAMD2L2_SERCOM3 - Serial Communication Interface 3
CONFIG_SAMD2L2_SERCOM4 - Serial Communication Interface 4
CONFIG_SAMD2L2_SERCOM5 - Serial Communication Interface 5
CONFIG_SAMD2L2_TCC0 - Timer/Counter 0 for Control
CONFIG_SAMD2L2_TCC1 - Timer/Counter 1 for Control
CONFIG_SAMD2L2_TCC2 - Timer/Counter 2 for Control
CONFIG_SAMD2L2_TC3 - Timer/Counter 3
CONFIG_SAMD2L2_TC4 - Timer/Counter 4
CONFIG_SAMD2L2_TC5 - Timer/Counter 5
CONFIG_SAMD2L2_TC6 - Timer/Counter 6
CONFIG_SAMD2L2_TC7 - Timer/Counter 6
CONFIG_SAMD2L2_USB - USB device or host
CONFIG_SAMD2L2_WDT - Watchdog Timer
Some subsystems can be configured to operate in different ways. The drivers
need to know how to configure the subsystem.
CONFIG_SAMD2L2_SERCOM0_ISI2C, CONFIG_SAMD2L2_SERCOM0_ISSPI, or CONFIG_SAMD2L2_SERCOM0_ISUSART
CONFIG_SAMD2L2_SERCOM1_ISI2C, CONFIG_SAMD2L2_SERCOM1_ISSPI, or CONFIG_SAMD2L2_SERCOM1_ISUSART
CONFIG_SAMD2L2_SERCOM2_ISI2C, CONFIG_SAMD2L2_SERCOM2_ISSPI, or CONFIG_SAMD2L2_SERCOM2_ISUSART
CONFIG_SAMD2L2_SERCOM3_ISI2C, CONFIG_SAMD2L2_SERCOM3_ISSPI, or CONFIG_SAMD2L2_SERCOM3_ISUSART
CONFIG_SAMD2L2_SERCOM4_ISI2C, CONFIG_SAMD2L2_SERCOM4_ISSPI, or CONFIG_SAMD2L2_SERCOM4_ISUSART
CONFIG_SAMD2L2_SERCOM5_ISI2C, CONFIG_SAMD2L2_SERCOM5_ISSPI, or CONFIG_SAMD2L2_SERCOM5_ISUSART
SAML21 specific device driver settings
CONFIG_USARTn_SERIAL_CONSOLE - selects the USARTn (n=0,1,2,..5) for the
console and ttys0 (default is the USART4).
CONFIG_USARTn_RXBUFSIZE - Characters are buffered as received.
This specific the size of the receive buffer
CONFIG_USARTn_TXBUFSIZE - Characters are buffered before
being sent. This specific the size of the transmit buffer
CONFIG_USARTn_BAUD - The configure BAUD of the USART. Must be
CONFIG_USARTn_BITS - The number of bits. Must be either 7 or 8.
CONFIG_USARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity
CONFIG_USARTn_2STOP - Two stop bits
Configurations
==============
Each SAML21 Xplained Pro configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh saml21-xplained:<subdir>
Before building, make sure that the PATH environmental variable includes the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of the following.
NOTE: These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output of on SERCOM4 which is available on EXT1 (see the section
"Serial Consoles" above). The SERCOM1 on EXT2 or EXT3 or the
virtual COM port on SERCOME could be used, instead, by
reconfiguring to use SERCOM1 or SERCOM3 instead of SERCOM4:
System Type -> SAMD/L Peripheral Support
CONFIG_SAMD2L2_SERCOM1=y : Enable one or both
CONFIG_SAMD2L2_SERCOM3=y
CONFIG_SAMD2L2_SERCOM4=n
Device Drivers -> Serial Driver Support -> Serial Console
CONFIG_USART1_SERIAL_CONSOLE=y : Select only one for the console
CONFIG_USART3_SERIAL_CONSOLE=y : Select only one for the console
CONFIG_USART4_SERIAL_CONSOLE=n
Device Drivers -> Serial Driver Support -> SERCOMn Configuration
where n=1 or 3:
CONFIG_USARTn_2STOP=0
CONFIG_USARTn_BAUD=115200
CONFIG_USARTn_BITS=8
CONFIG_USARTn_PARITY=0
CONFIG_USARTn_RXBUFSIZE=256
CONFIG_USARTn_TXBUFSIZE=256
3. Unless otherwise stated, the configurations are setup for
Cygwin under Windows:
Build Setup:
CONFIG_HOST_WINDOWS=y : Windows Host
CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on windows
4. These configurations use the ARM EABI toolchain. But
that is easily reconfigured:
System Type -> Toolchain:
CONFIG_ARMV6M_TOOLCHAIN_GNU_EABIW=y
Any re-configuration should be done before making NuttX or else the
subsequent 'make' will fail. If you have already attempted building
NuttX then you will have to 1) 'make distclean' to remove the old
configuration, 2) 'tools/configure.sh sam3u-ek/ksnh' to start
with a fresh configuration, and 3) perform the configuration changes
above.
Also, make sure that your PATH variable has the new path to your
Atmel tools. Try 'which arm-none-eabi-gcc' to make sure that you
are selecting the right tool.
See also the "NOTE about Windows native toolchains" in the section
called "GNU Toolchain Options" above.
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES above
and below:
NOTES:
1. This configuration is set up to build on Windows using the Cygwin
environment using the ARM EABI toolchain. This can be easily
changed as described above under "Configurations."
2. By default, this configuration provides a serial console on SERCOM4
at 115200 8N1 via EXT1:
PIN EXT1 GPIO Function
---- ---- ------------------
13 PB09 SERCOM4 / USART RX
14 PB08 SERCOM4 / USART TX
19 GND N/A
20 VCC N/A
If you would prefer to use the EDBG serial COM port or would prefer
to use SERCOM4 on EXT1 or EXT2, you will need to reconfigure the
SERCOM as described under "Configurations". See also the section
entitled "Serial Consoles" above.
3. NOTE: If you get a compilation error like:
libxx_new.cxx:74:40: error: 'operator new' takes type 'size_t'
('unsigned int') as first parameter [-fper
Sometimes NuttX and your toolchain will disagree on the underlying
type of size_t; sometimes it is an 'unsigned int' and sometimes it is
an 'unsigned long int'. If this error occurs, then you may need to
toggle the value of CONFIG_ARCH_SIZET_LONG.
4. WARNING: This info comes from the SAMD20 Xplained README. I have
not tried the I/O1 module on the SAML21!
If the I/O1 module is connected to the SAML21 Xplained Pro, then
support for the SD card slot can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
File Systems:
CONFIG_FS_FAT=y : Enable the FAT file system
CONFIG_FAT_LCNAMES=y : Enable upper/lower case 8.3 file names (Optional, see below)
CONFIG_FAT_LFN=y : Enable long file named (Optional, see below)
CONFIG_FAT_MAXFNAME=32 : Maximum supported file name length
There are issues related to patents that Microsoft holds on FAT long
file name technologies. See the top level NOTICE file for further
details.
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM0=y : Use SERCOM0 if the I/O is in EXT1
CONFIG_SAMD2L2_SERCOM0_ISSPI=y : Configure SERCOM0 as an SPI master
Device Drivers
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_MMCSD=y : Enable MMC/SD support
CONFIG_MMCSD_NSLOTS=1 : Only one MMC/SD card slot
CONFIG_MMCSD_MULTIBLOCK_DISABLE=n : Should not need to disable multi-block transfers
CONFIG_MMCSD_MMCSUPPORT=n : May interfere with some SD cards
CONFIG_MMCSD_HAVE_CARDDETECT=y : I/O1 module as a card detect GPIO
CONFIG_MMCSD_SPI=y : Use the SPI interface to the MMC/SD card
CONFIG_MMCSD_SPICLOCK=20000000 : This is a guess for the optimal MMC/SD frequency
CONFIG_MMCSD_SPIMODE=0 : Mode 0 is required
Board Selection -> Common Board Options
CONFIG_NSH_MMCSDSLOTNO=0 : Only one MMC/SD slot, slot 0
CONFIG_NSH_MMCSDSPIPORTNO=0 : Use port=0 -> SERCOM0 if the I/O1 is in EXT1
Board Selection -> SAML21 Xplained Pro Modules
CONFIG_SAML21_XPLAINED_IOMODULE=y : I/O1 module is connected
CONFIG_SAML21_XPLAINED_IOMODULE_EXT2=y : I/O1 modules is in EXT2
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : Board has architecture-specific initialization
NOTE: If you enable the I/O1 this configuration with SERCOM4 as the
console and with the I/O1 module in EXT1, you *must* remove USART
jumper. Otherwise, you have lookback on SERCOM4 and NSH will *not*
behave very well (since its outgoing prompts also appear as incoming
commands).
STATUS: As of 2013-6-18, this configuration appears completely
functional. Testing, however, has been very light. Example:
NuttShell (NSH) NuttX-6.34
nsh> mount -t vfat /dev/mmcsd0 /mnt/stuff
nsh> ls /mnt/stuff
/mnt/stuff:
nsh> echo "This is a test" >/mnt/stuff/atest.txt
nsh> ls /mnt/stuff
/mnt/stuff:
atest.txt
nsh> cat /mnt/stuff/atest.txt
This is a test
nsh>
5. WARNING: This info comes from the SAMD20 Xplained README. I have
not tried the OLED1 module on the SAML21!
5. If the OLED1 module is connected to the SAML21 Xplained Pro, then
support for the OLED display can be enabled by making the following
changes to the configuration. These changes assume that the I/O1
modules is connected in EXT1. Most of the modifications necessary
to work with the I/O1 in a different connector are obvious.. except
for the selection of SERCOM SPI support:
EXT1: SPI is provided through SERCOM0
EXT2: SPI is provided through SERCOM1
EXT3: SPI is provided through SERCOM5
System Type -> Peripherals:
CONFIG_SAMD2L2_SERCOM1=y : Use SERCOM1 if the I/O is in EXT2
CONFIG_SAMD2L2_SERCOM1_ISSPI=y : Configure SERCOM1 as an SPI master
Device Drivers -> SPI
CONFIG_SPI=y : Enable SPI support
CONFIG_SPI_EXCHANGE=y : The exchange() method is supported
CONFIG_SPI_CMDDATA=y : CMD/DATA support is required
Device Drivers -> LCDs
CONFIG_LCD=y : Enable LCD support
CONFIG_LCD_MAXCONTRAST=255 : Maximum contrast value
CONFIG_LCD_LANDSCAPE=y : Landscape orientation (see below*)
CONFIG_LCD_UG2832HSWEG04=y : Enable support for the OLED
CONFIG_LCD_SSD1306_SPIMODE=0 : SPI Mode 0
CONFIG_LCD_SSD1306_SPIMODE=3500000 : Pick an SPI frequency
Board Selection -> SAML21 Xplained Pro Modules
CONFIG_SAML21_XPLAINED_OLED1MODULE=y : OLED1 module is connected
CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2=y : OLED1 modules is in EXT2
The NX graphics subsystem also needs to be configured:
CONFIG_NX=y : Enable graphics support
CONFIG_NX_LCDDRIVER=y : Using an LCD driver
CONFIG_NX_NPLANES=1 : With a single color plane
CONFIG_NX_WRITEONLY=n : You can read from the LCD (see below*)
CONFIG_NX_DISABLE_2BPP=y : Disable all resolutions except 1BPP
CONFIG_NX_DISABLE_4BPP=y
CONFIG_NX_DISABLE_8BPP=y
CONFIG_NX_DISABLE_16BPP=y
CONFIG_NX_DISABLE_24BPP=y
CONFIG_NX_DISABLE_32BPP=y
CONFIG_NX_PACKEDMSFIRST=y : LSB packed first (shouldn't matter)
CONFIG_NXSTART_EXTERNINIT=y : We have board_graphics_setup()
CONFIG_NXTK_BORDERWIDTH=2 : Use a small border
CONFIG_NXTK_DEFAULT_BORDERCOLORS=y : Default border colors
CONFIG_NXFONTS_CHARBITS=7 : 7-bit fonts
CONFIG_NXFONT_SANS17X23B=y : Pick a font (any that will fit)
* The hardware is write only, but the driver maintains a frame buffer
to support read and read-write-modiry operations on the LCD.
Reading from the frame buffer is, however, untested.
Then, in order to use the OLED, you will need to build some kind of
graphics application or use one of the NuttX graphics examples.
Here, for example, is the setup for the graphic "Hello, World!"
example:
CONFIG_EXAMPLES_NXHELLO=y : Enables the example
CONFIG_EXAMPLES_NXHELLO_DEFAULT_COLORS=y : Use default colors (see below *)
CONFIG_EXAMPLES_NXHELLO_DEFAULT_FONT=y : Use the default font
CONFIG_EXAMPLES_NXHELLO_BPP=1 : One bit per pixel
CONFIG_EXAMPLES_NXHELLO_EXTERNINIT=y : Special initialization is required.
* The OLED is monochrome so the only "colors" are black and white.
The default "colors" will give you while text on a black background.
You can override the faults it you want black text on a while background.

View File

@ -0,0 +1,68 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_POSIX_TIMERS is not set
# CONFIG_NSH_DISABLEBG is not set
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLE_CMP is not set
# CONFIG_NSH_DISABLE_DD is not set
# CONFIG_NSH_DISABLE_EXEC is not set
# CONFIG_NSH_DISABLE_EXIT is not set
# CONFIG_NSH_DISABLE_GET is not set
# CONFIG_NSH_DISABLE_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_ITEF is not set
# CONFIG_NSH_DISABLE_LOOPS is not set
# CONFIG_NSH_DISABLE_LOSETUP is not set
# CONFIG_NSH_DISABLE_MKRD is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_SEMICOLON is not set
# CONFIG_NSH_DISABLE_WGET is not set
# CONFIG_NSH_DISABLE_XD is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="saml21-xplained"
CONFIG_ARCH_BOARD_SAML21_XPLAINED=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="samd2l2"
CONFIG_ARCH_CHIP_SAML21J18=y
CONFIG_ARCH_CHIP_SAML2X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=4356
CONFIG_BUILTIN=y
CONFIG_DEFAULT_SMALL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
CONFIG_INTELHEX_BINARY=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=32768
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SAMD2L2_SERCOM3=y
CONFIG_SAMD2L2_SERCOM4=y
CONFIG_SAML21_XPLAINED_DFLL=y
CONFIG_SAML21_XPLAINED_DFLL_CLOSEDLOOP=y
CONFIG_SAML21_XPLAINED_DFLL_XOSC32KSRC=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=12
CONFIG_START_MONTH=2
CONFIG_START_YEAR=2014
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USART4_RXBUFSIZE=64
CONFIG_USART4_SERIAL_CONSOLE=y
CONFIG_USART4_TXBUFSIZE=64
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,657 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_INCLUDE_BOARD_H
#define __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
# ifdef CONFIG_SAMD2L2_GPIOIRQ
# include <arch/irq.h>
# endif
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Clocking *****************************************************************/
/* Overview
*
* Since there is no high speed crystal, we will run from the OSC16M clock
* source.
* We will use its default, POR frequency of 4MHz to avoid an additional
* clock switch.
*
* OSC16M Output = 4MHz
* `- GCLK1 Input = 4MHz Prescaler = 1 output = 4MHz
* `- DFLL Input = 4MHz Multiplier = 12 output = 48MHz
* `- GCLK0 Input = 48MHz Prescaler = 1 output = 48MHz
* `- MCLK Input = 48Mhz CPU divider = 1 CPU frequency = 48MHz
* APBA divider = 1 APBA frequency = 48MHz
* APBB divider = 1 APBB frequency = 48MHz
* APBC divider = 1 APBC frequency = 48MHz
* APBD divider = 1 APBD frequency = 48MHz
* APBE divider = 1 APBE frequency = 48MHz
*
* The SAML21 Xplained Pro has one on-board crystal:
*
* XC101 32.768KHz XOSC32
*
* REVISIT: Not currently used, may want to use as GCLK1 source with
* DFLL multiplier of ((48000000+16384)/32768) = 1465 which would yield
* a clock of 48,005,120 MHz.
*/
/* XOSC Configuration -- Not available
*
* BOARD_XOSC_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC_FREQUENCY - In Hz
* BOARD_XOSC_STARTUPTIME - See SYSCTRL_XOSC_STARTUP_* definitions
* BOARD_XOSC_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC_AMPGC - Boolean (defined / not defined)
* BOARD_XOSC_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC_RUNINSTANDBY - Boolean (defined / not defined)
*/
#undef BOARD_XOSC_ENABLE
#define BOARD_XOSC_FREQUENCY 12000000UL
#define BOARD_XOSC_STARTUPTIME SYSCTRL_XOSC_STARTUP_1S
#define BOARD_XOSC_ISCRYSTAL 1
#define BOARD_XOSC_AMPGC 1
#define BOARD_XOSC_ONDEMAND 1
#undef BOARD_XOSC_RUNINSTANDBY
/* XOSC32 Configuration -- Not used
*
* BOARD_XOSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_XOSC32K_FREQUENCY - In Hz
* BOARD_XOSC32K_STARTUPTIME - See SYSCTRL_XOSC32K_STARTUP_* definitions
* BOARD_XOSC32K_ISCRYSTAL - Boolean (defined / not defined)
* BOARD_XOSC32K_AAMPEN - Boolean (defined / not defined)
* BOARD_XOSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_XOSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_XOSC32K_RUNINSTANDBY - Boolean (defined / not defined)
* BOARD_XOSC32K_WRITELOCK - Boolean (defined / not defined)
*/
#undef BOARD_XOSC32K_ENABLE
#ifdef CONFIG_SAML21_XPLAINED_XOSC32K
# define BOARD_XOSC32K_ENABLE 1
# define BOARD_XOSC32K_FREQUENCY 32768 /* 32.768KHz XTAL */
# define BOARD_XOSC32K_STARTUPTIME OSC32KCTRL_XOSC32K_STARTUP_100MS
# define BOARD_XOSC32K_ISCRYSTAL 1
# undef BOARD_XOSC32K_EN1KHZ
# define BOARD_XOSC32K_EN32KHZ 1
# define BOARD_XOSC32K_ONDEMAND 1
# undef BOARD_XOSC32K_RUNINSTANDBY
# undef BOARD_XOSC32K_WRITELOCK
#endif
/* OSC32 Configuration -- not used
*
* BOARD_OSC32K_ENABLE - Boolean (defined / not defined)
* BOARD_OSC32K_FREQUENCY - In Hz
* BOARD_OSC32K_STARTUPTIME - See SYSCTRL_OSC32K_STARTUP_* definitions
* BOARD_OSC32K_EN1KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_EN32KHZ - Boolean (defined / not defined)
* BOARD_OSC32K_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC32K_RUNINSTANDBY - Boolean (defined / not defined)
* BOARD_OSC32K_WRITELOCK - Boolean (defined / not defined)
*/
#undef BOARD_OSC32K_ENABLE
#define BOARD_OSC32K_FREQUENCY 32768 /* 32.768kHz internal oscillator */
#define BOARD_OSC32K_STARTUPTIME SYSCTRL_OSC32K_STARTUP_4MS
#define BOARD_OSC32K_EN1KHZ 1
#define BOARD_OSC32K_EN32KHZ 1
#define BOARD_OSC32K_ONDEMAND 1
#undef BOARD_OSC32K_RUNINSTANDBY
#undef BOARD_OSC32K_WRITELOCK
/* OSC16M Configuration -- always enabled
*
* BOARD_OSC16M_FSEL - See OSCCTRL_OSC16MCTRL_FSEL_* definitions
* BOARD_OSC16M_ONDEMAND - Boolean (defined / not defined)
* BOARD_OSC16M_RUNINSTANDBY - Boolean (defined / not defined)
*/
#if defined(CONFIG_SAML21_XPLAINED_OSC16M_4MHZ)
# define BOARD_OSC16M_FSEL OSCCTRL_OSC16MCTRL_FSEL_4MHZ
# define BOARD_OSC16M_ONDEMAND 1
# undef BOARD_OSC16M_RUNINSTANDBY
# define BOARD_OSC16M_FREQUENCY 4000000 /* 4MHz high-accuracy internal oscillator */
#elif defined(CONFIG_SAML21_XPLAINED_OSC16M_8MHZ)
# define BOARD_OSC16M_FSEL OSCCTRL_OSC16MCTRL_FSEL_8MHZ
# define BOARD_OSC16M_ONDEMAND 1
# undef BOARD_OSC16M_RUNINSTANDBY
# define BOARD_OSC16M_FREQUENCY 8000000 /* 8MHz high-accuracy internal oscillator */
#elif defined(CONFIG_SAML21_XPLAINED_OSC16M_12MHZ)
# define BOARD_OSC16M_FSEL OSCCTRL_OSC16MCTRL_FSEL_12MHZ
# define BOARD_OSC16M_ONDEMAND 1
# undef BOARD_OSC16M_RUNINSTANDBY
# define BOARD_OSC16M_FREQUENCY 12000000 /* 12MHz high-accuracy internal oscillator */
#elif defined(CONFIG_SAML21_XPLAINED_OSC16M_16MHZ)
# define BOARD_OSC16M_FSEL OSCCTRL_OSC16MCTRL_FSEL_16MHZ
# define BOARD_OSC16M_ONDEMAND 1
# undef BOARD_OSC16M_RUNINSTANDBY
# define BOARD_OSC16M_FREQUENCY 16000000 /* 18MHz high-accuracy internal oscillator */
#else
# error OSC16M operating frequency not defined (CONFIG_SAML21_XPLAINED_OSC16M_*MHZ)
#endif
/* OSCULP32K Configuration -- not used. */
#define BOARD_OSCULP32K_FREQUENCY 32000 /* 32kHz ultra-low-power internal oscillator */
/* Digital Frequency Locked Loop configuration. In closed-loop mode, the
* DFLL output frequency (Fdfll) is given by:
*
* Fdfll = DFLLmul * Frefclk
* = 12 * 4000000 = 48MHz
*
* Where the reference clock is Generic Clock Channel 0 output of GLCK1.
* GCLCK1 provides OSC16M, undivided.
*
* When operating in open-loop mode, the output frequency of the DFLL will
* be determined by the values written to the DFLL Coarse Value bit group
* and the DFLL Fine Value bit group in the DFLL Value register.
*
* BOARD_DFLL48M_CLOSEDLOOP - Boolean (defined / not defined)
* BOARD_DFLL48M_OPENLOOP - Boolean (defined / not defined)
* BOARD_DFLL48M_RECOVERY - Boolean (defined / not defined)
* BOARD_DFLL48M_TRACKAFTERFINELOCK - Boolean (defined / not defined)
* BOARD_DFLL48M_KEEPLOCKONWAKEUP - Boolean (defined / not defined)
* BOARD_DFLL48M_ENABLECHILLCYCLE - Boolean (defined / not defined)
* BOARD_DFLL48M_QUICKLOCK - Boolean (defined / not defined)
* BOARD_DFLL48M_RUNINSTDBY - Boolean (defined / not defined)
* BOARD_DFLL48M_ONDEMAND - Boolean (defined / not defined)
*
* Closed loop mode only:
* BOARD_DFLL48M_REFCLK_CLKGEN - GCLK index in the range {0..8}
* BOARD_DFLL48M_MULTIPLIER - Value
* BOARD_DFLL48M_MAXCOARSESTEP - Value
* BOARD_DFLL48M_MAXFINESTEP - Value
*
* BOARD_DFLL48M_FREQUENCY - The resulting frequency
*/
#undef BOARD_DFLL48M_ENABLE 1 /* Assume not using the DFLL48M */
#undef BOARD_DFLL48M_CLOSEDLOOP
#undef BOARD_DFLL48M_OPENLOOP
#undef BOARD_DFLL48M_RECOVERY
#ifdef CONFIG_SAML21_XPLAINED_DFLL
# define BOARD_DFLL48M_ENABLE 1 /* Using the DFLL48M */
/* DFLL mode of operation */
# if defined(CONFIG_SAML21_XPLAINED_DFLL_OPENLOOP)
# define BOARD_DFLL48M_OPENLOOP 1 /* In open loop mode */
# elif defined(CONFIG_SAML21_XPLAINED_DFLL_CLOSEDLOOP)
# define BOARD_DFLL48M_CLOSEDLOOP 1 /* In closed loop mode */
# elif defined(CONFIG_SAML21_XPLAINED_DFLL_RECOVERY)
# define BOARD_DFLL48M_RECOVERY 1 /* In USB recover mode */
# else
# error DFLL mode not provided
# endif
/* DFLL source clock selection */
# if defined(CONFIG_SAML21_XPLAINED_DFLL_OSC16MSRC)
# define BOARD_DFLL_SRC_FREQUENCY BOARD_OSC16M_FREQUENCY
# elif defined(CONFIG_SAML21_XPLAINED_DFLL_XOSC32KSRC)
# define BOARD_DFLL_SRC_FREQUENCY BOARD_XOSC32K_FREQUENCY
# else
# error DFLL clock source not provided
# endif
/* Mode-independent options */
# undef BOARD_DFLL48M_RUNINSTDBY
# undef BOARD_DFLL48M_ONDEMAND
/* DFLL closed loop mode configuration */
# define BOARD_DFLL48M_REFCLK_CLKGEN 1
# define BOARD_DFLL48M_MULTIPLIER (48000000 / BOARD_DFLL_SRC_FREQUENCY)
# define BOARD_DFLL48M_QUICKLOCK 1
# define BOARD_DFLL48M_TRACKAFTERFINELOCK 1
# define BOARD_DFLL48M_KEEPLOCKONWAKEUP 1
# define BOARD_DFLL48M_ENABLECHILLCYCLE 1
# define BOARD_DFLL48M_MAXCOARSESTEP (0x1f / 4)
# define BOARD_DFLL48M_MAXFINESTEP (0xff / 4)
# ifdef CONFIG_SAML21_XPLAINED_DFLL_OPENLOOP
# define BOARD_DFLL48M_FREQUENCY (13720000) /* REVISIT: Needs to be measured */
# else
# define BOARD_DFLL48M_FREQUENCY (BOARD_DFLL48M_MULTIPLIER * BOARD_DFLL_SRC_FREQUENCY)
# endif
#endif
/* Fractional Digital Phase Locked Loop configuration.
*
* BOARD_FDPLL96M_ENABLE - Boolean (defined / not defined)
* BOARD_FDPLL96M_RUNINSTDBY - Boolean (defined / not defined)
* BOARD_FDPLL96M_ONDEMAND - Boolean (defined / not defined)
* BOARD_FDPLL96M_LBYPASS - Boolean (defined / not defined)
* BOARD_FDPLL96M_WUF - Boolean (defined / not defined)
* BOARD_FDPLL96M_LPEN - Boolean (defined / not defined)
* BOARD_FDPLL96M_FILTER - See OSCCTRL_DPLLCTRLB_FILTER_*
* definitions
* BOARD_FDPLL96M_REFCLK - See OSCCTRL_DPLLCTRLB_REFLCK_*
* definitions
* BOARD_FDPLL96M_REFCLK_CLKGEN - GCLK index in the range {0..8}
* BOARD_FDPLL96M_LOCKTIME_ENABLE - Boolean (defined / not defined)
* BOARD_FDPLL96M_LOCKTIME - See OSCCTRL_DPLLCTRLB_LTIME_*
* definitions
* BOARD_FDPLL96M_LOCKTIME_CLKGEN - GCLK index in the range {0..8}
* BOARD_FDPLL96M_REFDIV - Numeric value, 1 - 2047
* BOARD_FDPLL96M_PRESCALER - See OSCCTRL_DPLLPRESC_* definitions
* BOARD_FDPLL96M_REFFREQ - Numeric value
* BOARD_FDPLL96M_FREQUENCY - Numeric value
*/
#undef BOARD_FDPLL96M_ENABLE
#undef BOARD_FDPLL96M_RUNINSTDBY
#define BOARD_FDPLL96M_ONDEMAND 1
#undef BOARD_FDPLL96M_LBYPASS
#undef BOARD_FDPLL96M_WUF
#undef BOARD_FDPLL96M_LPEN
#define BOARD_FDPLL96M_FILTER OSCCTRL_DPLLCTRLB_FILTER_DEFAULT
#define BOARD_FDPLL96M_REFCLK OSCCTRL_DPLLCTRLB_REFLCK_XOSCK32K
#define BOARD_FDPLL96M_REFCLK_CLKGEN 1
#undef BOARD_FDPLL96M_LOCKTIME_ENABLE
#define BOARD_FDPLL96M_LOCKTIME OSCCTRL_DPLLCTRLB_LTIME_NONE
#define BOARD_FDPLL96M_LOCKTIME_CLKGEN 1
#define BOARD_FDPLL96M_REFDIV 1
#define BOARD_FDPLL96M_PRESCALER OSCCTRL_DPLLPRESC_DIV1
#define BOARD_FDPLL96M_REFFREQ 32768
#define BOARD_FDPLL96M_FREQUENCY 48000000
/* GCLK Configuration
*
* Global enable/disable.
*
* BOARD_GCLK_ENABLE - *MUST* be defined
*
* For n=1-7:
* BOARD_GCLKn_ENABLE - Boolean (defined / not defined)
*
* For n=0-8:
* BOARD_GCLKn_RUN_IN_STANDBY - Boolean (defined / not defined)
* BOARD_GCLKn_CLOCK_SOURCE - See GCLK_GENCTRL_SRC_* definitions
* BOARD_GCLKn_PRESCALER - Value
* BOARD_GCLKn_OUTPUT_ENABLE - Boolean (defined / not defined)
*/
#define BOARD_GCLK_ENABLE 1
/* GCLK generator 0 (Main Clock) - Source is the DFLL */
#ifdef CONFIG_SAML21_XPLAINED_DFLL
# undef BOARD_GCLK0_RUN_IN_STANDBY
# define BOARD_GCLK0_CLOCK_SOURCE GCLK_GENCTRL_SRC_DFLL48M
# define BOARD_GCLK0_PRESCALER 1
# undef BOARD_GCLK0_OUTPUT_ENABLE
# define BOARD_GCLK0_FREQUENCY (BOARD_DFLL48M_FREQUENCY / BOARD_GCLK0_PRESCALER)
#else
# undef BOARD_GCLK0_RUN_IN_STANDBY
# define BOARD_GCLK0_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
# define BOARD_GCLK0_PRESCALER 1
# undef BOARD_GCLK0_OUTPUT_ENABLE
# define BOARD_GCLK0_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK0_PRESCALER)
#endif
/* Configure GCLK generator 1 - Drives the DFLL */
#if defined(CONFIG_SAML21_XPLAINED_DFLL_OSC16MSRC)
# define BOARD_GCLK1_ENABLE 1
# undef BOARD_GCLK1_RUN_IN_STANDBY
# define BOARD_GCLK1_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
# define BOARD_GCLK1_PRESCALER 1
# undef BOARD_GCLK1_OUTPUT_ENABLE
# define BOARD_GCLK1_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK1_PRESCALER)
#elif defined(CONFIG_SAML21_XPLAINED_DFLL_XOSC32KSRC)
# define BOARD_GCLK1_ENABLE 1
# undef BOARD_GCLK1_RUN_IN_STANDBY
# define BOARD_GCLK1_CLOCK_SOURCE GCLK_GENCTRL_SRC_XOSC32K
# define BOARD_GCLK1_PRESCALER 1
# undef BOARD_GCLK1_OUTPUT_ENABLE
# define BOARD_GCLK1_FREQUENCY (BOARD_XOSC32K_FREQUENCY / BOARD_GCLK1_PRESCALER)
#else
# error DFLL clock source not provided
#endif
/* Configure GCLK generator 2 (RTC) */
#undef BOARD_GCLK2_ENABLE
#undef BOARD_GCLK2_RUN_IN_STANDBY
#define BOARD_GCLK2_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC32K
#define BOARD_GCLK2_PRESCALER 32
#undef BOARD_GCLK2_OUTPUT_ENABLE
#define BOARD_GCLK2_FREQUENCY (BOARD_OSC32K_FREQUENCY / BOARD_GCLK2_PRESCALER)
/* Configure GCLK generator 3 */
#undef BOARD_GCLK3_ENABLE
#undef BOARD_GCLK3_RUN_IN_STANDBY
#define BOARD_GCLK3_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK3_PRESCALER 1
#undef BOARD_GCLK3_OUTPUT_ENABLE
#define BOARD_GCLK3_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK3_PRESCALER)
/* Configure GCLK generator 4 */
#undef BOARD_GCLK4_ENABLE
#undef BOARD_GCLK4_RUN_IN_STANDBY
#define BOARD_GCLK4_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK4_PRESCALER 1
#undef BOARD_GCLK4_OUTPUT_ENABLE
#define BOARD_GCLK4_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK4_PRESCALER)
/* Configure GCLK generator 5 */
#undef BOARD_GCLK5_ENABLE
#undef BOARD_GCLK5_RUN_IN_STANDBY
#define BOARD_GCLK5_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK5_PRESCALER 1
#undef BOARD_GCLK5_OUTPUT_ENABLE
#define BOARD_GCLK5_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK5_PRESCALER)
/* Configure GCLK generator 6 */
#undef BOARD_GCLK6_ENABLE
#undef BOARD_GCLK6_RUN_IN_STANDBY
#define BOARD_GCLK6_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK6_PRESCALER 1
#undef BOARD_GCLK6_OUTPUT_ENABLE
#define BOARD_GCLK6_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK6_PRESCALER)
/* Configure GCLK generator 7 */
#undef BOARD_GCLK7_ENABLE
#undef BOARD_GCLK7_RUN_IN_STANDBY
#define BOARD_GCLK7_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK7_PRESCALER 1
#undef BOARD_GCLK7_OUTPUT_ENABLE
#define BOARD_GCLK7_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK7_PRESCALER)
/* Configure GCLK generator 8 */
#undef BOARD_GCLK8_ENABLE
#undef BOARD_GCLK8_RUN_IN_STANDBY
#define BOARD_GCLK8_CLOCK_SOURCE GCLK_GENCTRL_SRC_OSC16M
#define BOARD_GCLK8_PRESCALER 1
#undef BOARD_GCLK8_OUTPUT_ENABLE
#define BOARD_GCLK8_FREQUENCY (BOARD_OSC16M_FREQUENCY / BOARD_GCLK8_PRESCALER)
/* The source of the main clock is always GCLK_MAIN. Also called GCLKGEN[0],
* this is the clock feeding the Power Manager.
* The Power Manager, in turn, generates main clock which is divided
* down to produce the CPU, AHB, and APB clocks.
*
* The main clock is initially OSC16M divided by 8.
*/
#define BOARD_GCLK_MAIN_FREQUENCY BOARD_GCLK0_FREQUENCY
/* Main clock dividers
*
* BOARD_CPU_DIVIDER - See MCLK_CPUDIV_DIV* definitions
* BOARD_CPU_FRQUENCY - In Hz
* BOARD_CPU_FAILDECT - Boolean (defined / not defined)
* BOARD_LOWPOWER_DIVIDER - See MCLK_LPDIV_DIV_* definitions
* BOARD_LOWPOWER_FREQUENCY - In Hz
* BOARD_BACKUP_DIVIDER - See MCLK_BUPDIV_DIV_* definitions
* BOARD_BACKUP_FREQUENCY - In Hz
*/
#undef BOARD_CPU_FAILDECT
#define BOARD_CPU_DIVIDER MCLK_CPUDIV_DIV1
#define BOARD_LOWPOWER_DIVIDER MCLK_LPDIV_DIV1
#define BOARD_BACKUP_DIVIDER MCLK_BUPDIV_DIV1
/* Resulting frequencies */
#define BOARD_MCK_FREQUENCY (BOARD_GCLK_MAIN_FREQUENCY)
#define BOARD_CPU_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_LOWPOWER_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_BACKUP_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_APBA_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_APBB_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_APBC_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_APBD_FREQUENCY (BOARD_MCK_FREQUENCY)
#define BOARD_APBE_FREQUENCY (BOARD_MCK_FREQUENCY)
/* FLASH wait states
*
* REVISIT: These values come from the SAMD20
* Vdd Range Wait states Maximum Operating Frequency
* ------------- -------------- ---------------------------
* 1.62V to 2.7V 0 14 MHz
* 1 28 MHz
* 2 42 MHz
* 3 48 MHz
* 2.7V to 3.63V 0 24 MHz
* 1 48 MHz
*/
#if 0
# define BOARD_FLASH_WAITSTATES 3
#else
# define BOARD_FLASH_WAITSTATES 1
#endif
/* SERCOM definitions *******************************************************/
/* This is the source clock generator for the GCLK_SERCOM_SLOW clock that is
* common to SERCOM modules 0-4.
* It will generate clocking on the common SERCOM0-4 channel.
*
* SERCOM5 uses a different channel and will probably need to use a different
* GCLK generator.
*/
#define BOARD_SERCOM04_SLOW_GCLKGEN 0
/* SERCOM0 SPI is available on EXT1
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PA5 SERCOM0 PAD1 SPI SS
* 16 PA6 SERCOM0 PAD2 SPI MOSI
* 17 PA4 SERCOM0 PAD0 SPI MISO
* 18 PA7 SERCOM0 PAD3 SPI SCK
*/
#define BOARD_SERCOM0_GCLKGEN 0
#define BOARD_SERCOM0_SLOW_GCLKGEN BOARD_SERCOM04_SLOW_GCLKGEN
#define BOARD_SERCOM0_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM0_PINMAP_PAD0 PORT_SERCOM0_PAD0_2 /* SPI_MISO */
#define BOARD_SERCOM0_PINMAP_PAD1 0 /* SPI_SS (not used) */
#define BOARD_SERCOM0_PINMAP_PAD2 PORT_SERCOM0_PAD2_2 /* SPI_MOSI */
#define BOARD_SERCOM0_PINMAP_PAD3 PORT_SERCOM0_PAD3_2 /* SPI_SCK */
#define BOARD_SERCOM0_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM1 USART is available on EXT2 and EXT3
*
* PIN EXT1 EXT2 EXT3 GPIO Function
* ---- ---- ---- ---- ------------------
* 13 --- PA19 PA19 SERCOM1 / USART RX
* 14 --- PA18 PA18 SERCOM1 / USART TX
* 19 GND GND GND N/A
* 20 VCC VCC VCC N/A
*/
#define BOARD_SERCOM1_GCLKGEN 0
#define BOARD_SERCOM1_SLOW_GCLKGEN BOARD_SERCOM04_SLOW_GCLKGEN
#define BOARD_SERCOM1_MUXCONFIG (USART_CTRLA_TXPAD2 | USART_CTRLA_RXPAD3)
#define BOARD_SERCOM1_PINMAP_PAD0 0 /* (not used) */
#define BOARD_SERCOM1_PINMAP_PAD1 0 /* (not used) */
#define BOARD_SERCOM1_PINMAP_PAD2 PORT_SERCOM1_PAD2_1 /* USART_TX */
#define BOARD_SERCOM1_PINMAP_PAD3 PORT_SERCOM1_PAD3_1 /* USART_RX */
#define BOARD_SERCOM1_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SAML21 Xplained Pro contains an Embedded Debugger (EDBG) that can be
* used to program and debug the ATSAML21J18A using Serial Wire Debug (SWD).
* The Embedded debugger also include a Virtual COM port interface over
* SERCOM3. Virtual COM port connections:
*
* PA22 SERCOM3 PAD[0] / USART TXD
* PA23 SERCOM3 PAD[1] / USART RXD
*/
#define BOARD_SERCOM3_GCLKGEN 0
#define BOARD_SERCOM3_SLOW_GCLKGEN BOARD_SERCOM04_SLOW_GCLKGEN
#define BOARD_SERCOM3_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0_2)
#define BOARD_SERCOM3_PINMAP_PAD0 PORT_SERCOM3_PAD0_1 /* USART TX */
#define BOARD_SERCOM3_PINMAP_PAD1 PORT_SERCOM3_PAD1_1 /* USART RX */
#define BOARD_SERCOM3_PINMAP_PAD2 0 /* (not used) */
#define BOARD_SERCOM3_PINMAP_PAD3 0 /* (not used) */
#define BOARD_SERCOM3_FREQUENCY BOARD_GCLK0_FREQUENCY
/* The SERCOM4 USART is available on EXT1
*
* PIN EXT1 EXT2 EXT3 GPIO Function
* ---- ---- ---- ---- ------------------
* 13 PB09 --- --- SERCOM4 PAD[1] / USART RX
* 14 PB08 --- --- SERCOM4 PAD[0] / USART TX
* 19 GND GND GND N/A
* 20 VCC VCC VCC N/A
*/
#define BOARD_SERCOM4_GCLKGEN 0
#define BOARD_SERCOM4_SLOW_GCLKGEN BOARD_SERCOM04_SLOW_GCLKGEN
#define BOARD_SERCOM4_MUXCONFIG (USART_CTRLA_RXPAD1 | USART_CTRLA_TXPAD0_2)
#define BOARD_SERCOM4_PINMAP_PAD0 PORT_SERCOM4_PAD0_3 /* USART TX */
#define BOARD_SERCOM4_PINMAP_PAD1 PORT_SERCOM4_PAD1_3 /* USART RX */
#define BOARD_SERCOM4_PINMAP_PAD2 0
#define BOARD_SERCOM4_PINMAP_PAD3 0
#define BOARD_SERCOM4_FREQUENCY BOARD_GCLK0_FREQUENCY
/* SERCOM5 is dedicated for use with SPI at the EXT2 and EXT3 connectors
*
* PIN PORT SERCOM FUNCTION
* --- ------------------ -----------
* 15 PB17 SERCOM5 PAD1 SPI SS
* 16 PB22 SERCOM5 PAD2 SPI MOSI
* 17 PB16 SERCOM5 PAD0 SPI MISO
* 18 PB23 SERCOM5 PAD3 SPI SCK
*/
#define BOARD_SERCOM5_GCLKGEN 0
#define BOARD_SERCOM5_SLOW_GCLKGEN ?
#define BOARD_SERCOM5_MUXCONFIG (SPI_CTRLA_DOPO_DOPAD231 | SPI_CTRLA_DIPAD0)
#define BOARD_SERCOM5_PINMAP_PAD0 PORT_SERCOM5_PAD0_1 /* SPI_MISO */
#define BOARD_SERCOM5_PINMAP_PAD1 0 /* SPI_SS (not used) */
#define BOARD_SERCOM5_PINMAP_PAD2 PORT_SERCOM5_PAD2_4 /* SPI_MOSI */
#define BOARD_SERCOM5_PINMAP_PAD3 PORT_SERCOM5_PAD3_4 /* SPI_SCK */
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK0_FREQUENCY
/* USB definitions **********************************************************/
/* This is the source clock generator for the GCLK_USB clock
*/
#define BOARD_USB_GCLKGEN 0
#define BOARD_USB_FREQUENCY BOARD_GCLK0_FREQUENCY
/* default USB Pad calibration (not used yet by USB driver) */
#define BOARD_USB_PADCAL_P 29
#define BOARD_USB_PADCAL_N 5
#define BOARD_USB_PADCAL_TRIM 3
/* LED definitions **********************************************************/
/* There are three LEDs on board the SAML21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAML21
* USB connector.
*
* This LED is controlled by PC07 and the LED can be activated by driving
* the PB10 to GND.
*/
/* LED index values for use with board_userled() */
#define BOARD_STATUS_LED 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_STATUS LED_BIT (1 << BOARD_STATUS_LED)
/* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as defined below.
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally.
* If the LED is flashing at approximately 2Hz, then a fatal error has been
* detected and the system has halted.
*/
#define LED_STARTED 0 /* STATUS LED=OFF */
#define LED_HEAPALLOCATE 0 /* STATUS LED=OFF */
#define LED_IRQSENABLED 0 /* STATUS LED=OFF */
#define LED_STACKCREATED 1 /* STATUS LED=ON */
#define LED_INIRQ 2 /* STATUS LED=no change */
#define LED_SIGNAL 2 /* STATUS LED=no change */
#define LED_ASSERTION 2 /* STATUS LED=no change */
#define LED_PANIC 3 /* STATUS LED=flashing */
/* Button definitions *******************************************************/
/* Mechanical buttons:
*
* The SAML21 Xplained Pro contains two mechanical buttons.
* One button is the RESET button connected to the SAML21 reset line and the
* other is a generic user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA02 SW0
*/
/* The SAML21 Xplained Pro supports one button: */
#define BUTTON_SW0 0
#define NUM_BUTTONS 1
#define BUTTON_SW0_BIT (1 << BUTTON_SW0)
#endif /* __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_INCLUDE_BOARD_H */

View File

@ -0,0 +1,63 @@
############################################################################
# boards/arm/samd2l2/saml21-xplained/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv6-m/Toolchain.defs
LDSCRIPT = flash.ld
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif

View File

@ -0,0 +1,118 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/scripts/flash.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAML21J18A has 256KB of FLASH beginning at address 0x0000:0000 and
* 32KB of SRAM beginning at address 0x2000:0000. There is also 8KB low-
* power SRAM at 0x30000000 that may be used by the DMAC.
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
lpram (rw) : ORIGIN = 0x30000000, LENGTH = 8K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
ENTRY(_stext)
SECTIONS
{
.text : {
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section : {
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > flash
.ARM.extab : {
*(.ARM.extab*)
} >flash
.ARM.exidx : {
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >flash
.data : {
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
_eronly = LOADADDR(.data);
.ramfunc ALIGN(4): {
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > flash
_framfuncs = LOADADDR(.ramfunc);
.bss : {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
.lpram : {
_slpram = ABSOLUTE(.);
*(.lpram)
_elpram = ABSOLUTE(.);
} > lpram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,53 @@
############################################################################
# boards/arm/samd2l2/saml21-xplained/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = sam_boot.c
ifeq ($(CONFIG_SAMD2L2_SERCOM0),y)
CSRCS += sam_spi.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
CSRCS += sam_userleds.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += sam_buttons.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sam_appinit.c
endif
ifeq ($(CONFIG_SAML21_XPLAINED_IOMODULE),y)
CSRCS += sam_mmcsd.c
endif
ifeq ($(CONFIG_SAML21_XPLAINED_OLED1MODULE),y)
ifeq ($(CONFIG_LCD_UG2832HSWEG04),y)
CSRCS += sam_ug2832hsweg04.c
endif
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,123 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "saml21-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Some configuration checks */
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT1
# ifndef SAMD2L2_HAVE_SPI0
# error I/O1 module on EXT1 requires SERCOM SPI0
# undef CONFIG_SAML21_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 0
#endif
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT2
# ifndef SAMD2L2_HAVE_SPI1
# error I/O1 module on EXT2 requires SERCOM SPI1
# undef CONFIG_SAML21_XPLAINED_IOMODULE
# endif
# define SPI_PORTNO 1
#endif
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE
/* Support for the SD card slot on the I/O1 module */
/* Verify NSH PORT and SLOT settings */
# define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAMD2L2_MMCSDSLOTNO
# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO)
# endif
# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SPI_PORTNO
# error CONFIG_NSH_MMCSDSPIPORTNO must have the same value as SPI_PORTNO
# endif
/* Default MMC/SD minor number */
# ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
# endif
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
#if defined(SAMD2L2_HAVE_SPI0) && defined(CONFIG_SAML21_XPLAINED_IOMODULE)
/* Initialize the SPI-based MMC/SD slot */
int ret = sam_sdinitialize(SPI_PORTNO, CONFIG_NSH_MMCSDMINOR);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize MMC/SD slot: %d\n",
ret);
return ret;
}
#endif
return OK;
}

View File

@ -0,0 +1,149 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_autoleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAML21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labelled STATUS near the SAML21
* USB connector.
*
* This LED is controlled by PB10 and the LED can be activated by driving
* PB10 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt** N/C
* LED_SIGNAL In a signal handler*** N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "saml21-xplained.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
bool ledstate = true;
switch (led)
{
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
break; /* Leave ledstate == true to turn OFF */
default:
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
ledstate = false; /* Set ledstate == false to turn ON */
break;
}
sam_portwrite(PORT_STATUS_LED, ledstate);
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
/* These should not happen and are ignored */
default:
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
/* These result in no-change */
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
/* Turn STATUS LED off set driving the output high */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
sam_portwrite(PORT_STATUS_LED, true);
break;
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,77 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_boot.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include "sam_config.h"
#include "saml21-xplained.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_boardinitialize
*
* Description:
* All SAM3U architectures must provide the following entry point.
* This entry point is called early in the initialization -- after all
* memory has been configured and mapped but before any devices have been
* initialized.
*
****************************************************************************/
void sam_boardinitialize(void)
{
/* Configure SPI chip selects if
* 1) SPI is not disabled, and
* 2) the weak function
* sam_spidev_initialize() has been brought into the link.
*/
#ifdef SAMD2L2_HAVE_SPI
if (sam_spidev_initialize)
{
sam_spidev_initialize();
}
#endif
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS
board_autoled_initialize();
#endif
}

View File

@ -0,0 +1,128 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_buttons.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/irq.h>
#include <nuttx/irq.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "saml21-xplained.h"
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_button_initialize
*
* Description:
* board_button_initialize() must be called to initialize button resources.
* After that, board_buttons() may be called to collect the current state
* of all buttons or board_button_irq() may be called to register button
* interrupt handlers.
*
****************************************************************************/
uint32_t board_button_initialize(void)
{
sam_configport(PORT_SW0);
return NUM_BUTTONS;
}
/****************************************************************************
* Name: board_buttons
*
* Description:
* After board_button_initialize() has been called,
* board_buttons() may be called to collect the state of all buttons.
* board_buttons() returns an 32-bit bit set with each bit associated
* with a button. See the BUTTON* definitions above for the meaning of
* each bit in the returned value.
*
****************************************************************************/
uint32_t board_buttons(void)
{
return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT;
}
/****************************************************************************
* Name: board_button_irq
*
* Description:
* This function may be called to register an interrupt handler that will
* be called when a button is depressed or released. The ID value is one
* of the BUTTON* definitions provided above.
*
* Configuration Notes:
* Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the
* overall PORT IRQ feature and CONFIG_AVR32_PORTIRQSETA and/or
* CONFIG_AVR32_PORTIRQSETB must be enabled to select PORTs to support
* interrupts on. For button support, bits 2 and 3 must be set in
* CONFIG_AVR32_PORTIRQSETB (PB2 and PB3).
*
****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{
int ret = -EINVAL;
if (id == BUTTON_SW0)
{
irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the
* following operations are atomic.
*/
flags = enter_critical_section();
/* Configure the interrupt */
sam_portirq(IRQ_SW0);
irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0);
leave_critical_section(flags);
ret = OK;
}
/* Return the old button handler (so that it can be restored) */
return ret;
}
#endif
#endif /* CONFIG_ARCH_BUTTONS */

View File

@ -0,0 +1,114 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_mmcsd.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h>
#include "sam_config.h"
#include "sam_spi.h"
#include "saml21-xplained.h"
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y)
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error SERCOM0 SPI support is required
#endif
#ifndef CONFIG_MMCSD
# error MMC/SD support is required (CONFIG_MMCSD)
#endif
#define SAMD2L2_MMCSDSLOTNO 0 /* There is only one slot */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card. Requires
* - CONFIG_SAML21_XPLAINED_IOMODULE=y,
* - CONFIG_DISABLE_MOUNTPOINT=n,
* - CONFIG_MMCSD=y, and
* - SAMD2L2_HAVE_SPI0=y
* (CONFIG_SAMD2L2_SERCOM0 && CONFIG_SAMD2L2_SERCOM0_ISSPI)
*
****************************************************************************/
int sam_sdinitialize(int port, int minor)
{
FAR struct spi_dev_s *spi;
int ret;
/* Get the SPI driver instance for the SD chip select */
finfo("Initializing SERCOM SPI%d\n", port);
spi = sam_spibus_initialize(port);
if (!spi)
{
ferr("ERROR: Failed to initialize SPI%d\n", port);
return -ENODEV;
}
finfo("Successfully initialized SPI%d\n", port);
/* Bind the SPI device for the chip select to the slot */
finfo("Binding SPI%d to MMC/SD slot %d\n", port, SAMD2L2_MMCSDSLOTNO);
ret = mmcsd_spislotinitialize(minor, SAMD2L2_MMCSDSLOTNO, spi);
if (ret < 0)
{
ferr("ERROR: Failed to bind SPI%d to MMC/SD slot %d: %d\n",
port, SAMD2L2_MMCSDSLOTNO, ret);
return ret;
}
finfo("Successfully bound SPI%d to MMC/SD slot %d\n",
port, SAMD2L2_MMCSDSLOTNO);
return OK;
}
#endif /* CONFIG_SAML21_XPLAINED_IOMODULE */

View File

@ -0,0 +1,406 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_spi.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/spi.h>
#include "sam_config.h"
#include "sam_port.h"
#include "sam_spi.h"
#include "saml21-xplained.h"
#ifdef SAMD2L2_HAVE_SPI
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAML21 Xplained
* Pro board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void)
{
/* The I/O module containing the SD connector may or may not be installed.
* And, if it is installed, it may be in connector EXT1 or EXT2.
*/
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE
/* TODO: enable interrupt on card detect */
sam_configport(PORT_SD_CD); /* Card detect input */
sam_configport(PORT_SD_CS); /* Chip select output */
#endif
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE
sam_configport(PORT_OLED_DATA); /* Command/data */
sam_configport(PORT_OLED_CS); /* Card detect input */
#endif
}
/****************************************************************************
* Name: sam_spi[n]select, sam_spi[n]status, and sam_spi[n]cmddata
*
* Description:
* These external functions must be provided by board-specific logic. They
* include:
*
* o sam_spi[n]select is a functions to manage the board-specific chip
* selects
* o sam_spi[n]status and sam_spi[n]cmddata: Implementations of the status
* and cmddata methods of the SPI interface defined by struct spi_ops_
* (see include/nuttx/spi/spi.h). All other methods including
* sam_spibus_initialize()) are provided by common SAMD/L logic.
*
* Where [n] is the SERCOM number for the SPI module.
*
* To use this common SPI logic on your board:
*
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide sam_spi[n]select() and sam_spi[n]status() functions in your
* board-specific logic. These functions will perform chip selection
* and status operations using GPIOs in the way your board is
* configured.
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
* sam_spi[n]cmddata() functions in your board-specific logic. This
* function will perform cmd/data selection operations using GPIOs in
* the way your board is configured.
* 3. Add a call to sam_spibus_initialize() in your low level application
* initialization logic
* 4. The handle returned by sam_spibus_initialize() may then be used to
* bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
/****************************************************************************
* Name: sam_spi[n]select
*
* Description:
* PIO chip select pins may be programmed by the board specific logic in
* one of two different ways. First, the pins may be programmed as SPI
* peripherals. In that case, the pins are completely controlled by the
* SPI driver. This method still needs to be provided, but it may be only
* a stub.
*
* An alternative way to program the PIO chip select pins is as a normal
* GPIO output. In that case, the automatic control of the CS pins is
* bypassed and this function must provide control of the chip select.
* NOTE: In this case, the GPIO output pin does *not* have to be the
* same as the NPCS pin normal associated with the chip select number.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
* selected - TRUE:Select the device, FALSE:De-select the device
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
void sam_spi0select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT1
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT1
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
void sam_spi1select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT2
/* Select/de-select the SD card */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
sam_portwrite(PORT_SD_CS, !selected);
}
#endif
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2
/* Select/de-select the OLED */
if (devid == SPIDEV_DISPLAY(0))
{
/* Active low */
sam_portwrite(PORT_OLED_CS, !selected);
}
#endif
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
void sam_spi2select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
void sam_spi3select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
void sam_spi4select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
void sam_spi5select(FAR struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
#endif
/****************************************************************************
* Name: sam_spi[n]status
*
* Description:
* Return status information associated with the SPI device.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
*
****************************************************************************/
#ifdef SAMD2L2_HAVE_SPI0
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT1
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
uint8_t sam_spi1status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE_EXT2
/* Check if an SD card is present in the microSD slot */
if (devid == SPIDEV_MMCSD(0))
{
/* Active low */
if (!sam_portread(PORT_SD_CD))
{
ret |= SPI_STATUS_PRESENT;
}
}
#endif
return ret;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
uint8_t sam_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
uint8_t sam_spi3status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
uint8_t sam_spi4status(FAR struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
uint8_t sam_spi5status(FAR struct spi_dev_s *dev, uint32_t devid)
{
uint8_t ret = 0;
return ret;
}
#endif
/****************************************************************************
* Name: sam_spi[n]cmddata
*
* Description:
* Some SPI devices require an additional control to determine if the SPI
* data being sent is a command or is data. If CONFIG_SPI_CMDDATA then
* this function will be called to different be command and data transfers.
*
* This is often needed, for example, by LCD drivers. Some LCD hardware
* may be configured to use 9-bit data transfers with the 9th bit
* indicating command or data. That same hardware may be configurable,
* instead, to use 8-bit data but to require an additional, board-
* specific GPIO control to distinguish command and data. This function
* would be needed in that latter case.
*
* Input Parameters:
* dev - SPI device info
* devid - Identifies the (logical) device
*
* Returned Value:
* Zero on success; a negated errno on failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA
#ifdef SAMD2L2_HAVE_SPI0
int sam_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT1
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI1
int sam_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*
* High: the inputs are treated as display data.
* Low: the inputs are transferred to the command registers.
*/
sam_portwrite(PORT_OLED_DATA, !cmd);
}
#endif
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI2
int sam_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI3
int sam_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI4
int sam_spi4cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#ifdef SAMD2L2_HAVE_SPI5
int sam_spi5cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
return OK;
}
#endif
#endif /* CONFIG_SPI_CMDDATA */
#endif /* SAMD2L2_HAVE_SPI */

View File

@ -0,0 +1,191 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_ug2832hsweg04.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* OLED1 Connector:
*
* OLED1 CONNECTOR
* ----------------- ---------------------- ----------------------
* OLED1 EXT1 EXT2
* ----------------- ---------------------- ----------------------
* 1 ID 1 1
* ----------------- ---------------------- ----------------------
* 2 GND 2 GND 2 GND
* ----------------- ---------------------- ----------------------
* 3 BUTTON2 3 PB00 AIN[8] 3 PA10 AIN[18]
* ----------------- ---------------------- ----------------------
* 4 BUTTON3 4 PB01 AIN[9] 4 PA11 AIN[19]
* ----------------- ---------------------- ----------------------
* 5 DATA_CMD_SEL 5 PB06 PORT 5 PA20 PORT
* ----------------- ---------------------- ----------------------
* 6 LED3 6 PB07 PORT 6 PA21 PORT
* ----------------- ---------------------- ----------------------
* 7 LED1 7 PB02 TC6/WO[0] 7 PA22 TC4/WO[0]
* ----------------- ---------------------- ----------------------
* 8 LED2 8 PB03 TC6/WO[1] 8 PA23 TC4/WO[1]
* ----------------- ---------------------- ----------------------
* 9 BUTTON1 9 PB04 EXTINT[4] 9 PB14 EXTINT[14]
* ----------------- ---------------------- ----------------------
* 10 DISPLAY_RESET 10 PB05 PORT 10 PB15 PORT
* ----------------- ---------------------- ----------------------
* 11 N/C 11 PA08 SERCOM2 PAD[0] 11 PA08 SERCOM2 PAD[0]
* I²C SDA I²C SDA
* ----------------- ---------------------- ----------------------
* 12 N/C 12 PA09 SERCOM2 PAD[1] 12 PA09 SERCOM2 PAD[1]
* I²C SCL I²C SCL
* ----------------- ---------------------- ----------------------
* 13 N/C 13 PB09 SERCOM4 PAD[1] 13 PB13 SERCOM4 PAD[1]
* USART RX USART RX
* ----------------- ---------------------- ----------------------
* 14 N/C 14 PB08 SERCOM4 PAD[0] 14 PB12 SERCOM4 PAD[0]
* USART TX USART TX
* ----------------- ---------------------- ----------------------
* 15 DISPLAY_SS 15 PA05 SERCOM0 PAD[1] 15 PA17 SERCOM1 PAD[1]
* SPI SS SPI SS
* ----------------- ---------------------- ----------------------
* 16 SPI_MOSI 16 PA06 SERCOM0 PAD[2] 16 PA18 SERCOM1 PAD[2]
* SPI MOSI SPI MOSI
* ----------------- ---------------------- ----------------------
* 17 N/C 17 PA04 SERCOM0 PAD[0] 17 PA16 SERCOM1 PAD[0]
* SPI MISO SPI MISO
* ----------------- ---------------------- ----------------------
* 18 SPI_SCK 18 PA07 SERCOM0 PAD[3] 18 PA19 SERCOM1 PAD[3]
* SPI SCK SPI SCK
* ----------------- ---------------------- ----------------------
* 19 GND 19 GND GND
* ----------------- ---------------------- ----------------------
* 20 VCC 20 VCC VCC
* ----------------- ---------------------- ----------------------
*
* OLED1 signals
*
* DATA_CMD_SEL - Data/command select. Used to choose whether the
* communication is data to the display memory or a command to the LCD
* controller. High = data, low = command
* DISPLAY_RESET - Reset signal to the OLED display, active low. Used during
* initialization of the display.
* DISPLAY_SS - SPI slave select signal, must be held low during SPI
* communication.
* SPI_MOSI - SPI master out, slave in signal. Used to write data to the
* display
* SPI_SCK SPI - clock signal, generated by the master.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
#include "sam_port.h"
#include "sam_spi.h"
#include "saml21-xplained.h"
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* The pin configurations here require that SPI1 is selected */
#ifndef CONFIG_LCD_SSD1306
# error "The OLED driver requires CONFIG_LCD_SSD1306 in the configuration"
#endif
#ifndef CONFIG_LCD_UG2832HSWEG04
# error "The OLED driver requires CONFIG_LCD_UG2832HSWEG04 in the configuration"
#endif
#ifndef SAMD2L2_HAVE_SPI0
# error "The OLED driver requires SAMD2L2_HAVE_SPI0 in the configuration"
#endif
#ifndef CONFIG_SPI_CMDDATA
# error "The OLED driver requires CONFIG_SPI_CMDDATA in the configuration"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_graphics_setup
*
* Description:
* Called by NX initialization logic to configure the OLED.
*
****************************************************************************/
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
{
FAR struct spi_dev_s *spi;
FAR struct lcd_dev_s *dev;
/* Configure the OLED PORTs. This initial configuration is RESET low,
* putting the OLED into reset state.
*/
sam_configport(PORT_OLED_RST);
/* Wait a bit then release the OLED from the reset state */
up_mdelay(20);
sam_portwrite(PORT_OLED_RST, true);
/* Get the SPI1 port interface */
spi = sam_spibus_initialize(OLED_CSNO);
if (!spi)
{
lcderr("ERROR: Failed to initialize SPI port 1\n");
}
else
{
/* Bind the SPI port to the OLED */
dev = ssd1306_initialize(spi, NULL, devno);
if (!dev)
{
lcderr("ERROR: Failed to bind SPI port 1 to OLED %d\n", devno);
}
else
{
lcdinfo("Bound SPI port 1 to OLED %d\n", devno);
/* And turn the OLED on */
dev->setpower(dev, CONFIG_LCD_MAXPOWER);
return dev;
}
}
return NULL;
}
#endif /* CONFIG_SAML21_XPLAINED_OLED1MODULE */

View File

@ -0,0 +1,108 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/sam_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* There are three LEDs on board the SAML21 Xplained Pro board: The EDBG
* controls two of the LEDs, a power LED and a status LED. There is only
* one user controllable LED, a yellow LED labeled STATUS near the SAML21 USB
* connector.
*
* This LED is controlled by PB10 and the LED can be activated by driving
* PB10 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED.
* Otherwise, the LED can be controlled from user applications using the
* logic in this file.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <arch/board/board.h>
#include "sam_port.h"
#include "saml21-xplained.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the
* board_userled_initialize() is available to initialize the LED from user
* application logic.
*
****************************************************************************/
uint32_t board_userled_initialize(void)
{
sam_configport(PORT_STATUS_LED);
return BOARD_NLEDS;
}
/****************************************************************************
* Name: board_userled
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs. If CONFIG_ARCH_LEDS is not defined, then the board_userled() is
* available to control the LED from user application logic.
*
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_STATUS_LED)
{
sam_portwrite(PORT_STATUS_LED, !ledon);
}
}
/****************************************************************************
* Name: board_userled_all
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
* LEDs.
* If CONFIG_ARCH_LEDS is not defined, then the board_userled_all() is
* available to control the LED from user application logic. NOTE: since
* there is only a single LED on-board, this is function isn't very useful.
*
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
board_userled(BOARD_STATUS_LED, (ledset & BOARD_STATUS_LED_BIT) != 0);
}
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,254 @@
/****************************************************************************
* boards/arm/samd2l2/saml21-xplained/src/saml21-xplained.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_SRC_SAML21_XPLAINED_H
#define __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_SRC_SAML21_XPLAINED_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <arch/irq.h>
#include <nuttx/irq.h>
#include "sam_config.h"
#include "sam_pinmap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* LEDs: There are three LEDs on board the SAML21 Xplained Pro board:
* The EDBG controls two of the LEDs, a power LED and a status LED.
* There is only one user controllable LED, a yellow LED labelled STATIS
* near the SAML21 USB connector.
*
* This LED is controlled by PB10 and the LED can be activated by driving
* PB10 to GND.
*
* When CONFIG_ARCH_LEDS is defined in the NuttX configuration, NuttX will
* control the LED as follows:
*
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus if the LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If the LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
#define PORT_STATUS_LED (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTB | PORT_PIN10)
/* Mechanical buttons:
*
* The SAML21 Xplained Pro contains two mechanical buttons. One button is the
* RESET button connected to the SAML21 reset line and the other is a generic
* user configurable button.
* When a button is pressed it will drive the I/O line to GND.
*
* PA02 SW0
*/
#define PORT_SW0 (PORT_INTERRUPT | PORT_PULL_UP | PORTA | PORT_PIN2)
#define IRQ_SW0 SAM_IRQ_PA2
/* I/O1
*
* Support for the microSD card slot on the I/O1 module. The I/O1 requires
* SPI support and two PORTs. These the PORTs will vary if the I/O1
* is installed on the EXT1 or EXT2 connector:
*
* --- ------------------ ---------------------- --------------------------
* PIN EXT1 EXT2 Description
* --- ------------------ ---------------------- --------------------------
* 15 PA05 SERCOM0 PAD[1] 15 PA17 GPIO] Active low chip select
* SPI SS OUTPUT, pulled high on
* board.
* 10 PA02 GPIO 10 PB15 GPIO Active low card detect
* INPUT, must use internal
* pull-up.
* --- ------------------ ---------------------- --------------------------
*/
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the I/O1 module
# endif
# if defined(CONFIG_SAML21_XPLAINED_IOMODULE_EXT1)
# if defined(CONFIG_SAML21_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT1)
# error I/O1 and OLED1 modules cannot both reside in EXT1
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTA | PORT_PIN2)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAML21_XPLAINED_IOMODULE_EXT2)
# if defined(CONFIG_SAML21_XPLAINED_OLED1MODULE) && \
defined(CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2)
# error I/O1 and OLED1 modules cannot both reside in EXT2
# endif
# define PORT_SD_CD (PORT_INTERRUPT | PORT_INT_CHANGE | PORT_PULL_UP | \
PORTB | PORT_PIN15)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the I/O1 module installed in?
# endif
#endif
/* OLED1
*
* Support for the microSD card slot on the I/O1 module.
* The I/O1 requires SPI support and three output PORTs.
* These the PORTs will vary if the OLED1 is installed on the EXT1
* or EXT2 connector:
*
* --- ------------------- -------------------- ---------------------------
* PIN EXT1 EXT2 Description
* --- ------------------- -------------------- ---------------------------
* 5 PB06 PA02 PA20 PA02 DATA_CMD_SEL
* 10 PA02 PA02 PB15 PA02 DISPLAY_RESET. Active low.
* 15 PA05 SERCOM0 PAD[1] PA17 SERCOM1 PAD[1] DISPLAY_SS. Active low.
* SPI SS SPI SS
* --- ------------------- -------------------- ---------------------------
*/
#ifdef CONFIG_SAML21_XPLAINED_OLED1MODULE
# ifndef SAMD2L2_HAVE_SPI0
# error SAMD2L2_HAVE_SPI0 is required to use the OLED1 module
# endif
# ifndef CONFIG_SPI_CMDDATA
# error CONFIG_SPI_CMDDATA is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_SSD1306
# error CONFIG_LCD_SSD1306 is required to use the OLED1 module
# endif
# ifndef CONFIG_LCD_UG2832HSWEG04
# error CONFIG_LCD_UG2832HSWEG04 is required to use the OLED1 module
# endif
# if defined(CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT1)
# if defined(CONFIG_SAML21_XPLAINED_IOMODULE) && \
defined(CONFIG_SAML21_XPLAINED_IOMODULE_EXT1)
# error OLED1 and I/O1 modules cannot both reside in EXT1
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN6)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTA | PORT_PIN2)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN5)
# elif defined(CONFIG_SAML21_XPLAINED_OLED1MODULE_EXT2)
# if defined(CONFIG_SAML21_XPLAINED_IOMODULE) && \
defined(CONFIG_SAML21_XPLAINED_IOMODULE_EXT2)
# error OLED1 and I/O1 modules cannot both reside in EXT2
# endif
# define PORT_OLED_DATA (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTA | PORT_PIN20)
# define PORT_OLED_RST (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_CLEAR | \
PORTB | PORT_PIN15)
# define PORT_OLED_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTA | PORT_PIN17)
# else
# error Which connector is the OLED1 module installed in?
# endif
#endif
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
# define PORT_SD_CS (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | \
PORTB | PORT_PIN11) /* REVISIT */
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: sam_spidev_initialize
*
* Description:
* Called to configure SPI chip select PORT pins for the SAM3U-EK board.
*
****************************************************************************/
void weak_function sam_spidev_initialize(void);
/****************************************************************************
* Name: sam_sdinitialize
*
* Description:
* Initialize the SPI-based SD card.
* Requires CONFIG_SAML21_XPLAINED_IOMODULE=y,
* CONFIG_DISABLE_MOUNTPOINT=n, CONFIG_MMCSD=y,
* and the appropriate SERCOM SPI port enabled.
*
****************************************************************************/
#ifdef CONFIG_SAML21_XPLAINED_IOMODULE
int sam_sdinitialize(int port, int minor);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_SAMD2L2_SAML21_XPLAINED_SRC_SAML21_XPLAINED_H */

View File

@ -0,0 +1,108 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_METRO_M4
choice
prompt "Execution memory"
default METRO_M4_RUNFROMFLASH
config METRO_M4_RUNFROMFLASH
bool "Run from FLASH"
select BOOT_RUNFROMFLASH
---help---
This is the normal configuration for building METRO M4 code.
config METRO_M4_RUNFROMSRAM
bool "Run from SRAM"
select BOOT_RUNFROMISRAM
---help---
During early bring-up, it is safer to execute entirely from
SRAM until you are confident in the initialization logic.
Then you can safely switch to FLASH.
REVISIT: This auto-selects CONFIG_BOOT_RUNFROMISRAM but I have
found, with some difficulty, that that choice still defaults to
CONFIG_BOOT_RUNFROMFLASH, causing link-time failures when running
from SRAM.
endchoice # Execution memory
config METRO_M4_32KHZXTAL
bool "32.768 KHz XTAL"
default n
---help---
According to the schematic, a 32.768 KHz crystal is installed on
board. However, I have been unable to use this crystal and thought
perhaps it is missing or defective on my board (there is a metal
package that could be a crystal on board, but I am not certain).
Another, more likely option is that there is a coding error on my
part that prevents the 32.768 KHz crystal from usable(?)
The configuration defaults to using the always-on OSCULP32 as the
slow clock source. This option will select instead XOSC32 as the
slow clock source.
config METRO_M4_AT24_BLOCKMOUNT
bool "AT24 Serial EEPROM auto-mount"
default n
depends on MTD_AT24XX
---help---
Automatically initialize the AT24 I2C EEPROM driver when NSH starts.
choice
prompt "AT24 serial EPPROM configuration"
default METRO_M4_AT24_FTL
depends on METRO_M4_AT24_BLOCKMOUNT
config METRO_M4_AT24_FTL
bool "Create AT24 block driver"
---help---
Create the MTD driver for the AT24 and "wrap" the AT24 as a standard
block driver that could then, for example, be mounted using FAT or
any other file system. Any file system may be used, but there will
be no wear-leveling.
config METRO_M4_AT24_NXFFS
bool "Create AT24 NXFFS file system"
depends on FS_NXFFS
---help---
Create the MTD driver for the AT24 and mount the AT24 device as
a wear-leveling, NuttX FLASH file system (NXFFS). The downside of
NXFFS is that it can be very slow.
endchoice # AT24 serial EPPROM configuration
if FS_AUTOMOUNTER
config METRO_M4_USB_AUTOMOUNT
bool "USB automounter"
default n
if METRO_M4_USB_AUTOMOUNT
config METRO_M4_USB_AUTOMOUNT_FSTYPE
string "USB file system type"
default "vfat"
config METRO_M4_USB_AUTOMOUNT_BLKDEV
string "USB block device"
default "/dev/sda"
config METRO_M4_USB_AUTOMOUNT_MOUNTPOINT
string "USB mount point"
default "/mnt/usb"
config METRO_M4_USB_AUTOMOUNT_DDELAY
int "USB debounce delay (milliseconds)"
default 1000
config METRO_M4_USB_AUTOMOUNT_UDELAY
int "USB unmount retry delay (milliseconds)"
default 2000
endif # METRO_M4_USB_AUTOMOUNT
endif # FS_AUTOMOUNTER
endif # ARCH_BOARD_METRO_M4

View File

@ -0,0 +1,323 @@
README
======
This directory contains the port of NuttX to the Adafruit Metro M4. The
Metro M4 uses a Arduino form factor and and pinout. It's powered with an
ATSAMD51J19:
o Cortex M4 core running at 120 MHz
o Hardware DSP and floating point support
o 512 KB flash, 192 KB RAM
o 32-bit, 3.3V logic and power
o Dual 1 MSPS DAC (A0 and A1)
o Dual 1 MSPS ADC (8 analog pins)
o 6 x hardware SERCOM (I2C, SPI or UART)
o 16 x PWM outputs
o Stereo I2S input/output with MCK pin
o 10-bit Parallel capture controller (for camera/video in)
o Built in crypto engines with AES (256 bit), true RNG, Pubkey controller
o 64 QFN
Contents
========
o STATUS
o Unlocking FLASH
o Serial Console
o LEDs
o Run from SRAM
o Configurations
STATUS
======
2018-07-26: The basic port was merged into master. It is still
incomplete and untested.
2018-07-29: Code complete. Clock configuration complete. Unverified
SERCOM USART, SPI, I2C, Port configuration, and DMA support have been
added. I still have no hardware in hand to test.
2018-07-20: Brought in the USB driver from the SAML21. It is the same
USB IP with only small differences. There a a few, small open issues
still to be resolved.
2018-08-01: Hardware in hand. Initial attempts to program the board
using a Segger J-Link connected via SWD were unsuccessful because the
Metro M4 comes with an application in FLASH and the FLASH locked. See
"Unlocking FLASH with J-Link Commander" below. After unlocking the
FLASH, I was able to successfully write the NuttX image.
Unfortunately, the board seems to have become unusable after the first
NuttX image was written to FLASH. I am unable to connect the JTAG
debugger. The primary JTAG problem seems to be that it is now unable
to halt the CPU.
Future me: This boot-up failure was do to bad clock initialization
logic that caused infinite loops during clock configuration. Unlocking
and erasing the FLASH is innocuous, but the JTAG will apparently not
work if the clocks are not in a good state.
I would say that as a general practice, any changes to the clock
configuration should be testing in SRAM first before risking the
write to FLASH.
2018-08-03: Added a configuration option to run out of SRAM vs FLASH.
This is a safer way to do the initial board bring-up since it does
not modify the FLASH image nor does it require unlocking the FLASH
pages.
2018-08-31: I finally have a new Metro M4 and have successfully
debugged from SRAM (with FLASH unlocked and erased). Several
errors in clock configuration logic have been corrected and it now
gets through clock configuration okay. It now hangs in the low-level
USART initialization.
It hangs trying to enabled the SERCOM slow clock channel. The clock
sequence is:
1. 32.678KHz crystal -> XOSC32K
This is configured and says that XOSC32K is ready.
2. XOSCK32 -> GCLK3.
This is configured and it says that is is ready (GENEN=1).
3. GCLK3 ->SERCOM slow clock channel.
This hangs when I try to enable the peripheral clock.
2018-09-01: I found a workaround by substituting OSCULP32K for XOSC32
as the source to GCLK3. With that workaround, the port gets past all
clock and USART configuration. A new configuration option was added,
CONFIG_METRO_M4_32KHZXTAL. By default this workaround is in place.
But you can enable CONFIG_METRO_M4_32KHZXTAL if you want to further
study the XOSC32K problem.
With that workaround (and a bunch of other fixes), the basic NSH
configuration appears fully function, indicating the the board bring-
up is complete.
There are additional drivers ported from SAML21 which has, in most cases,
identical peripherals. None of these drivers have been verified on the
SAMD51, However. These include: DMAC, I2C, SPI, and USB.
WARNING: If you decide to invest the time to discover whey the XOSC32K
clock source is not working, be certain to use the SRAM configuration.
That configuration in FLASH is most likely lock up your board irrecoverably
is there are any start-up errors!
Unlocking FLASH
===============
Options
-------
The Adafruit Metro M4 comes with a very nice bootloader resident in FLASH.
so we have two options:
1. Learn to play well with others. Make NuttX coexist and work in the
memory partition available to it. Or,
2. Be greedy, unlock the FLASH and overwrite the bootloader.
I chose to do the last one. I used a Segger J-Link and here are the steps
that I took. You can probably do these things in Atmel Studio (?) but for
other debug environments, you would have to come up with the solution.
Unlocking FLASH with J-Link Commander
-------------------------------------
1. Start J-Link Commander:
SEGGER J-Link Commander V6.32i (Compiled Jul 24 2018 15:20:49)
DLL version V6.32i, compiled Jul 24 2018 15:19:55
Connecting to J-Link via USB...O.K.
Firmware: J-Link V9 compiled Apr 20 2018 16:47:26
Hardware version: V9.30
S/N: 269303123
License(s): FlashBP, GDB
OEM: SEGGER-EDU
VTref=3.296V
Type "connect" to establish a target connection, '?' for help
J-Link>con
Please specify device / core. <Default>: ATSAMD51P19
Type '?' for selection dialog
Device>ATSAMD51P19
Please specify target interface:
J) JTAG (Default)
S) SWD
TIF>S
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "ATSAMD51P19" selected.
Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Scanning AP map to find all available APs
...etc. ...
2. Look at The NVM "user page" memory at address 0x00804000:
J-Link>mem8 804000, 10
00804000 = 39 92 9A F6 80 FF EC AE FF FF FF FF FF FF FF FF
The field NVM BOOT (also called BOOTPROT) is the field that locks the
lower part of FLASH to support the boot loader. This is bits 26-29
of the NVM user page:
J-Link>mem32 804000, 1
00804000 = F69A9239
In binary 11|11 01|10 1001 1010 1001 0010 0011 1001, so NVM Boot 1101.
To unlock the FLASH memory reserved for the bootloader, we need to
change this field to 111 so that:
11|11 11|10 10|01 1010 1001 0010 0011 1001 = F7da9239, or
00804000 = 39 92 9A FE 80 FF EC AE FF FF FF FF FF FF FF FF
is read.
3. Modify the NVM "user page"
I did this using the instructions for the SAMD21 found at
https://roamingthings.de/use-j-link-to-change-the-boot-loader-protection-of-a-sam-d21/
We will need to create a small Motorola S-REC file to write new values
into NVM. See https://en.m.wikipedia.org/wiki/SREC_(file_format) for a
description of the Motorola SREC format.
I wrote a small program at boards/arm/samd5e5/metro-m4-scripts/nvm.c that will
generate this Motorola SREC file with the correct checksum. The file at
boards/arm/samd5e5/metro-m4-scripts/nvm.c is the output of that program.
J-Link>mem8 804000,10
00804000 = 39 92 9A F6 80 FF EC AE FF FF FF FF FF FF FF FF
J-Link>loadfile D:\Spuda\Documents\projects\nuttx\master\nuttx\boards\metro-m4\scripts\nvm.srec
Downloading file [D:\Spuda\Documents\projects\nuttx\master\nuttx\boards\metro-m4\scripts\nvm.srec]...
J-Link: Flash download: Bank 1 @ 0x00804000: 1 range affected (16 bytes)
J-Link: Flash download: Total time needed: 0.089s (Prepare: 0.035s, Compare: 0.011s, Erase: 0.000s, Program: 0.019s, Verify: 0.011s, Restore: 0.011s)
O.K.
J-Link>mem8 804000,10
00804000 = 39 92 9A FE 80 FF EC AE FF FF FF FF FF FF FF FF
You will, of course, have to change the path as appropriate for your system.
4. Erase FLASH (optional)
J-Link>erase
Erasing device (ATSAMD51P19)...
J-Link: Flash download: Total time needed: 2.596s (Prepare: 0.031s, Compare: 0.000s, Erase: 2.553s, Program: 0.000s, Verify: 0.000s, Restore: 0.012s)
J-Link: Flash download: Total time needed: 0.066s (Prepare: 0.038s, Compare: 0.000s, Erase: 0.016s, Program: 0.000s, Verify: 0.000s, Restore: 0.010s)
Erasing done.
J-Link>
Serial Console
==============
An Arduino compatible serial Shield is assumed (or equivalently, and
external RS-232 or serial-to-USB adapter connected on Arduino pins D0 and
D1):
------ ----------------- -----------
SHIELD SAMD5E5 FUNCTION
------ ----------------- -----------
D0 PA23 SERCOM3 PAD2 RXD
D1 PA22 SERCOM3 PAD0 TXD
LEDs
====
The Adafruit Metro M4 has four LEDs, but only two are controllable by software:
1. The red LED on the Arduino D13 pin, and
2. A NeoPixel RGB LED.
Currently, only the red LED is supported.
------ ----------------- -----------
SHIELD SAMD5E5 FUNCTION
------ ----------------- -----------
D13 PA16 GPIO output
Run from SRAM
=============
I bricked my first Metro M4 board because there were problems in the
bring-up logic. These problems left the chip in a bad state that was
repeated on each reset because the code was written into FLASH and I was
unable to ever connect to it again via SWD.
To make the bring-up less risky, I added a configuration option to build
the code to execution entirely out of SRAM. By default, the setting
CONFIG_METRO_M4_RUNFROMFLASH=y is used and the code is built to run out of
FLASH. If CONFIG_METRO_M4_RUNFROMSRAM=y is selected instead, then the
code is built to run out of SRAM.
To use the code in this configuration, the program must be started a
little differently:
gdb> mon reset
gdb> mon halt
gdb> load nuttx << Load NuttX into SRAM
gdb> file nuttx << Assuming debug symbols are enabled
gdb> mon memu32 0x20000000 << Get the address of initial stack
gdb> mon reg sp 0x200161c4 << Set the initial stack pointer using this address
gdb> mon memu32 0x20000004 << Get the address of __start entry point
gdb> mon reg pc 0x20000264 << Set the PC using this address (without bit 0 set)
gdb> si << Step in just to make sure everything is okay
gdb> [ set breakpoints ]
gdb> c << Then continue until you hit a breakpoint
Where 0x200161c4 and 0x20000264 are the values of the initial stack and
the __start entry point that I read from SRAM
Configurations
==============
Each Adafruit Metro M4 configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh [OPTIONS] metro-m4:<subdir>
Do 'tools/configure.sh -h' for the list of options. If you are building
under Windows with Cygwin, you would need the -c option, for example.
Before building, make sure that the PATH environmental variable includes the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of configurations listed in the following paragraph.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output of on SERCOM3 which is available on a Arduino Serial
Shield (see the section "Serial Console" above).
3. Unless otherwise stated, the configurations are setup build under
Linux with a generic ARM EABI toolchain:
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES ;for
common configuration above and the following:
NOTES:
1. The CMCC (Cortex M Cache Controller) is enabled.

View File

@ -0,0 +1,47 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="metro-m4"
CONFIG_ARCH_BOARD_METRO_M4=y
CONFIG_ARCH_CHIP="samd5e5"
CONFIG_ARCH_CHIP_SAMD51J19=y
CONFIG_ARCH_CHIP_SAMD5X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=7225
CONFIG_BUILTIN=y
CONFIG_DISABLE_ENVIRON=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=196608
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMD5E5_CMCC=y
CONFIG_SAMD5E5_EIC=y
CONFIG_SAMD5E5_SERCOM3=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=23
CONFIG_START_MONTH=7
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,487 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD5E5_METRO_M4_INCLUDE_BOARD_H
#define __BOARDS_ARM_SAMD5E5_METRO_M4_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
/* Clocking *****************************************************************/
/* Overview
*
* Per the schematic Adafruit Metro M4 Pro has one on-board crystal:
*
* X4 32.768KHz XOSC32
*
* However, I have been unsuccessful using it and have fallen back to using
* OSCULP32K(Unless CONFIG_METRO_M4_32KHZXTAL=y)
*
* Since there is no high speed crystal, we will run from the OSC16M clock
* source.
*
* OSC48M Output = 48Mhz
* |
* FDLL Input = 48MHz
* | Output = 48MHz
* GCLK5 Input = 48MHz
* | Output = 2MHz
* DPLL0 Input = 2MHz
* | Output = 120MHz
* GCLK0 Input = 120MHz
* | Output = 120MHz
* MCK Input = 120MHz
* | Output = 120MHz
* CPU Input = 120MHz
*/
#define BOARD_OSC32K_FREQUENCY 32768 /* OSCULP32K frequency 32.768 KHz (nominal) */
#define BOARD_XOSC32K_FREQUENCY 32768 /* XOSC32K frequency 32.768 KHz */
#define BOARD_DFLL_FREQUENCY 48000000 /* FDLL frequency 28MHz */
#define BOARD_XOSC0_FREQUENCY 12000000 /* XOSC0 frequency 12MHz (disabled) */
#define BOARD_XOSC1_FREQUENCY 12000000 /* XOSC0 frequency 12MHz (disabled)*/
#define BOARD_DPLL0_FREQUENCY 120000000 /* DPLL0 output frueuency (120MHz) */
#define BOARD_DPLL1_FREQUENCY 47985664 /* DPLL1 output frequency (disabled) */
#define BOARD_GCLK0_FREQUENCY BOARD_DPLL0_FREQUENCY
#define BOARD_GCLK1_FREQUENCY BOARD_DFLL_FREQUENCY
#define BOARD_GCLK2_FREQUENCY (BOARD_XOSC32K_FREQUENCY / 4) /* Disabled */
#ifdef CONFIG_METRO_M4_32KHZXTAL
# define BOARD_GCLK3_FREQUENCY BOARD_XOSC32K_FREQUENCY /* Enabled */
#else
# define BOARD_GCLK3_FREQUENCY BOARD_OSC32K_FREQUENCY /* Always-on */
#endif
#define BOARD_GCLK4_FREQUENCY BOARD_DPLL0_FREQUENCY
#define BOARD_GCLK5_FREQUENCY (BOARD_DFLL_FREQUENCY / 24)
#define BOARD_GCLK6_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_GCLK7_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_GCLK8_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_GCLK9_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_GCLK10_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_GCLK11_FREQUENCY BOARD_XOSC1_FREQUENCY /* Disabled */
#define BOARD_CPU_FREQUENCY BOARD_GCLK0_FREQUENCY /* CPU frequency 120MHz */
/* XOSC32 */
#ifdef CONFIG_METRO_M4_32KHZXTAL
# define BOARD_HAVE_XOSC32K 1 /* 32.768 KHz XOSC32 crystal installed */
# define BOARD_XOSC32K_ENABLE TRUE /* Enable XOSC32 */
#else
# define BOARD_HAVE_XOSC32K 0 /* No 32.768 KHz XOSC32 crystal installed */
# define BOARD_XOSC32K_ENABLE FALSE /* Disable XOSC32 */
#endif
#define BOARD_XOSC32K_XTALEN TRUE /* Crystal connected on XIN32 */
#define BOARD_XOSC32K_EN32K FALSE /* No 32KHz output */
#define BOARD_XOSC32K_EN1K FALSE /* No 1KHz output */
#define BOARD_XOSC32K_HIGHSPEED TRUE /* High speed mode */
#define BOARD_XOSC32K_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_XOSC32K_ONDEMAND TRUE /* Enable on-demand control */
#define BOARD_XOSC32K_CFDEN FALSE /* Clock failure detector not enabled */
#define BOARD_XOSC32K_CFDEO FALSE /* No clock failure event */
#define BOARD_XOSC32K_CALIBEN FALSE /* No OSCULP32K calibration */
#define BOARD_XOSC32K_STARTUP 0 /* Startup time: 62592us */
#define BOARD_XOSC32K_CALIB 0 /* Dummy OSCULP32K calibration value */
#define BOARD_XOSC32K_RTCSEL 0 /* RTC clock = ULP1K */
/* XOSC0 */
#define BOARD_HAVE_XOSC0 0 /* No XOSC0 clock/crystal installed */
#define BOARD_XOSC0_ENABLE FALSE /* Don't enable XOSC0 */
#define BOARD_XOSC0_XTALEN FALSE /* External clock connected */
#define BOARD_XOSC0_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_XOSC0_ONDEMAND TRUE /* Disable on-demand control */
#define BOARD_XOSC0_LOWGAIN FALSE /* Disable low buffer gain */
#define BOARD_XOSC0_ENALC FALSE /* Disable automatic loop control */
#define BOARD_XOSC0_CFDEN FALSE /* Clock failure detector not enabled */
#define BOARD_XOSC0_SWBEN FALSE /* XOSC clock switch not enabled */
#define BOARD_XOSC0_STARTUP 0 /* XOSC0 start-up time 31µs */
/* XOSC1 */
#define BOARD_HAVE_XOSC1 0 /* No XOSC0 clock/crystal installed */
#define BOARD_XOSC1_ENABLE FALSE /* Don't enable XOSC1 */
#define BOARD_XOSC1_XTALEN TRUE /* External crystal connected */
#define BOARD_XOSC1_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_XOSC1_ONDEMAND TRUE /* Disable on-demand control */
#define BOARD_XOSC1_LOWGAIN FALSE /* Disable low buffer gain */
#define BOARD_XOSC1_ENALC FALSE /* Disable automatic loop control */
#define BOARD_XOSC1_CFDEN FALSE /* Clock failure detector not enabled */
#define BOARD_XOSC1_SWBEN FALSE /* XOSC clock switch not enabled */
#define BOARD_XOSC1_STARTUP 0 /* XOSC0 start-up time 31µs */
/* GCLK */
#define BOARD_GCLK_SET1 0x0020 /* Pre-configure: GCLK5 needed by DPLL0 */
#define BOARD_GCLK_SET2 0x0fdf /* Post-configure: All GCLKs except GCLK5 */
#define BOARD_GCLK0_ENABLE TRUE /* Enable GCLK0 */
#define BOARD_GCLK0_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK0_OE TRUE /* Generate output on GCLK_IO */
#define BOARD_GCLK0_DIVSEL 0 /* GCLK frequency is source/DIV */
#define BOARD_GCLK0_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK0_SOURCE 7 /* Select DPLL0 output as GCLK0 source */
#define BOARD_GCLK0_DIV 1 /* Division factor */
#define BOARD_GCLK1_ENABLE TRUE /* Enable GCLK1 */
#define BOARD_GCLK1_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK1_OE TRUE /* Generate output on GCLK_IO */
#define BOARD_GCLK1_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK1_SOURCE 6 /* Select DFLL output as GCLK1 source */
#define BOARD_GCLK1_DIV 1 /* Division factor */
#define BOARD_GCLK2_ENABLE FALSE /* Don't enable GCLK2 */
#define BOARD_GCLK2_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK2_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK2_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK2_SOURCE 1 /* Select XOSC1 as GCLK2 source */
#define BOARD_GCLK2_DIV 1 /* Division factor */
#define BOARD_GCLK3_ENABLE TRUE /* Enable GCLK3 */
#define BOARD_GCLK3_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK3_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK3_RUNSTDBY FALSE /* Don't run in standby */
#ifdef CONFIG_METRO_M4_32KHZXTAL
# define BOARD_GCLK3_SOURCE 5 /* Select XOSC32K as GCLK3 source */
#else
# define BOARD_GCLK3_SOURCE 4 /* Select OSCULP32K as GCLK3 source */
#endif
#define BOARD_GCLK3_DIV 1 /* Division factor */
#define BOARD_GCLK4_ENABLE TRUE /* Enable GCLK4 */
#define BOARD_GCLK4_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK4_OE TRUE /* Generate output on GCLK_IO */
#define BOARD_GCLK4_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK4_SOURCE 7 /* Select DPLL0 output as GCLK4 source */
#define BOARD_GCLK4_DIV 1 /* Division factor */
#define BOARD_GCLK5_ENABLE TRUE /* Enable GCLK5 */
#define BOARD_GCLK5_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK5_OE TRUE /* Generate output on GCLK_IO */
#define BOARD_GCLK5_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK5_SOURCE 6 /* Select DFLL output as GCLK5 source */
#define BOARD_GCLK5_DIV 24 /* Division factor */
#define BOARD_GCLK6_ENABLE FALSE /* Don't enable GCLK6 */
#define BOARD_GCLK6_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK6_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK6_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK6_SOURCE 1 /* Select XOSC1 as GCLK6 source */
#define BOARD_GCLK6_DIV 1 /* Division factor */
#define BOARD_GCLK7_ENABLE FALSE /* Don't enable GCLK7 */
#define BOARD_GCLK7_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK7_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK7_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK7_SOURCE 1 /* Select XOSC1 as GCLK7 source */
#define BOARD_GCLK7_DIV 1 /* Division factor */
#define BOARD_GCLK8_ENABLE FALSE /* Don't enable GCLK8 */
#define BOARD_GCLK8_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK8_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK8_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK8_SOURCE 1 /* Select XOSC1 as GCLK8 source */
#define BOARD_GCLK8_DIV 1 /* Division factor */
#define BOARD_GCLK9_ENABLE FALSE /* Don't enable GCLK9 */
#define BOARD_GCLK9_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK9_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK9_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK9_SOURCE 1 /* Select XOSC1 as GCLK9 source */
#define BOARD_GCLK9_DIV 1 /* Division factor */
#define BOARD_GCLK10_ENABLE FALSE /* Don't enable GCLK10 */
#define BOARD_GCLK10_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK10_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK10_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK10_SOURCE 1 /* Select XOSC1 as GCLK10 source */
#define BOARD_GCLK10_DIV 1 /* Division factor */
#define BOARD_GCLK11_ENABLE FALSE /* Don't enable GCLK11 */
#define BOARD_GCLK11_OOV FALSE /* Clock output will be LOW */
#define BOARD_GCLK11_OE FALSE /* No generator output of GCLK_IO */
#define BOARD_GCLK11_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_GCLK11_SOURCE 1 /* Select XOSC1 as GCLK11 source */
#define BOARD_GCLK11_DIV 1 /* Division factor */
#define BOARD_GCLK11_FREQUENCY BOARD_XOSC1_FREQUENCY
/* DFLL */
#define BOARD_DFLL_ENABLE TRUE /* DFLL enable */
#define BOARD_DFLL_RUNSTDBY FALSE /* Don't run in standby */
#define BOARD_DFLL_ONDEMAND FALSE /* No n-demand control */
#define BOARD_DFLL_MODE FALSE /* TRUE->48MHz! Closed mode! */
#define BOARD_DFLL_STABLE FALSE /* No stable DFLL frequency */
#define BOARD_DFLL_LLAW FALSE /* Don't ose lock after wake */
#define BOARD_DFLL_USBCRM FALSE /* Use USB clock recovery mode */
#define BOARD_DFLL_CCDIS FALSE /* Chill cycle disable */
#define BOARD_DFLL_QLDIS FALSE /* No Quick Lock Disable */
#define BOARD_DFLL_BPLCKC FALSE /* No bypass coarse clock */
#define BOARD_DFLL_WAITLOCK TRUE /* Wait lock */
#define BOARD_DFLL_CALIBEN FALSE /* Don't overwrite factory calibration */
#define BOARD_DFLL_GCLKLOCK FALSE /* Don't lock the GCLK source */
#define BOARD_DFLL_FCALIB 128 /* Coarse calibration value (if caliben) */
#define BOARD_DFLL_CCALIB (31 / 4) /* Fine calibration value (if caliben) */
#define BOARD_DFLL_FSTEP 1 /* Fine maximum step */
#define BOARD_DFLL_CSTEP 1 /* Coarse maximum step */
#define BOARD_DFLL_GCLK 3 /* Generic clock generator 3 output: OSCULP32K / GCLK source (if !usbcrm || !mode) */
#if (BOARD_DFLL_MODE == TRUE) && (BOARD_DFLL_USBCRM == TRUE)
#define BOARD_DFLL_MUL 0xBB80 /* 48MHz/1KHz DFLL multiply factor */
#else
#define BOARD_DFLL_MUL 1465 /* 1464(3)=48MHz/32768 4915(2) DFLL multiply factor */
#endif
/* DPLL0/1
*
* Fckr is the frequency of the selected reference clock reference:
*
* BOARD_XOSC32K_FREQENCY,
* BOARD_XOSCn_FREQUENCY / DIV, or
* BOARD_GCLKn_FREQUENCY
*
* The DPLL output frequency is then given by:
*
* Fdpll = Fckr * (LDR + 1 + LDRFRAC / 32)
*
* DPLL0:
* Fckr = BOARD_GCLK5_FREQUENCY = BOARD_DFLL_FREQUENCY / 24 = 2MHz
* Fdpll = 2Mhz * (59 + 1 + 0 / 32) = 120MHz
*
* DPLL1: (not enabled)
* Fckr = BOARD_XOSCK32_FREQUENCY = 32.768KHz
* Fdpll = 32768 * (1463 + 1 + 13/32) = 47.986 MHz
*/
#define BOARD_DPLL0_ENABLE TRUE /* DPLL enable */
#define BOARD_DPLL0_DCOEN FALSE /* DCO filter enable */
#define BOARD_DPLL0_LBYPASS FALSE /* Lock bypass */
#define BOARD_DPLL0_WUF FALSE /* Wake up fast */
#define BOARD_DPLL0_RUNSTDBY FALSE /* Run in standby */
#define BOARD_DPLL0_ONDEMAND FALSE /* On demand clock activation */
#define BOARD_DPLL0_REFLOCK FALSE /* Do not lock reference clock section */
#define BOARD_DPLL0_REFCLK 0 /* Reference clock selection */
#define BOARD_DPLL0_LTIME 0 /* Lock time */
#define BOARD_DPLL0_FILTER 0 /* Proportional integer filter selection */
#define BOARD_DPLL0_DCOFILTER 0 /* Sigma-delta DCO filter selection */
#define BOARD_DPLL0_GCLK 5 /* GCLK source (if refclock == 0) */
#define BOARD_DPLL0_GCLKLOCK 0 /* Don't lock GCLK source clock configuration */
#define BOARD_DPLL0_LDRFRAC 0 /* Loop divider fractional part */
#define BOARD_DPLL0_LDRINT 59 /* Loop divider ratio */
#define BOARD_DPLL0_DIV 0 /* Clock divider */
#define BOARD_DPLL1_ENABLE FALSE /* DPLL enable */
#define BOARD_DPLL1_DCOEN FALSE /* DCO filter enable */
#define BOARD_DPLL1_LBYPASS FALSE /* Lock bypass */
#define BOARD_DPLL1_WUF FALSE /* Wake up fast */
#define BOARD_DPLL1_RUNSTDBY FALSE /* Run in standby */
#define BOARD_DPLL1_ONDEMAND FALSE /* On demand clock activation */
#define BOARD_DPLL1_REFLOCK FALSE /* Do not lock reference clock section */
#define BOARD_DPLL1_REFCLK 1 /* Reference clock = XOSCK32 */
#define BOARD_DPLL1_LTIME 0 /* Lock time */
#define BOARD_DPLL1_FILTER 0 /* Sigma-delta DCO filter selection */
#define BOARD_DPLL1_DCOFILTER 0 /* Sigma-delta DCO filter selection */
#define BOARD_DPLL1_GCLK 0 /* GCLK source (if refclock == 0) */
#define BOARD_DPLL1_GCLKLOCK 0 /* Don't lock GCLK source clock configuration */
#define BOARD_DPLL1_LDRFRAC 13 /* Loop divider fractional part */
#define BOARD_DPLL1_LDRINT 1463 /* Loop divider ratio */
#define BOARD_DPLL1_DIV 0 /* Clock divider */
/* Master Clock (MCLK)
*
* GCLK0 is always the direct source the GCLK_MAIN.
* CPU frequency = 120MHz / 1 = 120MHz
*/
#define BOARD_MCLK_CPUDIV 1 /* MCLK divider to get CPU frequency */
/* Peripheral clocking */
#define BOARD_GCLK_EIC 4 /* EIC GCLK index */
/* FLASH wait states
*
* Vdd Range Wait states Maximum Operating Frequency
* --------- ----------- ---------------------------
* > 2.7V 0 24 MHz
* 1 51 MHz
* 2 77 MHz
* 3 101 MHz
* 4 119 MHz
* 5 120 MHz
* >1.71V 0 22 MHz
* 1 44 MHz
* 2 67 MHz
* 3 89 MHz
* 4 111 MHz
* 5 120 MHz
*/
#define BOARD_FLASH_WAITSTATES 6
/* LED definitions **********************************************************/
/* The Adafruit Metro M4 has four LEDs, but only two are controllable by
* software:
*
* 1. The red LED on the Arduino D13 pin, and
* 2. A NeoPixel RGB LED.
*
* Currently, only the red LED is supported.
*
* ------ ----------------- -----------
* SHIELD SAMD5E5 FUNCTION
* ------ ----------------- -----------
* D13 PA16 GPIO output
*/
/* LED index values for use with board_userled() */
#define BOARD_RED_LED 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_RED_LED_BIT (1 << BOARD_RED_LED)
/* This LED is not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/sam_autoleds.c. The LEDs are used to encode
* OS-related events as follows:
*
* ------------------- ---------------------------- ------
* SYMBOL Meaning LED
* ------------------- ---------------------------- ------
*/
#define LED_STARTED 0 /* NuttX has been started OFF */
#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */
#define LED_STACKCREATED 1 /* Idle stack created ON */
#define LED_INIRQ 2 /* In an interrupt N/C */
#define LED_SIGNAL 2 /* In a signal handler N/C */
#define LED_ASSERTION 2 /* An assertion failed N/C */
#define LED_PANIC 3 /* The system has crashed FLASH */
#undef LED_IDLE /* MCU is is sleep mode Not used */
/* Thus is LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/* Alternate function pin selections ****************************************/
/* SERCOM definitions *******************************************************/
/* The SERCOM bus clock (CLK_SERCOMx_APB) can be enabled and disabled in the
* Main Clock Controller. The SERCOM uses two generic clocks:
* GCLK_SERCOMN_CORE and GCLK_SERCOM_SLOW.
* The core clock (GCLK_SERCOMx_CORE) is required to clock the SERCOM while
* working as a master. The slow clock (GCLK_SERCOM_SLOW) is only required
* for certain functions and is common to all SERCOM modules.
*
* These clocks must be configured and enabled in the Generic Clock
* Controller (GCLK) before using the SERCOM.
*/
#define BOARD_SERCOM_SLOWGEN 3 /* 32.768KHz, common to all SERCOMS */
#define BOARD_SERCOM_SLOWLOCK FALSE /* Don't lock the SLOWCLOCK */
#define BOARD_SLOWCLOCK_FREQUENCY BOARD_GCLK3_FREQUENCY
/* SERCOM3
*
* An Arduino compatible serial Shield is assumed (or equivalently, an
* external RS-232 or serial-to-USB adapter connected on Arduino pins D0
* and D1):
*
* ------ ----------------- ---------
* SHIELD SAMD5E5 FUNCTION
* ------ ----------------- ---------
* D0 PA23 SERCOM3 PAD1 RXD
* D1 PA22 SERCOM3 PAD0 TXD
*
* NOTES:
* USART_CTRLA_TXPAD0_2: TxD=PAD0 XCK=N/A RTS/TE=PAD2 CTS=PAD3
* USART_CTRLA_RXPAD1: RxD=PAD1
*/
#define BOARD_SERCOM3_MUXCONFIG (USART_CTRLA_TXPAD0_2 | USART_CTRLA_RXPAD1)
#define BOARD_SERCOM3_PINMAP_PAD0 PORT_SERCOM3_PAD0_1 /* PAD0: USART TX */
#define BOARD_SERCOM3_PINMAP_PAD1 PORT_SERCOM3_PAD1_1 /* PAD1: USART RX */
#define BOARD_SERCOM3_PINMAP_PAD2 0 /* PAD2: (not used) */
#define BOARD_SERCOM3_PINMAP_PAD3 0 /* PAD3: (not used) */
#define BOARD_TXIRQ_SERCOM3 SAM_IRQ_SERCOM3_0 /* INTFLAG[0] DRE */
#define BOARD_RXIRQ_SERCOM3 SAM_IRQ_SERCOM3_2 /* INTFLAG[2] RXC */
#define BOARD_SERCOM3_COREGEN 1 /* 48MHz Core clock */
#define BOARD_SERCOM3_CORELOCK FALSE /* Don't lock the CORECLOCK */
#define BOARD_SERCOM3_FREQUENCY BOARD_GCLK1_FREQUENCY
/* I2C
* PB02 - SERCOM5 PAD0 SDA
* PB03 - SERCOM5 PAD1 SCL
*/
#define BOARD_SERCOM5_MUXCONFIG (0)
#define BOARD_SERCOM5_PINMAP_PAD0 PORT_SERCOM5_PAD0_3 /* PB02: PAD0: I2C SDA */
#define BOARD_SERCOM5_PINMAP_PAD1 PORT_SERCOM5_PAD1_3 /* PB03: PAD1: I2C SCL */
#define BOARD_SERCOM5_PINMAP_PAD2 0 /* PAD2: (not used) */
#define BOARD_SERCOM5_PINMAP_PAD3 0 /* PAD3: (not used) */
#define BOARD_SERCOM5_GCLKGEN 1 /* 48MHz Core clock */
#define BOARD_SERCOM5_SLOW_GCLKGEN 3
#define BOARD_SERCOM5_FREQUENCY BOARD_GCLK1_FREQUENCY
/* Tickless */
#define BOARD_TC0_PINMAP_CC0 0 /* CC0: (not used) */
#define BOARD_TC0_PINMAP_CC1 0 /* CC1: (not used) */
#define BOARD_TC0_GCLKGEN 3
#define BOARD_TC0_FREQUENCY BOARD_GCLK3_FREQUENCY
#define BOARD_TC2_PINMAP_CC0 0 /* CC0: (not used) */
#define BOARD_TC2_PINMAP_CC1 0 /* CC1: (not used) */
#define BOARD_TC2_GCLKGEN 3
#define BOARD_TC2_FREQUENCY BOARD_GCLK3_FREQUENCY
#define BOARD_TC4_PINMAP_CC0 0 /* CC0: (not used) */
#define BOARD_TC4_PINMAP_CC1 0 /* CC1: (not used) */
#define BOARD_TC4_GCLKGEN 3
#define BOARD_TC4_FREQUENCY BOARD_GCLK3_FREQUENCY
/* USB */
#define BOARD_USB_GCLKGEN 1 /* GCLK1, 48MHz */
#endif /* __BOARDS_ARM_SAMD5E5_METRO_M4_INCLUDE_BOARD_H */

View File

@ -0,0 +1,78 @@
############################################################################
# boards/arm/samd5e5/metro-m4/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
ifeq ($(CONFIG_METRO_M4_RUNFROMFLASH),y)
LDSCRIPT = flash.ld
else ifeq ($(CONFIG_METRO_M4_RUNFROMSRAM),y)
LDSCRIPT = sram.ld
endif
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
ARCHWARNINGSXX = -Wall -Wshadow -Wundef
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
# Loadable module definitions
CMODULEFLAGS = $(CFLAGS) -mlong-calls # --target1-abs
LDMODULEFLAGS = -r -e module_initialize
ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
LDMODULEFLAGS += -T "${shell cygpath -w $(TOPDIR)/libs/libc/modlib/gnu-elf.ld}"
else
LDMODULEFLAGS += -T $(TOPDIR)/libs/libc/modlib/gnu-elf.ld
endif
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif

View File

@ -0,0 +1,108 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/scripts/flash.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAMD51J19 has 512Kb of FLASH beginning at address 0x0000:0000 and
* 192Kb of SRAM at address 0x2000:0000.
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 512K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 192K
}
OUTPUT_ARCH(arm)
ENTRY(_stext)
EXTERN(_vectors)
SECTIONS
{
.text :
{
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section :
{
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > flash
.ARM.extab :
{
*(.ARM.extab*)
} > flash
__exidx_start = ABSOLUTE(.);
.ARM.exidx :
{
*(.ARM.exidx*)
} > flash
__exidx_end = ABSOLUTE(.);
_eronly = ABSOLUTE(.);
.data :
{
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
.bss :
{
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,56 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/scripts/nvm.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <stdint.h>
const uint8_t nvm[20] =
{
0x14, /* Count 20 bytes */
0x80, 0x40, 0x00, /* 24-address : 804000 */
0x39, 0x92, 0x9a, 0xfe, 0x80, 0xff, 0xec, 0xae, /* 16-bytes of NVM data */
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
unsigned int csum;
int i;
printf("S2");
for (i = 0, csum = 0; i < 20; i++)
{
csum += nvm[i];
printf("%02X", (unsigned int)nvm[i]);
}
printf("%02X\r\n", ~csum & 0xff);
printf("S9030000FC\r\n");
return 0;
}

View File

@ -0,0 +1,2 @@
S21480400039929AFE80FFECAEFFFFFFFFFFFFFFFFB7
S9030000FC

View File

@ -0,0 +1,107 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/scripts/sram.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The ATSAMD51J19 has 512Kb of FLASH beginning at address 0x0000:0000 and
* 192Kb of SRAM at address 0x2000:0000. Only sram is used by this linker
* script.
*/
MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 512K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 192K
}
OUTPUT_ARCH(arm)
ENTRY(_stext)
EXTERN(_vectors)
SECTIONS
{
.text :
{
_stext = ABSOLUTE(.);
*(.vectors)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > sram
.init_section :
{
_sinit = ABSOLUTE(.);
*(.init_array .init_array.*)
_einit = ABSOLUTE(.);
} > sram
.ARM.extab :
{
*(.ARM.extab*)
} > sram
__exidx_start = ABSOLUTE(.);
.ARM.exidx :
{
*(.ARM.exidx*)
} > sram
__exidx_end = ABSOLUTE(.);
.data :
{
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram
.bss :
{
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -0,0 +1,74 @@
############################################################################
# boards/arm/samd5e5/metro-m4/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = sam_boot.c sam_bringup.c
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += sam_appinit.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
CSRCS += sam_userleds.c
endif
ifeq ($(CONFIG_USBDEV),y)
CSRCS += sam_usbdev.c
endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += sam_usbmsc.c
endif
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
CSRCS += sam_composite.c
endif
ifeq ($(CONFIG_USBHOST),y)
CSRCS += sam_usbhost.c
endif
ifeq ($(CONFIG_FS_AUTOMOUNTER),y)
CSRCS += sam_automount.c
endif
ifeq ($(CONFIG_SAMD5E5_SERCOM5_ISI2C),y)
CSRCS += sam_i2c.c
ifeq ($(CONFIG_MTD_AT24XX),y)
CSRCS += sam_at24.c
endif
endif
ifeq ($(CONFIG_FS_SMARTFS),y)
CSRCS += sam_smartfs.c
endif
ifeq ($(CONFIG_BQ27426),y)
CSRCS += sam_bq27426.c
endif
ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += sam_gpio.c
endif
include $(TOPDIR)/boards/Board.mk

View File

@ -0,0 +1,163 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/metro-m4.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_SAMD5E5_METRO_M4_SRC_METRO_M4_H
#define __BOARDS_ARM_SAMD5E5_METRO_M4_SRC_METRO_M4_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Metro-M4 GPIOs ***********************************************************/
/* LEDs
*
* The Adafruit Metro M4 has four LEDs, but only two are controllable by
* software:
*
* 1. The red LED on the Arduino D13 pin, and
* 2. A NeoPixel RGB LED.
*
* Currently, only the red LED is supported.
*
* ------ ----------------- -----------
* SHIELD SAMD5E5 FUNCTION
* ------ ----------------- -----------
* D13 PA16 GPIO output
*/
#define PORT_RED_LED (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | PORTA | PORT_PIN16)
#define PORT_D8 (PORT_OUTPUT | PORT_PULL_NONE | PORT_OUTPUT_SET | PORTA | PORT_PIN21)
#define PORT_D9 (PORT_INTERRUPT | PORT_PULL_NONE | PORT_INT_RISING | PORTA | PORT_PIN20)
#define PORT_D10 (PORT_INPUT | PORT_PULL_NONE | PORT_INT_CHANGE | PORTA | PORT_PIN18)
/* GPIO pins used by the GPIO Subsystem */
#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */
#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */
#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */
#define HAVE_AT24 1
/* AT24 Serial EEPROM */
#define AT24_I2C_BUS 5 /* AT24C256 connected to I2C5 */
#define AT24_MINOR 0
#if !defined(CONFIG_MTD_AT24XX) || !defined(CONFIG_SAMD5E5_SERCOM5_ISI2C)
# undef HAVE_AT24
#endif
/* Can't support AT24 features if mountpoints are disabled or if we were not
* asked to mount the AT25 part
*/
#if defined(CONFIG_DISABLE_MOUNTPOINT) || \
!defined(CONFIG_METRO_M4_AT24_BLOCKMOUNT)
# undef HAVE_AT24
#endif
/* On-chip Programming Memory */
#if defined(CONFIG_SAMD5E5_PROGMEM) || defined(CONFIG_MTD_PROGMEM)
#define HAVE_PROGMEM_CHARDEV
#endif
/* This is the on-chip progmem memroy driver minor number */
#define PROGMEM_MTD_MINOR 0
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
/****************************************************************************
* Name: sam_bringup
*
* Description:
* Perform architecture-specific initialization
*
* CONFIG_BOARD_LATE_INITIALIZE=y :
* Called from board_late_initialize().
*
* CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_LIB_BOARDCTL=y :
* Called from the NSH library
*
****************************************************************************/
int sam_bringup(void);
/****************************************************************************
* Name: sam_led_pminitialize
*
* Description:
* Register LED power management features.
*
****************************************************************************/
#ifdef CONFIG_PM
void sam_led_pminitialize(void);
#endif
#ifdef CONFIG_METRO_M4_USB_AUTOMOUNT
void sam_automount_initialize(void);
void sam_automount_event(bool inserted);
#endif
#ifdef CONFIG_SAMD5E5_SERCOM5_ISI2C
FAR struct i2c_master_s *g_i2c5_dev;
int metro_m4_i2cdev_initialize(void);
#endif
#ifdef CONFIG_FS_SMARTFS
int sam_smartfs_initialize(void);
#endif
#ifdef CONFIG_BQ27426
int sam_bq27426_initialize(FAR const char *devname);
#endif
#ifdef CONFIG_DEV_GPIO
int sam_gpio_initialize(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_SAMD5E5_METRO_M4_SRC_METRO_M4_H */

View File

@ -0,0 +1,79 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/board.h>
#include "metro-m4.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef OK
# define OK 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
#ifdef CONFIG_BOARD_LATE_INITIALIZE
/* Board initialization already performed by board_late_initialize() */
return OK;
#else
/* Perform board-specific initialization */
return sam_bringup();
#endif
}

View File

@ -0,0 +1,125 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_at24.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/nxffs.h>
#include "metro-m4.h"
#ifdef HAVE_AT24
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_at24_automount
*
* Description:
* Initialize and configure the AT24 serial EEPROM
*
****************************************************************************/
extern FAR struct i2c_master_s *g_i2c5_dev;
int sam_at24_automount(int minor)
{
FAR struct mtd_dev_s *mtd;
static bool initialized = false;
int ret;
/* Have we already initialized? */
if (!initialized)
{
/* Now bind the I2C interface to the AT24 I2C EEPROM driver */
finfo("Bind the AT24 EEPROM driver to I2C%d\n", AT24_I2C_BUS);
mtd = at24c_initialize(g_i2c5_dev);
if (!mtd)
{
ferr("ERROR: Failed to bind TWI%d to the AT24 EEPROM driver\n",
AT24_I2C_BUS);
return -ENODEV;
}
#if defined(CONFIG_METRO_M4_AT24_FTL)
/* And finally, use the FTL layer
* to wrap the MTD driver as a block driver
*/
finfo("Initialize the FTL layer to create /dev/mtdblock%d\n",
AT24_MINOR);
ret = ftl_initialize(AT24_MINOR, mtd);
if (ret < 0)
{
ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret);
return ret;
}
#elif defined(CONFIG_METRO_M4_AT24_NXFFS)
/* Initialize to provide NXFFS on the MTD interface */
finfo("Initialize the NXFFS file system\n");
ret = nxffs_initialize(mtd);
if (ret < 0)
{
ferr("ERROR: NXFFS initialization failed: %d\n", ret);
return ret;
}
/* Mount the file system at /mnt/at24 */
finfo("Mount the NXFFS file system at /dev/at24\n");
ret = nx_mount(NULL, "/mnt/at24", "nxffs", 0, NULL);
if (ret < 0)
{
ferr("ERROR: Failed to mount the NXFFS volume: %d\n",
ret);
return ret;
}
#endif
/* Now we are initialized */
initialized = true;
}
return OK;
}
#endif /* HAVE_AT24 */

View File

@ -0,0 +1,285 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_autoleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The Adafruit Metro M4 has four LEDs, but only two are controllable by
* software:
*
* 1. The red LED on the Arduino D13 pin, and
* 2. A NeoPixel RGB LED.
*
* Currently, only the red LED is supported.
*
* ------ ----------------- -----------
* SHIELD SAMD5E5 FUNCTION
* ------ ----------------- -----------
* D13 PA16 GPIO output
*
* This LED is not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/sam_autoleds.c. The LEDs are used to encode
* OS-related events as follows:
*
* ------------------- ---------------------------- ------
* SYMBOL Meaning LED
* ------------------- ---------------------------- ------
*
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
* LED_IDLE MCU is is sleep mode Not used
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/power/pm.h>
#include "arm_arch.h"
#include "arm_internal.h"
#include "sam_port.h"
#include "metro-m4.h"
#include <arch/board/board.h>
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* LED Power Management */
#ifdef CONFIG_PM
static void led_pm_notify(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate);
static int led_pm_prepare(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_PM
static struct pm_callback_s g_ledscb =
{
.notify = led_pm_notify,
.prepare = led_pm_prepare,
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: led_pm_notify
*
* Description:
* Notify the driver of new power state. This callback is called after
* all drivers have had the opportunity to prepare for the new power state.
*
****************************************************************************/
#ifdef CONFIG_PM
static void led_pm_notify(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate)
{
switch (pmstate)
{
case(PM_NORMAL):
{
/* Restore normal LEDs operation */
}
break;
case(PM_IDLE):
{
/* Entering IDLE mode - Turn leds off */
}
break;
case(PM_STANDBY):
{
/* Entering STANDBY mode - Logic for PM_STANDBY goes here */
}
break;
case(PM_SLEEP):
{
/* Entering SLEEP mode - Logic for PM_SLEEP goes here */
}
break;
default:
{
/* Should not get here */
}
break;
}
}
#endif
/****************************************************************************
* Name: led_pm_prepare
*
* Description:
* Request the driver to prepare for a new power state. This is a warning
* that the system is about to enter into a new power state. The driver
* should begin whatever operations that may be required to enter power
* state. The driver may abort the state change mode by returning a
* non-zero value from the callback function.
*
****************************************************************************/
#ifdef CONFIG_PM
static int led_pm_prepare(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate)
{
/* No preparation to change power modes is required by the LEDs driver.
* We always accept the state change by returning OK.
*/
return OK;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
sam_portconfig(PORT_RED_LED);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
bool ledstate = true;
switch (led)
{
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
break; /* Leave ledstate == true to turn OFF */
default:
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
ledstate = false; /* Set ledstate == false to turn ON */
break;
}
sam_portwrite(PORT_RED_LED, ledstate);
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
switch (led)
{
/* These should not happen and are ignored */
default:
case 0: /* LED_STARTED: NuttX has been started STATUS LED=OFF
* LED_HEAPALLOCATE: Heap has been allocated STATUS LED=OFF
* LED_IRQSENABLED: Interrupts enabled STATUS LED=OFF
*/
case 1: /* LED_STACKCREATED: Idle stack created STATUS LED=ON */
/* These result in no-change */
case 2: /* LED_INIRQ: In an interrupt STATUS LED=N/C
* LED_SIGNAL: In a signal handler STATUS LED=N/C
* LED_ASSERTION: An assertion failed STATUS LED=N/C
*/
return; /* Return to leave STATUS LED unchanged */
/* Turn STATUS LED off set driving the output high */
case 3: /* LED_PANIC: The system has crashed STATUS LED=FLASH */
sam_portwrite(PORT_RED_LED, true);
break;
}
}
/****************************************************************************
* Name: sam_led_pminitialize
*
* Description:
* Register LED power management features.
*
****************************************************************************/
#ifdef CONFIG_PM
void sam_led_pminitialize(void)
{
/* Register to receive power management callbacks */
int ret = pm_register(&g_ledscb);
if (ret != OK)
{
board_autoled_on(LED_ASSERTION);
}
}
#endif /* CONFIG_PM */
#endif /* CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,331 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_automount.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_FS_AUTOMOUNTER_DEBUG) && !defined(CONFIG_DEBUG_FS)
# define CONFIG_DEBUG_FS 1
#endif
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/fs/automount.h>
#include "metro-m4.h"
#ifdef CONFIG_FS_AUTOMOUNTER
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL (FAR void *)0
#endif
#ifndef OK
# define OK 0
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/* This structure represents the changeable state of the automounter */
struct sam_automount_state_s
{
volatile automount_handler_t handler; /* Upper half handler */
FAR void *arg; /* Handler argument */
bool enable; /* Fake interrupt enable */
bool pending; /* Set if there an event while disabled */
bool inserted;
};
/* This structure represents the static configuration of an automounter */
struct sam_automount_config_s
{
/* This must be first thing in structure so that we can simply cast from
* struct automount_lower_s to struct sam_automount_config_s
*/
struct automount_lower_s lower; /* Publicly visible part */
FAR struct sam_automount_state_s *state; /* Changeable state */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int sam_attach(FAR const struct automount_lower_s *lower,
automount_handler_t isr, FAR void *arg);
static void sam_enable(FAR const struct automount_lower_s *lower,
bool enable);
static bool sam_inserted(FAR const struct automount_lower_s *lower);
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_METRO_M4_USB_AUTOMOUNT
static struct sam_automount_state_s g_port0state;
static const struct sam_automount_config_s g_port0config =
{
.lower =
{
.fstype = CONFIG_METRO_M4_USB_AUTOMOUNT_FSTYPE,
.blockdev = CONFIG_METRO_M4_USB_AUTOMOUNT_BLKDEV,
.mountpoint = CONFIG_METRO_M4_USB_AUTOMOUNT_MOUNTPOINT,
.ddelay = MSEC2TICK(CONFIG_METRO_M4_USB_AUTOMOUNT_DDELAY),
.udelay = MSEC2TICK(CONFIG_METRO_M4_USB_AUTOMOUNT_UDELAY),
.attach = sam_attach,
.enable = sam_enable,
.inserted = sam_inserted
},
.state = &g_port0state
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: sam_attach
*
* Description:
* Attach a new port event handler
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
* isr - The new event handler to be attach
* arg - Client data to be provided when the event handler is invoked.
*
* Returned Value:
* Always returns OK
*
****************************************************************************/
static int sam_attach(FAR const struct automount_lower_s *lower,
automount_handler_t isr, FAR void *arg)
{
FAR const struct sam_automount_config_s *config;
FAR struct sam_automount_state_s *state;
finfo("Entry\n");
/* Recover references to our structure */
config = (FAR struct sam_automount_config_s *)lower;
DEBUGASSERT(config && config->state);
state = config->state;
/* Save the new handler info (clearing the handler first to eliminate
* race conditions).
*/
state->handler = NULL;
state->pending = false;
state->arg = arg;
state->handler = isr;
return OK;
}
/****************************************************************************
* Name: sam_enable
*
* Description:
* Enable port insertion/removal event detection
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
* enable - True: enable event detection; False: disable
*
* Returned Value:
* None
*
****************************************************************************/
static void sam_enable(FAR const struct automount_lower_s *lower,
bool enable)
{
FAR const struct sam_automount_config_s *config;
FAR struct sam_automount_state_s *state;
irqstate_t flags;
finfo("Entry\n");
/* Recover references to our structure */
config = (FAR struct sam_automount_config_s *)lower;
DEBUGASSERT(config && config->state);
state = config->state;
/* Save the fake enable setting */
flags = enter_critical_section();
state->enable = enable;
/* Did an interrupt occur while interrupts were disabled? */
if (enable && state->pending)
{
/* Yes.. perform the fake interrupt if the interrutp is attached */
if (state->handler)
{
(void)state->handler(&config->lower, state->arg, true);
}
state->pending = false;
}
leave_critical_section(flags);
}
/****************************************************************************
* Name: sam_inserted
*
* Description:
* Check if a card is inserted into the slot.
*
* Input Parameters:
* lower - An instance of the auto-mounter lower half state structure
*
* Returned Value:
* True if the card is inserted; False otherwise
*
****************************************************************************/
static bool sam_inserted(FAR const struct automount_lower_s *lower)
{
FAR const struct sam_automount_config_s *config;
config = (FAR struct sam_automount_config_s *)lower;
DEBUGASSERT(config && config->state);
finfo("inserted:%d\n", config->state->inserted);
return config->state->inserted;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_automount_initialize
*
* Description:
* Configure auto-mounters for each enable and so configured HSMCI
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
void sam_automount_initialize(void)
{
FAR void *handle;
finfo("Initializing automounter(s)\n");
#ifdef CONFIG_METRO_M4_USB_AUTOMOUNT
/* Initialize the USB auto-mounter */
handle = automount_initialize(&g_port0config.lower);
if (!handle)
{
ferr("ERROR: Failed to initialize auto-mounter for USB\n");
}
#endif
}
/****************************************************************************
* Name: sam_automount_event
*
* Description:
* It has already scheduled the MMC/SD block driver operations.
* Now we need to schedule the auto-mount event which will occur with
* a substantial delay to make sure that everything has settle down.
*
* Input Parameters:
* inserted - True if the card is inserted in the slot. False otherwise.
*
* Returned Value:
* None
*
* Assumptions:
* Interrupts are disabled.
*
****************************************************************************/
void sam_automount_event(bool inserted)
{
FAR const struct sam_automount_config_s *config;
FAR struct sam_automount_state_s *state;
#ifdef CONFIG_METRO_M4_USB_AUTOMOUNT
config = &g_port0config;
state = &g_port0state;
state->inserted = inserted;
#endif
finfo("event:%d\n", inserted);
/* Is the auto-mounter interrupt attached? */
if (state->handler)
{
/* Yes.. Have we been asked to hold off interrupts? */
if (!state->enable)
{
/* Yes.. just remember that there is a pending interrupt.
* We will deliver the interrupt when interrupts are
* "re-enabled."
*/
state->pending = true;
}
else
{
/* No.. forward the event to the handler */
(void)state->handler(&config->lower, state->arg, state->inserted);
}
}
}
#endif /* CONFIG_FS_AUTOMOUNTER */

View File

@ -0,0 +1,79 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_boot.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include "metro-m4.h"
#include <arch/board/board.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_board_initialize
*
* Description:
* All SAMD5/E5 architectures must provide the following entry point.
* This entry point is called early in the initialization -- after all
* memory has been configured and mapped but before any devices have been
* initialized.
*
****************************************************************************/
void sam_board_initialize(void)
{
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */
board_autoled_initialize();
#endif
}
/****************************************************************************
* Name: board_late_initialize
*
* Description:
* If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_late_initialize(). board_late_initialize() will be
* called immediately after up_initialize() is called and just before the
* initial application is started. This additional initialization phase
* may be used, for example, to initialize board-specific device drivers.
*
****************************************************************************/
#ifdef CONFIG_BOARD_LATE_INITIALIZE
void board_late_initialize(void)
{
/* Perform board-specific initialization */
sam_bringup();
}
#endif

View File

@ -0,0 +1,75 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_bq27426.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/power/battery_gauge.h>
#include <nuttx/power/bq27426.h>
#include <nuttx/power/battery_ioctl.h>
#include "arm_arch.h"
#include "chip.h"
#include "hardware/sam_i2c_master.h"
#include "metro-m4.h"
#include <arch/board/board.h>
#include "sam_config.h"
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef CONFIG_BQ27426
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_bq24298_initialize
*
* Description:
* Called to configure bq24298
*
****************************************************************************/
int sam_bq27426_initialize(FAR const char *devname)
{
FAR struct battery_gauge_dev_s *bq27426_m4;
bq27426_m4 = (FAR struct battery_gauge_dev_s *)bq27426_initialize(
g_i2c5_dev,
BQ27426_I2C_ADDRESS,
100000);
return battery_gauge_register(devname, bq27426_m4);
}
#endif /* CONFIG_BQ27426 */

View File

@ -0,0 +1,174 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_bringup.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include "metro-m4.h"
#if defined(CONFIG_SAMD5E5_WDT) && defined(CONFIG_WATCHDOG)
#include "sam_wdt.h"
#endif
#include <nuttx/fs/fs.h>
#ifdef CONFIG_SAMD5E5_SERCOM5_ISI2C
#include <nuttx/i2c/i2c_master.h>
#include "hardware/sam_i2c_master.h"
#endif
#ifdef CONFIG_USBHOST
# include "sam_usbhost.h"
#endif
#ifdef CONFIG_USBMONITOR
# include <nuttx/usb/usbmonitor.h>
#endif
#ifdef CONFIG_BQ27426
#include <nuttx/power/battery_gauge.h>
#include <nuttx/power/battery_ioctl.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define PROCFS_MOUNTPOINT "/proc"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_bringup
*
* Description:
* Perform architecture-specific initialization
*
* CONFIG_BOARD_LATE_INITIALIZE=y :
* Called from board_late_initialize().
*
* CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
* Called from the NSH library
*
****************************************************************************/
int sam_bringup(void)
{
int ret = OK;
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */
ret = nx_mount(NULL, PROCFS_MOUNTPOINT, "procfs", 0, NULL);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to mount procfs at %s: %d\n",
PROCFS_MOUNTPOINT, ret);
}
#endif
#if defined(CONFIG_SAMD5E5_WDT) && defined(CONFIG_WATCHDOG)
(void)sam_wdt_initialize(CONFIG_WATCHDOG_DEVPATH);
#endif
#ifdef CONFIG_SAMD5E5_SERCOM5_ISI2C
/* Initialize I2C bus */
ret = metro_m4_i2cdev_initialize();
#endif
#ifdef CONFIG_USBHOST
/* Initialize USB host operation. samd_usbhost_initialize() starts a
* thread will monitor for USB connection and disconnection events.
*/
ret = samd_usbhost_initialize();
if (ret != OK)
{
syslog(LOG_ERR, "samd_usbhost_initialize failed %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_USBMONITOR
/* Start the USB Monitor */
ret = usbmonitor_start();
if (ret != OK)
{
syslog(LOG_ERR, "usbmonitor_start failed %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_FS_SMARTFS
/* Initialize Smart File System (SMARTFS) */
ret = sam_smartfs_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to mount smartfs %d\n", ret);
return ret;
}
/* Mount the file system at /mnt/nvm */
ret = nx_mount("/dev/smart0", "/mnt/nvm", "smartfs", 0, NULL);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to mount the SmartFS volume: %d\n",
ret);
return ret;
}
#endif
#ifdef CONFIG_FS_AUTOMOUNTER
/* Initialize the auto-mounter */
sam_automount_initialize();
#endif
#ifdef CONFIG_BQ27426
/* Configure and initialize the BQ2426 distance sensor */
ret = sam_bq27426_initialize("/dev/batt1");
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sam_bq27426_initialize() failed: %d\n", ret);
}
#endif
#ifdef CONFIG_DEV_GPIO
ret = sam_gpio_initialize();
#endif
UNUSED(ret);
return OK;
}

View File

@ -0,0 +1,348 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_composite.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbdev_trace.h>
#include <nuttx/usb/cdcacm.h>
#include <nuttx/usb/usbmsc.h>
#include <nuttx/usb/composite.h>
#include "metro-m4.h"
#if defined(CONFIG_BOARDCTL_USBDEVCTRL) && defined(CONFIG_USBDEV_COMPOSITE)
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static FAR void *g_mschandle;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: board_mscclassobject
*
* Description:
* If the mass storage class driver is part of composite device, then
* its instantiation and configuration is a multi-step, board-specific,
* process (See comments for usbmsc_configure below). In this case,
* board-specific logic must provide board_mscclassobject().
*
* board_mscclassobject() is called from the composite driver. It must
* encapsulate the instantiation and configuration of the mass storage
* class and the return the mass storage device's class driver instance
* to the composite driver.
*
* Input Parameters:
* classdev - The location to return the mass storage class' device
* instance.
*
* Returned Value:
* 0 on success; a negated errno on failure
*
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static int board_mscclassobject(int minor,
FAR struct usbdev_devinfo_s *devinfo,
FAR struct usbdevclass_driver_s **classdev)
{
int ret;
DEBUGASSERT(g_mschandle == NULL);
/* Configure the mass storage device */
uinfo("Configuring with NLUNS=1\n");
ret = usbmsc_configure(1, &g_mschandle);
if (ret < 0)
{
uerr("ERROR: usbmsc_configure failed: %d\n", -ret);
return ret;
}
uinfo("MSC handle=%p\n", g_mschandle);
/* Bind the LUN(s) */
uinfo("Bind LUN=0 to /dev/mmcsd0\n");
ret = usbmsc_bindlun(g_mschandle, "/dev/mmcsd0", 0, 0, 0, false);
if (ret < 0)
{
uerr("ERROR: usbmsc_bindlun failed for LUN 1 at /dev/mmcsd0: %d\n",
ret);
usbmsc_uninitialize(g_mschandle);
g_mschandle = NULL;
return ret;
}
/* Get the mass storage device's class object */
ret = usbmsc_classobject(g_mschandle, devinfo, classdev);
if (ret < 0)
{
uerr("ERROR: usbmsc_classobject failed: %d\n", -ret);
usbmsc_uninitialize(g_mschandle);
g_mschandle = NULL;
}
return ret;
}
#endif
/****************************************************************************
* Name: board_mscuninitialize
*
* Description:
* Un-initialize the USB storage class driver. This is just an application
* specific wrapper aboutn usbmsc_unitialize() that is called form the
* composite device logic.
*
* Input Parameters:
* classdev - The class driver instrance previously give to the composite
* driver by board_mscclassobject().
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev)
{
DEBUGASSERT(g_mschandle != NULL);
usbmsc_uninitialize(g_mschandle);
g_mschandle = NULL;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_composite_initialize
*
* Description:
* Perform architecture specific initialization of a composite USB device.
*
****************************************************************************/
int board_composite_initialize(int port)
{
return OK;
}
/****************************************************************************
* Name: board_composite_connect
*
* Description:
* Connect the USB composite device on the specified USB device port using
* the specified configuration. The interpretation of the configid is
* board specific.
*
* Input Parameters:
* port - The USB device port.
* configid - The USB composite configuration
*
* Returned Value:
* A non-NULL handle value is returned on success. NULL is returned on
* any failure.
*
****************************************************************************/
FAR void *board_composite_connect(int port, int configid)
{
/* Here we are composing the configuration of the usb composite device.
*
* The standard is to use one CDC/ACM and one USB mass storage device.
*/
if (configid == 0)
{
#ifdef CONFIG_USBMSC_COMPOSITE
struct composite_devdesc_s dev[2];
int ifnobase = 0;
int strbase = COMPOSITE_NSTRIDS;
/* Configure the CDC/ACM device */
/* Ask the cdcacm driver to fill in the constants we didn't
* know here.
*/
cdcacm_get_composite_devdesc(&dev[0]);
/* Overwrite and correct some values... */
/* The callback functions for the CDC/ACM class */
dev[0].classobject = cdcacm_classobject;
dev[0].uninitialize = cdcacm_uninitialize;
/* Interfaces */
dev[0].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[0].minor = 0; /* The minor interface number */
/* Strings */
dev[0].devinfo.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[0].devinfo.epno[CDCACM_EP_INTIN_IDX] = 3;
dev[0].devinfo.epno[CDCACM_EP_BULKIN_IDX] = 4;
dev[0].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = 5;
/* Count up the base numbers */
ifnobase += dev[0].devinfo.ninterfaces;
strbase += dev[0].devinfo.nstrings;
/* Configure the mass storage device device */
/* Ask the usbmsc driver to fill in the constants we didn't
* know here.
*/
usbmsc_get_composite_devdesc(&dev[1]);
/* Overwrite and correct some values... */
/* The callback functions for the USBMSC class */
dev[1].classobject = board_mscclassobject;
dev[1].uninitialize = board_mscuninitialize;
/* Interfaces */
dev[1].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[1].minor = 0; /* The minor interface number */
/* Strings */
dev[1].devinfo.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[1].devinfo.epno[USBMSC_EP_BULKIN_IDX] = 1;
dev[1].devinfo.epno[USBMSC_EP_BULKOUT_IDX] = 2;
/* Count up the base numbers */
ifnobase += dev[1].devinfo.ninterfaces;
strbase += dev[1].devinfo.nstrings;
return composite_initialize(2, dev);
#else
return NULL;
#endif
}
/* Configuration with three CDC/ACMs
*
* This configuration can be used e.g. on a samv71-xult. The samv71 has
* 10 Endpoints (EPs). The EPs 0 up to 7 are DMA aware. The EPs 8 and 9
* are not.
*
* In a composite device we need the EP0 as an control Endpoint. Each
* CDC/ACM needs one Interrupt driven and two bulk Endpoints. This is
* why we configure the EPs 7, 8 and 9 to be the IRQ-EPs and the
* EP-Pairs 1/2, 3/4, 5/6 to be the bulk EPs for each device.
*
* This means, that
*
* - the Composite device uses EP0 as the control-Endpoint,
* - the CDC/ACM 0 uses EP7, EP1 and EP2,
* - the CDC/ACM 1 uses EP8, EP3 and EP4,
* - the CDC/ACM 2 uses EP9, EP5 and EP6
*
* as its EP-Configuration.
*/
else if (configid == 1)
{
struct composite_devdesc_s dev[3];
int strbase = COMPOSITE_NSTRIDS;
int ifnobase = 0;
int ia;
for (ia = 0; ia < 3; ia++)
{
/* Ask the cdcacm driver to fill in the
* constants we didn't know here
*/
cdcacm_get_composite_devdesc(&dev[ia]);
/* Overwrite and correct some values... */
/* The callback functions for the CDC/ACM class */
dev[ia].classobject = cdcacm_classobject;
dev[ia].uninitialize = cdcacm_uninitialize;
dev[ia].minor = ia; /* The minor interface number */
/* Interfaces */
dev[ia].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
/* Strings */
dev[ia].devinfo.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[ia].devinfo.epno[CDCACM_EP_INTIN_IDX] = 7 + ia;
dev[ia].devinfo.epno[CDCACM_EP_BULKIN_IDX] = 1 + ia * 2;
dev[ia].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = 2 + ia * 2;
ifnobase += dev[ia].devinfo.ninterfaces;
strbase += dev[ia].devinfo.nstrings;
}
return composite_initialize(3, dev);
}
else
{
return NULL;
}
}
#endif /* CONFIG_BOARDCTL_USBDEVCTRL && CONFIG_USBDEV_COMPOSITE */

View File

@ -0,0 +1,341 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_gpio.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/clock.h>
#include <nuttx/wdog.h>
#include <nuttx/ioexpander/gpio.h>
#include <nuttx/irq.h>
#include "irq/irq.h"
#include "chip.h"
#include <arch/board/board.h>
#include "sam_config.h"
#include "metro-m4.h"
#include "sam_port.h"
#include "sam_eic.h"
#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF)
/****************************************************************************
* Private Types
****************************************************************************/
struct samgpio_dev_s
{
struct gpio_dev_s gpio;
uint8_t id;
};
struct samgpint_dev_s
{
struct samgpio_dev_s samgpio;
pin_interrupt_t callback;
};
irqstate_t flags;
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value);
#endif
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpout_write(FAR struct gpio_dev_s *dev, bool value);
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpint_attach(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback);
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable);
/****************************************************************************
* Private Data
****************************************************************************/
#if BOARD_NGPIOIN > 0
static const struct gpio_operations_s gpin_ops =
{
.go_read = gpin_read,
.go_write = NULL,
.go_attach = NULL,
.go_enable = NULL,
};
#endif
static const struct gpio_operations_s gpout_ops =
{
.go_read = gpout_read,
.go_write = gpout_write,
.go_attach = NULL,
.go_enable = NULL,
};
static const struct gpio_operations_s gpint_ops =
{
.go_read = gpint_read,
.go_write = NULL,
.go_attach = gpint_attach,
.go_enable = gpint_enable,
};
static const int g_extint[1] = /* SAM_IRQ_EXTINT0 offset! */
{
4, /* PORT_D9 - PA20 - EXTINT 4 */
};
#if BOARD_NGPIOIN > 0
/* This array maps the GPIO pins used as INPUT */
static const uint32_t g_gpioinputs[BOARD_NGPIOIN] =
{
PORT_D10,
};
static struct samgpio_dev_s g_gpin[BOARD_NGPIOIN];
#endif
#if BOARD_NGPIOOUT
/* This array maps the GPIO pins used as OUTPUT */
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
{
PORT_D8,
};
static struct samgpio_dev_s g_gpout[BOARD_NGPIOOUT];
#endif
#if BOARD_NGPIOINT > 0
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] =
{
PORT_D9
};
static struct samgpint_dev_s g_gpint[BOARD_NGPIOINT];
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
static int samgpio_interrupt(int irq, void *context, void *arg)
{
FAR struct samgpint_dev_s *samgpint = (FAR struct samgpint_dev_s *)arg;
DEBUGASSERT(samgpint != NULL && samgpint->callback != NULL);
gpioinfo("Interrupt! callback=%p\n", samgpint->callback);
samgpint->callback(&samgpint->samgpio.gpio, samgpint->samgpio.id);
return OK;
}
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct samgpio_dev_s *samgpio = (FAR struct samgpio_dev_s *)dev;
DEBUGASSERT(samgpio != NULL && value != NULL);
DEBUGASSERT(samgpio->id < BOARD_NGPIOIN);
gpioinfo("Reading...\n");
*value = sam_portread(g_gpioinputs[samgpio->id]);
return OK;
}
#endif
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct samgpio_dev_s *samgpio = (FAR struct samgpio_dev_s *)dev;
DEBUGASSERT(samgpio != NULL && value != NULL);
DEBUGASSERT(samgpio->id < BOARD_NGPIOOUT);
gpioinfo("Reading...\n");
*value = sam_portread(g_gpiooutputs[samgpio->id]);
return OK;
}
static int gpout_write(FAR struct gpio_dev_s *dev, bool value)
{
FAR struct samgpio_dev_s *samgpio = (FAR struct samgpio_dev_s *)dev;
DEBUGASSERT(samgpio != NULL);
DEBUGASSERT(samgpio->id < BOARD_NGPIOOUT);
gpioinfo("Writing %d\n", (int)value);
sam_portwrite(g_gpiooutputs[samgpio->id], value);
return OK;
}
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct samgpint_dev_s *samgpint = (FAR struct samgpint_dev_s *)dev;
DEBUGASSERT(samgpint != NULL && value != NULL);
DEBUGASSERT(samgpint->samgpio.id < BOARD_NGPIOINT);
gpioinfo("Reading int pin...\n");
*value = sam_portread(g_gpiointinputs[samgpint->samgpio.id]);
return OK;
}
static int gpint_attach(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback)
{
FAR struct samgpint_dev_s *samgpint = (FAR struct samgpint_dev_s *)dev;
gpioinfo("Attaching the callback\n");
flags = enter_critical_section();
/* Make sure the interrupt is disabled */
int ret = irq_attach(SAM_IRQ_EXTINT0 + g_extint[samgpint->samgpio.id],
samgpio_interrupt, &g_gpint[samgpint->samgpio.id]);
if (ret == OK)
{
/* Configure the interrupt edge sensitivity
* in CONFIGn register of the EIC
*/
sam_eic_configure(g_extint[samgpint->samgpio.id],
g_gpiointinputs[samgpint->samgpio.id]);
}
leave_critical_section(flags);
gpioinfo("Attach %p\n", callback);
samgpint->callback = callback;
return OK;
}
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)
{
FAR struct samgpint_dev_s *samgpint = (FAR struct samgpint_dev_s *)dev;
flags = enter_critical_section();
if (enable)
{
if (samgpint->callback != NULL)
{
gpioinfo("Enabling the interrupt\n");
up_enable_irq(SAM_IRQ_EXTINT0 + g_extint[samgpint->samgpio.id]);
}
}
else
{
up_disable_irq(SAM_IRQ_EXTINT0 + g_extint[samgpint->samgpio.id]);
gpioinfo("Disable the interrupt\n");
}
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_gpio_initialize
*
* Description:
* Initialize GPIO drivers for use with /apps/examples/gpio
*
****************************************************************************/
int sam_gpio_initialize(void)
{
int i;
int pincount = 0;
#if BOARD_NGPIOIN > 0
for (i = 0; i < BOARD_NGPIOIN; i++)
{
/* Setup and register the GPIO pin */
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN;
g_gpin[i].gpio.gp_ops = &gpin_ops;
g_gpin[i].id = i;
(void)gpio_pin_register(&g_gpin[i].gpio, pincount);
/* Configure the pin that will be used as input */
sam_portconfig(g_gpioinputs[i]);
pincount++;
}
#endif
#if BOARD_NGPIOOUT > 0
for (i = 0; i < BOARD_NGPIOOUT; i++)
{
/* Setup and register the GPIO pin */
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
(void)gpio_pin_register(&g_gpout[i].gpio, pincount);
/* Configure the pin that will be used as output */
sam_portconfig(g_gpiooutputs[i]);
pincount++;
}
#endif
#if BOARD_NGPIOINT > 0
for (i = 0; i < BOARD_NGPIOINT; i++)
{
/* Setup and register the GPIO pin */
g_gpint[i].samgpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].samgpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].samgpio.id = i;
(void)gpio_pin_register(&g_gpint[i].samgpio.gpio, pincount);
/* Configure the pin that will be used as interrupt input */
sam_portconfig(g_gpiointinputs[i]);
pincount++;
}
#endif
return 0;
}
#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */

View File

@ -0,0 +1,87 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_i2c.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/i2c/i2c_master.h>
#include "arm_arch.h"
#include "chip.h"
#include "metro-m4.h"
#include "sam_config.h"
#include "sam_i2c_master.h"
#include <arch/board/board.h>
#if defined(SAMD5E5_HAVE_I2C5_MASTER)
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: metro_m4_i2cdev_initialize
*
* Description:
* Called to configure I2C
*
****************************************************************************/
int metro_m4_i2cdev_initialize(void)
{
int ret = OK;
#ifdef SAMD5E5_HAVE_I2C5_MASTER
g_i2c5_dev = sam_i2c_master_initialize(5);
if (!g_i2c5_dev)
{
syslog(LOG_ERR, "ERROR: metro_m4_i2cdev_initialize() failed: %d\n",
ret);
ret = -ENODEV;
}
else
{
#ifdef CONFIG_I2C_DRIVER
ret = i2c_register(g_i2c5_dev, 5);
#endif
}
#endif
return ret;
}
#endif /* SAMD5E5_HAVE_I2C5_MASTER */

View File

@ -0,0 +1,235 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_smartfs.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#include "arm_arch.h"
#include "chip.h"
#include <arch/board/board.h>
#include "metro-m4.h"
#ifdef CONFIG_MTD
# include <nuttx/mtd/mtd.h>
# include <nuttx/mtd/configdata.h>
# include <nuttx/drivers/drivers.h>
# include "sam_progmem.h"
#endif
#ifdef CONFIG_FS_SMARTFS
# include <nuttx/fs/smart.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_FS_SMARTFS
int ret;
FAR struct mtd_dev_s *mtd;
FAR struct mtd_geometry_s geo;
#endif
#if defined(CONFIG_MTD_PARTITION_NAMES)
const char *partname = "mnta";
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_FS_SMARTFS
int sam_smartfs_initialize(void)
{
/* Initialize the SAMD5E5 FLASH programming memory library */
sam_progmem_initialize();
/* Create an instance of the SAMD5E5 FLASH program memory device driver */
mtd = progmem_initialize();
if (!mtd)
{
syslog(LOG_ERR, "ERROR: progmem_initialize failed\n");
}
ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: mtd->ioctl failed: %d\n", ret);
return ret;
}
#ifdef CONFIG_MTD_PARTITION
{
int partno;
int partsize;
int partoffset;
int partszbytes;
int erasesize;
const char *partstring = "256";
const char *ptr;
FAR struct mtd_dev_s *mtd_part;
char partref[4];
/* Now create a partition on the FLASH device */
partno = 0;
ptr = partstring;
partoffset = 0;
/* Get the Flash erase size */
erasesize = geo.erasesize;
while (*ptr != '\0')
{
/* Get the partition size */
partsize = atoi(ptr);
partszbytes = (partsize << 10); /* partsize is defined in KB */
printf("partsize %d partszbytes %d\n", partsize, partszbytes);
/* Check if partition size is bigger then erase block */
if (partszbytes < erasesize)
{
syslog(LOG_ERR,
"ERROR: Partition size is lesser than erasesize!\n");
return -1;
}
/* Check if partition size is multiple of erase block */
if ((partszbytes % erasesize) != 0)
{
syslog(LOG_ERR,
"ERROR: Partition size is not multiple of erasesize!\n");
return -1;
}
mtd_part = mtd_partition(mtd, partoffset,
partszbytes / erasesize);
partoffset += partszbytes / erasesize;
/* Test if this is the config partition */
#if defined CONFIG_MTD_CONFIG
if (partno == 0)
{
/* Register the partition as the config device */
mtdconfig_register(mtd_part);
}
else
#endif
{
/* Now initialize a SMART Flash block device
* and bind it to the MTD device.
*/
#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS)
sprintf(partref, "p%d", partno);
smart_initialize(0, mtd_part, partref);
#endif
}
/* Set the partition name */
#ifdef CONFIG_MTD_PARTITION_NAMES
if (!mtd_part)
{
syslog(LOG_ERR,
"Error: failed to create partition %s\n",
partname);
return -1;
}
mtd_setpartitionname(mtd_part, partname);
/* Now skip to next name.
* We don't need to split the string here
* because the MTD partition logic will only
* display names up to the comma,
* thus allowing us to use a single static name
* in the code.
*/
while (*partname != ',' && *partname != '\0')
{
/* Skip to next ',' */
partname++;
}
if (*partname == ',')
{
partname++;
}
#endif
/* Update the pointer to point to the next size in the list */
while ((*ptr >= '0') && (*ptr <= '9'))
{
ptr++;
}
if (*ptr == ',')
{
ptr++;
}
/* Increment the part number */
partno++;
}
}
#else /* CONFIG_MTD_PARTITION */
/* Configure the device with no partition support */
smart_initialize(0, mtd, NULL);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: SmartFS initialization failed: %d\n", ret);
return ret;
}
#endif
return OK;
}
#endif /* CONFIG_FS_SMARTFS */

View File

@ -0,0 +1,92 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_usbdev.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbdev_trace.h>
#include "arm_arch.h"
#include "metro-m4.h"
#include <arch/board/board.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_usbinitialize
*
* Description:
* Called to setup USB-related GPIO pins
*
****************************************************************************/
void sam_usbinitialize(void)
{
/* USB Soft Connect Pullup */
}
/****************************************************************************
* Name: sam_usbpullup
*
* Description:
* If USB is supported and the board supports a pullup via GPIO (for USB
* software connect and disconnect), then the board software must provide
* sam_pullup. See include/nuttx/usb/usbdev.h for additional description
* of this method. Alternatively, if no pull-up GPIO the following EXTERN
* can be redefined to be NULL.
*
****************************************************************************/
int sam_usbpullup(FAR struct usbdev_s *dev, bool enable)
{
usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
return OK;
}
/****************************************************************************
* Name: sam_usbsuspend
*
* Description:
* Board logic must provide the sam_usbsuspend logic if the USBDEV driver
* is used. This function is called whenever the USB enters or leaves
* suspend mode. This is an opportunity for the board logic to shutdown
* clocks, power, etc. while the USB is suspended.
*
****************************************************************************/
void sam_usbsuspend(FAR struct usbdev_s *dev, bool resume)
{
uinfo("resume: %d\n", resume);
}

View File

@ -0,0 +1,235 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_usbhost.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <sched.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/kthread.h>
#include <nuttx/usb/usbhost.h>
#include <nuttx/usb/usbdev_trace.h>
#include "chip.h"
#include "arm_arch.h"
#include "metro-m4.h"
#include "sam_port.h"
#include "sam_usbhost.h"
#include <arch/board/board.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST)
#define HAVE_USB 1
#endif
#ifndef CONFIG_METRO_M4_USBHOST_PRIO
#define CONFIG_METRO_M4_USBHOST_PRIO 100
#endif
#ifndef CONFIG_METRO_M4_USBHOST_STACKSIZE
#define CONFIG_METRO_M4_USBHOST_STACKSIZE 1024
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_USBHOST
static struct usbhost_connection_s *g_usbconn;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: usbhost_waiter
*
* Description:
* Wait for USB devices to be connected.
*
****************************************************************************/
#ifdef CONFIG_USBHOST
static int usbhost_waiter(int argc, char *argv[])
{
struct usbhost_hubport_s *hport;
uinfo("Running\n");
for (; ; )
{
/* Wait for the device to change state */
DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
uinfo("%s\n", hport->connected ? "connected" : "disconnected");
/* Did we just become connected? */
if (hport->connected)
{
/* Yes.. enumerate the newly connected device */
(void)CONN_ENUMERATE(g_usbconn, hport);
}
#ifdef CONFIG_METRO_M4_USB_AUTOMOUNT
/* Let the automounter know about the insertion event */
sam_automount_event(hport->connected);
#endif
}
/* Keep the compiler from complaining */
return 0;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_usbinitialize
*
* Description:
*
****************************************************************************/
void sam_usbinitialize(void)
{
}
/****************************************************************************
* Name: sam_usbhost_vbusdrive
*
* Description:
* Enable/disable driving of VBUS 5V output. This function must be provided
* be each platform that implements the HS host interface
*
* Input Parameters:
* iface - For future growth to handle multiple USB host interface. Should
* be zero.
* enable - true: enable VBUS power; false: disable VBUS power
*
****************************************************************************/
#ifdef CONFIG_USBHOST
void sam_usbhost_vbusdrive(int iface, bool enable)
{
DEBUGASSERT(iface == 0);
if (enable)
{
/* Set your function here! */
}
else
{
/* Set your function here! */
}
}
#endif
/****************************************************************************
* Name: samd_usbhost_initialize
*
* Description:
* Called at application startup time to initialize the USB host
* functionality. This function will start a thread that will monitor for
* device connection/disconnection events.
*
****************************************************************************/
#ifdef CONFIG_USBHOST
int samd_usbhost_initialize(void)
{
int pid;
int ret;
/* First, register all of the class drivers needed to support the drivers
* that we care about:
*/
uinfo("Register class drivers\n");
#ifdef CONFIG_USBHOST_MSC
/* Register the USB mass storage class class */
ret = usbhost_msc_initialize();
if (ret != OK)
{
uerr("ERROR: Failed to register the mass storage class: %d\n", ret);
}
#endif
#ifdef CONFIG_USBHOST_HIDKBD
/* Initialize the HID keyboard class */
ret = usbhost_kbdinit();
if (ret != OK)
{
uerr("ERROR: Failed to register the HID keyboard class\n");
}
#endif
#ifdef CONFIG_USBHOST_HIDMOUSE
/* Initialize the HID mouse class */
ret = usbhost_mouse_init();
if (ret != OK)
{
uerr("ERROR: Failed to register the HID mouse class\n");
}
#endif
/* Then get an instance of the USB host interface */
uinfo("Initialize USB host\n");
g_usbconn = sam_usbhost_initialize(0);
if (g_usbconn)
{
/* Start a thread to handle device connection. */
uinfo("Start usbhost_waiter\n");
pid =
kthread_create("usbhost", CONFIG_METRO_M4_USBHOST_PRIO,
CONFIG_METRO_M4_USBHOST_STACKSIZE,
(main_t) usbhost_waiter, (FAR char *const *)NULL);
return pid < 0 ? -ENOEXEC : OK;
}
return -ENODEV;
}
#endif

View File

@ -0,0 +1,71 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_usbmsc.c
*
* Copyright 2020 Falker Automacao Agricola LTDA.
* Author: Leomar Mateus Radke <leomar@falker.com.br>
* Author: Ricardo Wartchow <wartchow@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <nuttx/board.h>
#include "metro-m4.h"
#include <arch/board/board.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_SYSTEM_USBMSC_DEVMINOR1
# define CONFIG_SYSTEM_USBMSC_DEVMINOR1 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_usbmsc_initialize
*
* Description:
* Perform architecture specific initialization of the USB MSC device.
*
****************************************************************************/
int board_usbmsc_initialize(int port)
{
/* If system/usbmsc is built as an NSH command
*/
#ifndef CONFIG_NSH_BUILTIN_APPS
#else
return OK;
#endif
}

View File

@ -0,0 +1,218 @@
/****************************************************************************
* boards/arm/samd5e5/metro-m4/src/sam_userleds.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* The Adafruit Metro M4 has four LEDs, but only two are controllable by
* software:
*
* 1. The red LED on the Arduino D13 pin, and
* 2. A NeoPixel RGB LED.
*
* Currently, only the red LED is supported.
*
* ------ ----------------- -----------
* SHIELD SAMD5E5 FUNCTION
* ------ ----------------- -----------
* D13 PA16 GPIO output
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/power/pm.h>
#include "arm_arch.h"
#include "sam_port.h"
#include "metro-m4.h"
#include <arch/board/board.h>
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* LED Power Management */
#ifdef CONFIG_PM
static void led_pm_notify(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate);
static int led_pm_prepare(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_PM
static struct pm_callback_s g_ledscb =
{
.notify = led_pm_notify,
.prepare = led_pm_prepare,
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: led_pm_notify
*
* Description:
* Notify the driver of new power state. This callback is called after
* all drivers have had the opportunity to prepare for the new power state.
*
****************************************************************************/
#ifdef CONFIG_PM
static void led_pm_notify(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate)
{
switch (pmstate)
{
case(PM_NORMAL):
{
/* Restore normal LEDs operation */
}
break;
case(PM_IDLE):
{
/* Entering IDLE mode - Turn leds off */
}
break;
case(PM_STANDBY):
{
/* Entering STANDBY mode - Logic for PM_STANDBY goes here */
}
break;
case(PM_SLEEP):
{
/* Entering SLEEP mode - Logic for PM_SLEEP goes here */
}
break;
default:
{
/* Should not get here */
}
break;
}
}
#endif
/****************************************************************************
* Name: led_pm_prepare
*
* Description:
* Request the driver to prepare for a new power state. This is a warning
* that the system is about to enter into a new power state. The driver
* should begin whatever operations that may be required to enter power
* state. The driver may abort the state change mode by returning a
* non-zero value from the callback function.
*
****************************************************************************/
#ifdef CONFIG_PM
static int led_pm_prepare(struct pm_callback_s *cb, int domain,
enum pm_state_e pmstate)
{
/* No preparation to change power modes is required by the LEDs driver.
* We always accept the state change by returning OK.
*/
return OK;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_userled_initialize
****************************************************************************/
uint32_t board_userled_initialize(void)
{
sam_portconfig(PORT_STATUS_LED);
return BOARD_NLEDS;
}
/****************************************************************************
* Name: board_userled
****************************************************************************/
void board_userled(int led, bool ledon)
{
if (led == BOARD_STATUS_LED)
{
sam_portwrite(PORT_STATUS_LED, !ledon);
}
}
/****************************************************************************
* Name: board_userled_all
****************************************************************************/
void board_userled_all(uint32_t ledset)
{
board_userled(BOARD_STATUS_LED, (ledset & BOARD_STATUS_LED_BIT) != 0);
}
/****************************************************************************
* Name: sam_led_pminitialize
*
* Description:
* Register LED power management features.
*
****************************************************************************/
#ifdef CONFIG_PM
void sam_led_pminitialize(void)
{
/* Register to receive power management callbacks */
int ret = pm_register(&g_ledscb);
if (ret != OK)
{
board_autoled_on(LED_ASSERTION);
}
}
#endif /* CONFIG_PM */
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -0,0 +1,50 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_SAME54_XPLAINED_PRO
choice
prompt "Execution memory"
default SAME54_XPLAINED_PRO_RUNFROMFLASH
config SAME54_XPLAINED_PRO_RUNFROMFLASH
bool "Run from FLASH"
select BOOT_RUNFROMFLASH
---help---
This is the normal configuration for building SAM E54 Xplained
Pro code.
config SAME54_XPLAINED_PRO_RUNFROMSRAM
bool "Run from SRAM"
select BOOT_RUNFROMISRAM
---help---
During early bring-up, it is safer to execute entirely from
SRAM until you are confident in the initialization logic.
Then you can safely switch to FLASH.
REVISIT: This auto-selects CONFIG_BOOT_RUNFROMISRAM but I have
found, with some difficulty, that that choice still defaults to
CONFIG_BOOT_RUNFROMFLASH, causing link-time failures when running
from SRAM.
endchoice # Execution memory
config SAME54_XPLAINED_PRO_32KHZXTAL
bool "32.768 KHz XTAL"
default n
---help---
According to the schematic, a 32.768 KHz crystal is installed on
board. However, I have been unable to use this crystal and thought
perhaps it is missing or defective on my board (there is a metal
package that could be a crystal on board, but I am not certain).
Another, more likely option is that there is a coding error on my
part that prevents the 32.768 KHz crystal from usable(?)
The configuration defaults to using the always-on OSCULP32 as the
slow clock source. This option will select instead XOSC32 as the
slow clock source.
endif # ARCH_BOARD_SAME54_XPLAINED_PRO

View File

@ -0,0 +1,159 @@
README
======
This directory contains the port of NuttX to the Microchip SAME54 Xplained
Pro board. This board is powered by an ATSAME54P20A:
o Cortex M4 core running at 120 MHz
o Hardware DSP and floating point support
o 1 MB flash, 256 KB RAM
o 32-bit, 3.3V logic and power
o Dual 1 MSPS DAC (A0 and A1)
o Dual 1 MSPS ADC (8 analog pins)
o 8 x hardware SERCOM (I2C, SPI or UART)
o 16 x PWM outputs
o Stereo I2S input/output with MCK pin
o 14-bit Parallel capture controller (for camera/video in)
o Built in crypto engines with AES (256 bit), true RNG, Pubkey controller
o 10/100 Ethernet MAC
o Dual SD/MMC controller
o Dual CAN bus interfaces
o 100-TQFP
Contents
========
o STATUS
o Serial Console
o LEDs
o Run from SRAM
o Configurations
STATUS
======
2019-09-17: Board port started based on Metro M4 board.
WARNING: If you decide to invest the time to discover whey the XOSC32K
clock source is not working, be certain to use the SRAM configuration.
That configuration in FLASH is most likely lock up your board irrecoverably
is there are any start-up errors!
Serial Console
==============
The onboard debugger on the SAME54 Xplained Pro provides a virtual serial
interface over the DEBUG USB port. The pins on the SAME54 are as follows:
----------------- -----------
SAMD5E5 FUNCTION
----------------- -----------
PB24 SERCOM2 PAD1 RXD
PB25 SERCOM2 PAD0 TXD
An external RS-232 or serial-to-USB adapter can be connected on pins PA22
and PA23:
----------------- ---------
SAMD5E5 FUNCTION
----------------- ---------
PA23 SERCOM3 PAD1 RXD
PA22 SERCOM3 PAD0 TXD
LEDs
====
The SAME54 Xplained Pro has three LEDs, but only one is controllable by software:
1. LED0 near the edge of the board
----------------- -----------
SAMD5E5 FUNCTION
----------------- -----------
PC18 GPIO output
Run from SRAM
=============
I bricked my first Metro M4 board because there were problems in the
bring-up logic. These problems left the chip in a bad state that was
repeated on each reset because the code was written into FLASH and I was
unable to ever connect to it again via SWD.
To make the bring-up less risky, I added a configuration option to build
the code to execution entirely out of SRAM. By default, the setting
CONFIG_SAME54_XPLAINED_PRO_RUNFROMFLASH=y is used and the code is built to run out of
FLASH. If CONFIG_SAME54_XPLAINED_PRO_RUNFROMSRAM=y is selected instead, then the
code is built to run out of SRAM.
To use the code in this configuration, the program must be started a
little differently:
gdb> mon reset
gdb> mon halt
gdb> load nuttx << Load NuttX into SRAM
gdb> file nuttx << Assuming debug symbols are enabled
gdb> mon memu32 0x20000000 << Get the address of initial stack
gdb> mon reg sp 0x200161c4 << Set the initial stack pointer using this address
gdb> mon memu32 0x20000004 << Get the address of __start entry point
gdb> mon reg pc 0x20000264 << Set the PC using this address (without bit 0 set)
gdb> si << Step in just to make sure everything is okay
gdb> [ set breakpoints ]
gdb> c << Then continue until you hit a breakpoint
Where 0x200161c4 and 0x20000264 are the values of the initial stack and
the __start entry point that I read from SRAM
Configurations
==============
Each SAME54 Xplained Pro configuration is maintained in a sub-directory and
can be selected as follow:
tools/configure.sh [OPTIONS] same54-xplained-pro:<subdir>
Do 'tools/configure.sh -h' for the list of options. If you are building
under Windows with Cygwin, you would need the -c option, for example.
Before building, make sure that the PATH environmental variable includes the
correct path to the directory than holds your toolchain binaries.
And then build NuttX by simply typing the following. At the conclusion of
the make, the nuttx binary will reside in an ELF file called, simply, nuttx.
make
The <subdir> that is provided above as an argument to the tools/configure.sh
must be is one of configurations listed in the following paragraph.
NOTES:
1. These configurations use the mconf-based configuration tool. To
change any of these configurations using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Unless stated otherwise, all configurations generate console
output on SERCOM2 which is available via USB debug.
3. Unless otherwise stated, the configurations are setup build under
Linux with a generic ARM EABI toolchain:
Configuration sub-directories
-----------------------------
nsh:
This configuration directory will built the NuttShell. See NOTES for
common configuration above and the following:
NOTES:
1. The CMCC (Cortex M Cache Controller) is enabled.

View File

@ -0,0 +1,48 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="same54-xplained-pro"
CONFIG_ARCH_BOARD_SAME54_XPLAINED_PRO=y
CONFIG_ARCH_CHIP="samd5e5"
CONFIG_ARCH_CHIP_SAME54P20=y
CONFIG_ARCH_CHIP_SAME5X=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=7225
CONFIG_BUILTIN=y
CONFIG_DISABLE_ENVIRON=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_MAX_TASKS=16
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_DEFAULT=1536
CONFIG_RAM_SIZE=196608
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMD5E5_CMCC=y
CONFIG_SAMD5E5_EIC=y
CONFIG_SAMD5E5_SERCOM2=y
CONFIG_SAMD5E5_SERCOM3=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=23
CONFIG_START_MONTH=7
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=64
CONFIG_USART3_TXBUFSIZE=64
CONFIG_USERMAIN_STACKSIZE=1536
CONFIG_USER_ENTRYPOINT="nsh_main"

Some files were not shown because too many files have changed in this diff Show More