2010-01-17 18:55:13 +01:00
|
|
|
/**************************************************************************
|
2013-06-02 21:57:22 +02:00
|
|
|
* arch/arm/src/sam34/sam_lowputc.c
|
2010-01-17 18:55:13 +01:00
|
|
|
*
|
2014-02-22 20:46:23 +01:00
|
|
|
* Copyright (C) 2010, 2013-2014 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-01-17 18:55:13 +01:00
|
|
|
*
|
|
|
|
* 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 <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "up_internal.h"
|
|
|
|
#include "up_arch.h"
|
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
#include "sam_gpio.h"
|
2013-06-13 01:32:00 +02:00
|
|
|
#include "sam_periphclks.h"
|
2013-06-02 21:04:40 +02:00
|
|
|
#include "sam_lowputc.h"
|
2013-06-08 19:39:06 +02:00
|
|
|
|
2013-06-27 19:06:13 +02:00
|
|
|
#if defined(CONFIG_ARCH_CHIP_SAM3U) || defined(CONFIG_ARCH_CHIP_SAM3X) || \
|
2014-02-22 20:46:23 +01:00
|
|
|
defined(CONFIG_ARCH_CHIP_SAM3A) || defined(CONFIG_ARCH_CHIP_SAM4S) || \
|
|
|
|
defined(CONFIG_ARCH_CHIP_SAM4E)
|
|
|
|
# include "chip/sam_uart.h"
|
2013-06-08 19:39:06 +02:00
|
|
|
#elif defined(CONFIG_ARCH_CHIP_SAM4L)
|
|
|
|
# include "chip/sam4l_usart.h"
|
|
|
|
#else
|
|
|
|
# error Unknown UART
|
|
|
|
#endif
|
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
#include "chip/sam_pinmap.h"
|
2010-01-17 18:55:13 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Definitions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration **********************************************************/
|
|
|
|
|
2010-01-21 03:35:34 +01:00
|
|
|
/* If the USART is not being used as a UART, then it really isn't enabled
|
|
|
|
* for our purposes.
|
|
|
|
*/
|
|
|
|
|
2010-01-17 18:55:13 +01:00
|
|
|
#ifndef CONFIG_USART0_ISUART
|
2013-06-02 18:33:57 +02:00
|
|
|
# undef CONFIG_SAM34_USART0
|
2010-01-17 18:55:13 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_USART1_ISUART
|
2013-06-02 18:33:57 +02:00
|
|
|
# undef CONFIG_SAM34_USART1
|
2010-01-17 18:55:13 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_USART2_ISUART
|
2013-06-02 18:33:57 +02:00
|
|
|
# undef CONFIG_SAM34_USART2
|
2010-01-17 18:55:13 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_USART3_ISUART
|
2013-06-02 18:33:57 +02:00
|
|
|
# undef CONFIG_SAM34_USART3
|
2010-01-17 18:55:13 +01:00
|
|
|
#endif
|
|
|
|
|
2013-06-11 22:32:07 +02:00
|
|
|
/* Is there a serial console? It could be on UART0-1 or USART0-3 */
|
2010-01-17 18:55:13 +01:00
|
|
|
|
2013-06-11 00:18:47 +02:00
|
|
|
#if defined(CONFIG_UART0_SERIAL_CONSOLE) && defined(CONFIG_SAM34_UART0)
|
2013-06-11 22:32:07 +02:00
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
|
|
|
#elif defined(CONFIG_UART1_SERIAL_CONSOLE) && defined(CONFIG_SAM34_UART1)
|
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif defined(CONFIG_USART0_SERIAL_CONSOLE) && defined(CONFIG_SAM34_USART0)
|
2013-06-11 22:32:07 +02:00
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif defined(CONFIG_USART1_SERIAL_CONSOLE) && defined(CONFIG_SAM34_USART1)
|
2013-06-11 22:32:07 +02:00
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif defined(CONFIG_USART2_SERIAL_CONSOLE) && defined(CONFIG_SAM34_USART2)
|
2013-06-11 22:32:07 +02:00
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif defined(CONFIG_USART3_SERIAL_CONSOLE) && defined(CONFIG_SAM34_USART3)
|
2013-06-11 22:32:07 +02:00
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# define HAVE_CONSOLE 1
|
|
|
|
#else
|
2013-06-11 22:32:07 +02:00
|
|
|
# warning "No valid CONFIG_USARTn_SERIAL_CONSOLE Setting"
|
|
|
|
# undef CONFIG_UART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_UART1_SERIAL_CONSOLE
|
2010-01-17 18:55:13 +01:00
|
|
|
# undef CONFIG_USART0_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
|
|
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
|
|
|
# undef HAVE_CONSOLE
|
|
|
|
#endif
|
|
|
|
|
2013-06-08 21:50:42 +02:00
|
|
|
/* Select MCU-specific settings
|
|
|
|
*
|
2014-02-22 20:46:23 +01:00
|
|
|
* For the SAM3U, SAM3A, SAM3X, SAM4E and SAM4S the USARTs are driven by the
|
|
|
|
* main clock. (This could also be the MCK/8 or an external clock but
|
|
|
|
* those options have not yet been necessary).
|
2013-06-08 21:50:42 +02:00
|
|
|
* For the SAM4L, the USARTs are driven by CLK_USART (undivided) which is
|
|
|
|
* selected by the PBADIVMASK register.
|
|
|
|
*/
|
|
|
|
|
2013-06-27 19:06:13 +02:00
|
|
|
#if defined(CONFIG_ARCH_CHIP_SAM3U) || defined(CONFIG_ARCH_CHIP_SAM3X) || \
|
2014-02-22 20:46:23 +01:00
|
|
|
defined(CONFIG_ARCH_CHIP_SAM3A) || defined(CONFIG_ARCH_CHIP_SAM4S) || \\
|
|
|
|
defined(CONFIG_ARCH_CHIP_SAM4E)
|
2013-06-08 21:50:42 +02:00
|
|
|
# define SAM_MR_USCLKS UART_MR_USCLKS_MCK /* Source = Main clock */
|
2013-06-12 01:33:43 +02:00
|
|
|
# define SAM_USART_CLOCK BOARD_MCK_FREQUENCY /* Frequency of the main clock */
|
2013-06-08 21:50:42 +02:00
|
|
|
#elif defined(CONFIG_ARCH_CHIP_SAM4L)
|
|
|
|
# define SAM_MR_USCLKS UART_MR_USCLKS_USART /* Source = USART_CLK (undefined) */
|
|
|
|
# define SAM_USART_CLOCK BOARD_PBA_FREQUENCY /* PBA frequency is undivided */
|
|
|
|
#else
|
|
|
|
# error Unrecognized SAM architecture
|
|
|
|
#endif
|
|
|
|
|
2010-01-17 18:55:13 +01:00
|
|
|
/* Select USART parameters for the selected console */
|
|
|
|
|
2013-06-11 00:18:47 +02:00
|
|
|
#if defined(CONFIG_UART0_SERIAL_CONSOLE)
|
|
|
|
# define SAM_CONSOLE_BASE SAM_UART0_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_UART0_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_UART0_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_UART0_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_UART0_2STOP
|
2013-06-11 22:32:07 +02:00
|
|
|
#elif defined(CONFIG_UART1_SERIAL_CONSOLE)
|
|
|
|
# define SAM_CONSOLE_BASE SAM_UART1_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_UART1_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_UART1_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_UART1_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_UART1_2STOP
|
2010-01-17 18:55:13 +01:00
|
|
|
#elif defined(CONFIG_USART0_SERIAL_CONSOLE)
|
2013-06-02 18:33:57 +02:00
|
|
|
# define SAM_CONSOLE_BASE SAM_USART0_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_USART0_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_USART0_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_USART0_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_USART0_2STOP
|
2010-01-17 18:55:13 +01:00
|
|
|
#elif defined(CONFIG_USART1_SERIAL_CONSOLE)
|
2013-06-02 18:33:57 +02:00
|
|
|
# define SAM_CONSOLE_BASE SAM_USART1_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_USART1_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_USART1_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_USART1_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_USART1_2STOP
|
2010-01-17 18:55:13 +01:00
|
|
|
#elif defined(CONFIG_USART2_SERIAL_CONSOLE)
|
2013-06-02 18:33:57 +02:00
|
|
|
# define SAM_CONSOLE_BASE SAM_USART2_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_USART2_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_USART2_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_USART2_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_USART2_2STOP
|
2010-01-17 18:55:13 +01:00
|
|
|
#elif defined(CONFIG_USART3_SERIAL_CONSOLE)
|
2013-06-02 18:33:57 +02:00
|
|
|
# define SAM_CONSOLE_BASE SAM_USART3_BASE
|
|
|
|
# define SAM_CONSOLE_BAUD CONFIG_USART3_BAUD
|
|
|
|
# define SAM_CONSOLE_BITS CONFIG_USART3_BITS
|
|
|
|
# define SAM_CONSOLE_PARITY CONFIG_USART3_PARITY
|
|
|
|
# define SAM_CONSOLE_2STOP CONFIG_USART3_2STOP
|
2010-01-17 18:55:13 +01:00
|
|
|
#else
|
|
|
|
# error "No CONFIG_U[S]ARTn_SERIAL_CONSOLE Setting"
|
|
|
|
#endif
|
|
|
|
|
2010-01-21 03:35:34 +01:00
|
|
|
/* Select the settings for the mode register */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#if SAM_CONSOLE_BITS == 5
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_CHRL_VALUE UART_MR_CHRL_5BITS /* 5 bits */
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif SAM_CONSOLE_BITS == 6
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_CHRL_VALUE UART_MR_CHRL_6BITS /* 6 bits */
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif SAM_CONSOLE_BITS == 7
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_CHRL_VALUE UART_MR_CHRL_7BITS /* 7 bits */
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif SAM_CONSOLE_BITS == 8
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_CHRL_VALUE UART_MR_CHRL_8BITS /* 8 bits */
|
2013-06-11 22:32:07 +02:00
|
|
|
#elif SAM_CONSOLE_BITS == 9 && !defined(CONFIG_UART0_SERIAL_CONSOLE) && \
|
|
|
|
!defined(CONFIG_UART1_SERIAL_CONSOLE)
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_CHRL_VALUE UART_MR_MODE9
|
2010-01-21 03:35:34 +01:00
|
|
|
#else
|
2013-07-27 19:28:31 +02:00
|
|
|
# error "Invalid number of bits"
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#if SAM_CONSOLE_PARITY == 1
|
2010-01-21 03:35:34 +01:00
|
|
|
# define MR_PAR_VALUE UART_MR_PAR_ODD
|
2013-06-02 18:33:57 +02:00
|
|
|
#elif SAM_CONSOLE_PARITY == 2
|
2010-01-21 03:35:34 +01:00
|
|
|
# define MR_PAR_VALUE UART_MR_PAR_EVEN
|
|
|
|
#else
|
|
|
|
# define MR_PAR_VALUE UART_MR_PAR_NONE
|
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#if SAM_CONSOLE_2STOP != 0
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_NBSTOP_VALUE UART_MR_NBSTOP_2
|
2010-01-21 03:35:34 +01:00
|
|
|
#else
|
2013-06-08 19:39:06 +02:00
|
|
|
# define MR_NBSTOP_VALUE UART_MR_NBSTOP_1
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
|
|
|
|
2013-06-08 21:50:42 +02:00
|
|
|
#define MR_VALUE (UART_MR_MODE_NORMAL | SAM_MR_USCLKS | \
|
2013-06-02 18:33:57 +02:00
|
|
|
MR_CHRL_VALUE | MR_PAR_VALUE | MR_NBSTOP_VALUE)
|
2010-01-21 03:35:34 +01:00
|
|
|
|
2010-01-17 18:55:13 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Private Types
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Global Variables
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Variables
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Name: up_lowputc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Output one byte on the serial console
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
void up_lowputc(char ch)
|
|
|
|
{
|
2010-01-21 03:35:34 +01:00
|
|
|
/* Wait for the transmitter to be available */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
while ((getreg32(SAM_CONSOLE_BASE + SAM_UART_SR_OFFSET) & UART_INT_TXEMPTY) == 0);
|
2010-01-21 03:35:34 +01:00
|
|
|
|
|
|
|
/* Send the character */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
putreg32((uint32_t)ch, SAM_CONSOLE_BASE + SAM_UART_THR_OFFSET);
|
2010-01-17 18:55:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2013-06-02 21:04:40 +02:00
|
|
|
* Name: sam_lowsetup
|
2010-01-17 18:55:13 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This performs basic initialization of the USART used for the serial
|
|
|
|
* console. Its purpose is to get the console output availabe as soon
|
|
|
|
* as possible.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2013-06-02 21:04:40 +02:00
|
|
|
void sam_lowsetup(void)
|
2010-01-17 18:55:13 +01:00
|
|
|
{
|
2010-01-21 03:52:06 +01:00
|
|
|
/* Enable clocking for all selected UART/USARTs */
|
2010-01-17 18:55:13 +01:00
|
|
|
|
2013-06-11 00:18:47 +02:00
|
|
|
#ifdef CONFIG_SAM34_UART0
|
2013-06-11 22:32:07 +02:00
|
|
|
sam_uart0_enableclk();
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SAM34_UART1
|
|
|
|
sam_uart1_enableclk();
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART0
|
2013-06-08 21:50:42 +02:00
|
|
|
sam_usart0_enableclk();
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART1
|
2013-06-08 21:50:42 +02:00
|
|
|
sam_usart1_enableclk();
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART2
|
2013-06-08 21:50:42 +02:00
|
|
|
sam_usart2_enableclk();
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART3
|
2013-06-08 21:50:42 +02:00
|
|
|
sam_usart3_enableclk();
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
|
|
|
|
2010-01-21 03:52:06 +01:00
|
|
|
/* Configure UART pins for all selected UART/USARTs */
|
2013-06-02 18:33:57 +02:00
|
|
|
|
2013-06-11 00:18:47 +02:00
|
|
|
#ifdef CONFIG_SAM34_UART0
|
2013-06-11 22:32:07 +02:00
|
|
|
(void)sam_configgpio(GPIO_UART0_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_UART0_TXD);
|
2010-01-21 03:52:06 +01:00
|
|
|
#endif
|
2013-06-08 21:50:42 +02:00
|
|
|
|
2013-06-12 16:18:42 +02:00
|
|
|
#ifdef CONFIG_SAM34_UART1
|
|
|
|
(void)sam_configgpio(GPIO_UART1_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_UART1_TXD);
|
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART0
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART0_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_USART0_TXD);
|
2013-06-08 21:50:42 +02:00
|
|
|
#ifdef CONFIG_USART0_OFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART0_CTS);
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USART0_IFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART0_RTS);
|
2010-01-21 03:52:06 +01:00
|
|
|
#endif
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART1
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART1_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_USART1_TXD);
|
2013-06-08 21:50:42 +02:00
|
|
|
#ifdef CONFIG_USART1_OFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART1_CTS);
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USART1_IFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART1_RTS);
|
2010-01-21 03:52:06 +01:00
|
|
|
#endif
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART2
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART2_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_USART2_TXD);
|
2013-06-08 21:50:42 +02:00
|
|
|
#ifdef CONFIG_USART2_OFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART2_CTS);
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USART2_IFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART2_RTS);
|
2010-01-21 03:52:06 +01:00
|
|
|
#endif
|
2013-06-08 21:50:42 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
#ifdef CONFIG_SAM34_USART3
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART3_RXD);
|
|
|
|
(void)sam_configgpio(GPIO_USART3_TXD);
|
2013-06-08 21:50:42 +02:00
|
|
|
#ifdef CONFIG_USART3_OFLOWCONTROL
|
2013-06-02 21:04:40 +02:00
|
|
|
(void)sam_configgpio(GPIO_USART3_CTS);
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2013-06-08 21:50:42 +02:00
|
|
|
#ifdef CONFIG_USART3_IFLOWCONTROL
|
|
|
|
(void)sam_configgpio(GPIO_USART3_RTS);
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Configure the console (only) */
|
2010-01-22 04:08:29 +01:00
|
|
|
#if defined(HAVE_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG)
|
2010-01-21 03:35:34 +01:00
|
|
|
/* Reset and disable receiver and transmitter */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
putreg32((UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS),
|
|
|
|
SAM_CONSOLE_BASE + SAM_UART_CR_OFFSET);
|
2010-01-21 03:35:34 +01:00
|
|
|
|
|
|
|
/* Disable all interrupts */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
putreg32(0xffffffff, SAM_CONSOLE_BASE + SAM_UART_IDR_OFFSET);
|
2010-01-21 03:35:34 +01:00
|
|
|
|
|
|
|
/* Set up the mode register */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
putreg32(MR_VALUE, SAM_CONSOLE_BASE + SAM_UART_MR_OFFSET);
|
2010-01-21 03:35:34 +01:00
|
|
|
|
2013-06-09 18:57:42 +02:00
|
|
|
/* Configure the console baud. NOTE: Oversampling by 8 is not supported.
|
|
|
|
* This may limit BAUD rates for lower USART clocks.
|
|
|
|
*/
|
2010-01-21 03:35:34 +01:00
|
|
|
|
2013-06-08 21:50:42 +02:00
|
|
|
putreg32(((SAM_USART_CLOCK + (SAM_CONSOLE_BAUD << 3)) / (SAM_CONSOLE_BAUD << 4)),
|
2013-06-02 18:33:57 +02:00
|
|
|
SAM_CONSOLE_BASE + SAM_UART_BRGR_OFFSET);
|
2010-01-21 03:35:34 +01:00
|
|
|
|
|
|
|
/* Enable receiver & transmitter */
|
|
|
|
|
2013-06-02 18:33:57 +02:00
|
|
|
putreg32((UART_CR_RXEN | UART_CR_TXEN),
|
|
|
|
SAM_CONSOLE_BASE + SAM_UART_CR_OFFSET);
|
2010-01-21 03:35:34 +01:00
|
|
|
#endif
|
2010-01-17 18:55:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|