diff --git a/configs/samv71-xult/README.txt b/configs/samv71-xult/README.txt index d58b6e5a241..323f080b607 100644 --- a/configs/samv71-xult/README.txt +++ b/configs/samv71-xult/README.txt @@ -20,6 +20,7 @@ Contents - Networking - Audio Interface - maXTouch Xplained Pro + - MCAN1 Loopback Test - Debugging - Configurations @@ -951,8 +952,8 @@ MXT Configuration Options ILI9488 Configuration Options ----------------------------- -Currently only the parallel mode is supported. This means that the LCD can -only be used in connected in the LCD (EXT4) connection. + Currently only the parallel mode is supported. This means that the LCD can + only be used in connected in the LCD (EXT4) connection. System Type -> SAMV7 Peripheral Support CONFIG_SAMV7_SMC=y : Needed by the ILI9466 driver controller @@ -990,27 +991,94 @@ only be used in connected in the LCD (EXT4) connection. CONFIG_EXAMPLES_NXLINES_VPLANE=0 CONFIG_EXAMPLES_NXLINES_DEVNO=0 +MCAN1 Loopback Test +=================== + + MCAN1 + ----- + SAM V71 Xplained Ultra has two MCAN modules that performs communication according + to ISO11898-1 (Bosch CAN specification 2.0 part A,B) and Bosch CAN FD + specification V1.0. MCAN1 is connected to an on-board ATA6561 CAN physical-layer + transceiver. + + ------- -------- -------- ------------- + SAM V71 FUNCTION ATA6561 SHARED + PIN FUNCTION FUNCTIONALITY + ------- -------- -------- ------------- + PC14 CANTX1 TXD Shield + PC12 CANRX1 RXD Shield + ------- -------- -------- ------------- + + Enabling MCAN1 + -------------- + These modifications may be applied to the samv71-xult/nsh configuration in order + to enable MCAN1: + + Device Drivers -> CAN Driver support + CONFIG_CAN=y # Enable the upper-half CAN driver + CONFIG_CAN_FIFOSIZE=8 + CONFIG_CAN_NPENDINGRTR=4 + + System Type -> SAMV7 Peripheral Selections + CONFIG_SAMV7_MCAN1=y # Enable MCAN1 as the lower-half + + System Type ->MCAN device driver options + CONFIG_SAMV7_MCAN_CLKSRC_MAIN=y # Use the MAIN clock as the source + CONFIG_SAMV7_MCAN_CLKSRC_PRESCALER=1 + + System Type ->MCAN device driver options -> MCAN1 device driver options + CONFIG_SAMV7_MCAN1_ISO11899_1=y # Loopback test only support ISO11899-1 + CONFIG_SAMV7_MCAN1_LOOPBACK=y # Needed for loopback test + CONFIG_SAMV7_MCAN1_BITRATE=500000 # Not critical for loopback test + CONFIG_SAMV7_MCAN1_PROPSEG=2 # Bit timing setup + CONFIG_SAMV7_MCAN1_PHASESEG1=11 # " " " " " " + CONFIG_SAMV7_MCAN1_PHASESEG2=11 # " " " " " " + CONFIG_SAMV7_MCAN1_FSJW=4 # " " " " " " + CONFIG_SAMV7_MCAN1_FBITRATE=2000000 # CAN_FD BTW mode is not used + CONFIG_SAMV7_MCAN1_FPROPSEG=2 # " " " " " " "" " " " " + CONFIG_SAMV7_MCAN1_FPHASESEG1=4 # " " " " " " "" " " " " + CONFIG_SAMV7_MCAN1_FPHASESEG2=4 # " " " " " " "" " " " " + CONFIG_SAMV7_MCAN1_FFSJW=2 # " " " " " " "" " " " " + CONFIG_SAMV7_MCAN1_NSTDFILTERS=0 # Filters are not used in the loopback test + CONFIG_SAMV7_MCAN1_NEXTFILTERS=0 # " " " " " " " " "" " " " " " " + CONFIG_SAMV7_MCAN1_RXFIFO0_32BYTES=y # Each RX FIFO0 element is 32 bytes + CONFIG_SAMV7_MCAN1_RXFIFO0_SIZE=8 # There are 8 queue elements + CONFIG_SAMV7_MCAN1_RXFIFO0_32BYTES=y # Each RX FIFO1 element is 32 bytes + CONFIG_SAMV7_MCAN1_RXFIFO0_SIZE=8 # There are 8 queue elements + CONFIG_SAMV7_MCAN1_RXBUFFER_32BYTES=y # Each RX BUFFER is 32 bytes + CONFIG_SAMV7_MCAN1_TXBUFFER_32BYTES=y # Each TX BUFFER is 32 bytes + CONFIG_SAMV7_MCAN1_TXFIFOQ_SIZE=8 # There are 8 queue elements + CONFIG_SAMV7_MCAN1_TXEVENTFIFO_SIZE=0 # The event FIFO is not used + + Enabling the CAN Loopback Test + ------------------------------ + Application Configuration -> Examples -> CAN Example + CONFIG_EXAMPLES_CAN=y # Enables the CAN test + + Enabling CAN Debug Output + ------------------------- + Debugging ========= -The on-board EDBG appears to work only with Atmel Studio. You can however, -simply connect a SAM-ICE or J-Link to the JTAG/SWD connector on the board -and that works great. The only tricky thing is getting the correct -orientation of the JTAG connection. + The on-board EDBG appears to work only with Atmel Studio. You can however, + simply connect a SAM-ICE or J-Link to the JTAG/SWD connector on the board + and that works great. The only tricky thing is getting the correct + orientation of the JTAG connection. -I have been using Atmel Studio to write code to flash then I use the Segger -J-Link GDB server to debug. I have been using the 'Device Programming' I -available under the Atmel Studio 'Tool' menu. I have to disconnect the -SAM-ICE while programming with the EDBG. I am sure that you could come up -with a GDB server-only solution if you wanted. + I have been using Atmel Studio to write code to flash then I use the Segger + J-Link GDB server to debug. I have been using the 'Device Programming' I + available under the Atmel Studio 'Tool' menu. I have to disconnect the + SAM-ICE while programming with the EDBG. I am sure that you could come up + with a GDB server-only solution if you wanted. -I run GDB like this from the directory containing the NuttX ELF file: + I run GDB like this from the directory containing the NuttX ELF file: - arm-none-eabi-gdb - (gdb) target remote localhost:2331 - (gdb) mon reset - (gdb) file nuttx - (gdb) ... start debugging ... + arm-none-eabi-gdb + (gdb) target remote localhost:2331 + (gdb) mon reset + (gdb) file nuttx + (gdb) ... start debugging ... Configurations ============== diff --git a/configs/samv71-xult/include/board.h b/configs/samv71-xult/include/board.h index 6042f327baf..ee192211cf1 100644 --- a/configs/samv71-xult/include/board.h +++ b/configs/samv71-xult/include/board.h @@ -503,6 +503,25 @@ # endif #endif /* CONFIG_SAMV71XULT_MXTXPLND */ +/* MCAN1 + * + * SAM V71 Xplained Ultra has two MCAN modules that performs communication according + * to ISO11898-1 (Bosch CAN specification 2.0 part A,B) and Bosch CAN FD + * specification V1.0. MCAN1 is connected to an on-board ATA6561 CAN physical-layer + * transceiver. + * + * ------- -------- -------- ------------- + * SAM V71 FUNCTION ATA6561 SHARED + * PIN FUNCTION FUNCTIONALITY + * ------- -------- -------- ------------- + * PC14 CANTX1 TXD Shield + * PC12 CANRX1 RXD Shield + * ------- -------- -------- ------------- + */ + +#define GPIO_MCAN1_TX GPIO_MCAN1_TX_2 +#define GPIO_MCAN1_RX GPIO_MCAN1_RX_2 + /************************************************************************************ * Public Types ************************************************************************************/ diff --git a/configs/samv71-xult/src/Makefile b/configs/samv71-xult/src/Makefile index 90bc363b51e..c5653e78268 100644 --- a/configs/samv71-xult/src/Makefile +++ b/configs/samv71-xult/src/Makefile @@ -90,6 +90,10 @@ ifeq ($(CONFIG_USBMSC),y) CSRCS += sam_usbmsc.c endif +ifeq ($(CONFIG_SAMV7_MCAN),y) +CSRCS += sam_mcan.c +endif + ifeq ($(CONFIG_AUDIO_WM8904),y) ifeq ($(CONFIG_SAMV7_TWIHS0),y) ifeq ($(CONFIG_SAMV7_SSC0),y) diff --git a/configs/samv71-xult/src/sam_mcan.c b/configs/samv71-xult/src/sam_mcan.c new file mode 100644 index 00000000000..8df23759418 --- /dev/null +++ b/configs/samv71-xult/src/sam_mcan.c @@ -0,0 +1,134 @@ +/************************************************************************************ + * configs/samv71-xultk/src/sam_mcan.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "sam_mcan.h" +#include "samv71-xult.h" + +#if defined(CONFIG_CAN) && (defined(CONFIG_SAMV7_MCAN0) || defined(CONFIG_SAMV7_MCAN1)) + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ + +#if defined(CONFIG_SAMV7_MCAN0) && defined(CONFIG_SAMV7_MCAN1) +# warning "Both MCAN0 and MCAN1 are enabled. Assuming only CAN1." +# undef CONFIG_SAMV7_MCAN0 +#endif + +#ifdef CONFIG_SAMV7_MCAN0 +# define CAN_PORT 0 +#else +# define CAN_PORT 1 +#endif + +/* Debug ***************************************************************************/ +/* Non-standard debug that may be enabled just for testing CAN */ + +#ifdef CONFIG_DEBUG_CAN +# define candbg dbg +# define canvdbg vdbg +# define canlldbg lldbg +# define canllvdbg llvdbg +#else +# define candbg(x...) +# define canvdbg(x...) +# define canlldbg(x...) +# define canllvdbg(x...) +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: can_devinit + * + * Description: + * All STM32 architectures must provide the following interface to work with + * examples/can. + * + ************************************************************************************/ + +int can_devinit(void) +{ + static bool initialized = false; + struct can_dev_s *can; + int ret; + + /* Check if we have already initialized */ + + if (!initialized) + { + /* Call stm32_caninitialize() to get an instance of the CAN interface */ + + can = sam_mcan_initialize(CAN_PORT); + if (can == NULL) + { + candbg("ERROR: Failed to get CAN interface\n"); + return -ENODEV; + } + + /* Register the CAN driver at "/dev/can0" */ + + ret = can_register("/dev/can0", can); + if (ret < 0) + { + candbg("ERROR: can_register failed: %d\n", ret); + return ret; + } + + /* Now we are initialized */ + + initialized = true; + } + + return OK; +} + +#endif /* CONFIG_CAN && (CONFIG_SAMV7_MCAN0 || CONFIG_SAMV7_MCAN1) */