From d4958348824356e84c1521a9e428804d2796ceb2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 23 May 2015 13:08:28 -0600 Subject: [PATCH] SAML21: Several SERCOM fixes. No gets UART output, but at the wrong BAUD --- arch/arm/src/samdl/chip/saml_gclk.h | 2 +- arch/arm/src/samdl/chip/saml_usart.h | 12 ++++++------ arch/arm/src/samdl/sam_lowputc.c | 3 +++ arch/arm/src/samdl/sam_sercom.c | 9 ++++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/arm/src/samdl/chip/saml_gclk.h b/arch/arm/src/samdl/chip/saml_gclk.h index 22d01ace76..c172bb2020 100644 --- a/arch/arm/src/samdl/chip/saml_gclk.h +++ b/arch/arm/src/samdl/chip/saml_gclk.h @@ -56,7 +56,7 @@ /* GCLK register offsets ********************************************************************/ #define SAM_GCLK_CTRLA_OFFSET 0x0000 /* Control register */ -#define SAM_GCLK_SYNCHBUSY_OFFSET 0x0004 /* Status register */ +#define SAM_GCLK_SYNCHBUSY_OFFSET 0x0004 /* Status register */ #define SAM_GCLK_GENCTRL_OFFSET(n) (0x0020 + ((n) << 2)) /* General clock generator n */ #define SAM_GCLK_PCHCTRL_OFFSET(m) (0x0080 + ((m) << 2)) /* Peripheral channel control m */ diff --git a/arch/arm/src/samdl/chip/saml_usart.h b/arch/arm/src/samdl/chip/saml_usart.h index 2d364f6e70..d47a1ddf2f 100644 --- a/arch/arm/src/samdl/chip/saml_usart.h +++ b/arch/arm/src/samdl/chip/saml_usart.h @@ -65,7 +65,7 @@ #define SAM_USART_INTFLAG_OFFSET 0x0018 /* Interrupt flag and status clear register */ #define SAM_USART_STATUS_OFFSET 0x001a /* Status register */ #define SAM_USART_SYNCBUSY_OFFSET 0x001c /* Synchronization busy register */ -#define SAM_USART_DATA_OFFSET 0x0018 /* Data register */ +#define SAM_USART_DATA_OFFSET 0x0028 /* Data register */ #define SAM_USART_DBGCTRL_OFFSET 0x0030 /* Debug control register */ /* USART register addresses *****************************************************************/ @@ -156,11 +156,11 @@ #define USART_CTRLA_IBON (1 << 8) /* Bit 8: Immediate BUFOVF notification */ #define USART_CTRLA_SAMPR_SHIFT (11) /* Bits 11-12: Sample rate */ #define USART_CTRLA_SAMPR_MASK (3 << USART_CTRLA_SAMPR_SHIFT) -# define USART_CTRLA_SAMPR_16XA (xx << USART_CTRLA_SAMPR_SHIFT) /* 16x oversampling; arithmetic baud */ -# define USART_CTRLA_SAMPR_16XF (xx << USART_CTRLA_SAMPR_SHIFT) /* 16x oversampling; fractional baud */ -# define USART_CTRLA_SAMPR_8XA (xx << USART_CTRLA_SAMPR_SHIFT) /* 8x oversampling; arithmetic baud */ -# define USART_CTRLA_SAMPR_8XF (xx << USART_CTRLA_SAMPR_SHIFT) /* 8x oversampling; fractional baud */ -# define USART_CTRLA_SAMPR_3XA (xx << USART_CTRLA_SAMPR_SHIFT) /* 3x oversampling; arithmetic baud */ +# define USART_CTRLA_SAMPR_16XA (0 << USART_CTRLA_SAMPR_SHIFT) /* 16x oversampling; arithmetic baud */ +# define USART_CTRLA_SAMPR_16XF (1 << USART_CTRLA_SAMPR_SHIFT) /* 16x oversampling; fractional baud */ +# define USART_CTRLA_SAMPR_8XA (2 << USART_CTRLA_SAMPR_SHIFT) /* 8x oversampling; arithmetic baud */ +# define USART_CTRLA_SAMPR_8XF (3 << USART_CTRLA_SAMPR_SHIFT) /* 8x oversampling; fractional baud */ +# define USART_CTRLA_SAMPR_3XA (4 << USART_CTRLA_SAMPR_SHIFT) /* 3x oversampling; arithmetic baud */ #define USART_CTRLA_TXPO_SHIFT (16) /* Bits 16-17: Transmit data pinout */ #define USART_CTRLA_TXPO_MASK (3 << USART_CTRLA_TXPO_SHIFT) # define USART_CTRLA_TXPAD0_1 (0 << USART_CTRLA_TXPO_SHIFT) /* TxD=SERCOM PAD[0]; XCK=PAD[1] */ diff --git a/arch/arm/src/samdl/sam_lowputc.c b/arch/arm/src/samdl/sam_lowputc.c index 755fc61add..f4d39b0307 100644 --- a/arch/arm/src/samdl/sam_lowputc.c +++ b/arch/arm/src/samdl/sam_lowputc.c @@ -132,6 +132,9 @@ sam_usart_configure(const struct sam_usart_config_s * const config) * * BAUD = 63,019 * Fbaud = 115,219 + * + * REVISIT: For the SAML21, only 16x sampling with arithmetic BAUD is + * supported. */ tmp = (uint64_t)config->baud << 20; diff --git a/arch/arm/src/samdl/sam_sercom.c b/arch/arm/src/samdl/sam_sercom.c index 8f5e713bbe..602e823265 100644 --- a/arch/arm/src/samdl/sam_sercom.c +++ b/arch/arm/src/samdl/sam_sercom.c @@ -45,6 +45,7 @@ #include #include +#include #include "up_arch.h" @@ -54,6 +55,8 @@ #include "sam_gclk.h" #include "sam_sercom.h" +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -145,7 +148,7 @@ void sercom_coreclk_configure(int sercom, int gclkgen, bool wrlock) void sercom_slowclk_configure(int gclkgen) { -#if defined(CONFIG_ARCH_FAMILY_SAMDL21) +#if defined(CONFIG_ARCH_FAMILY_SAML21) static bool configured = false; #ifdef CONFIG_DEBUG static uint8_t slowgen = 0xff; @@ -165,7 +168,7 @@ void sercom_slowclk_configure(int gclkgen) configured = true; #ifdef CONFIG_DEBUG - slowgen = (uint8_t)clkgen; + slowgen = (uint8_t)gclkgen; #endif } @@ -176,7 +179,7 @@ void sercom_slowclk_configure(int gclkgen) else { - DEBUGASSERT((int)slowgen == clkgen); + DEBUGASSERT((int)slowgen == gclkgen); } #endif