[sam] LED Blink test app working on Arduino Due

This commit is contained in:
Thibaut VIARD 2011-09-13 18:12:51 +02:00
parent 6f2d59ed2f
commit 80d5368b52
9 changed files with 61 additions and 34 deletions

View File

@ -1,5 +1,5 @@
#VARIANTS = sam3s_ek sam3u_ek arduino_due #VARIANTS = sam3s_ek sam3u_ek arduino_due
VARIANTS = sam3u_ek VARIANTS = arduino_due
SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables

View File

@ -1,6 +1,3 @@
# Makefile for compiling libboard
BOARD =
SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

@ -1,11 +1,21 @@
# Makefile for compiling libArduino # Makefile for compiling libArduino
.SUFFIXES: .o .a .c .s .SUFFIXES: .o .a .c .s
#CHIP=__SAM3S4C__ # putting default variant
CHIP=__SAM3U4E__ ifeq ("$(VARIANT)", "")
#VARIANT=sam3s_ek #VARIANT=sam3s_ek
VARIANT=sam3u_ek #VARIANT=sam3u_ek
#VARIANT=arduino_due VARIANT=arduino_due
endif
ifeq ("$(VARIANT)", "sam3s_ek")
CHIP=__SAM3S4C__
else ifeq ("$(VARIANT)", "sam3u_ek")
CHIP=__SAM3U4E__
else ifeq ("$(VARIANT)", "arduino_due")
CHIP=__SAM3U4E__
endif
TOOLCHAIN=gcc TOOLCHAIN=gcc
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

@ -11,9 +11,9 @@ void setup( void )
pinMode( PIN_LED, OUTPUT ) ; pinMode( PIN_LED, OUTPUT ) ;
digitalWrite( PIN_LED, LOW ) ; digitalWrite( PIN_LED, LOW ) ;
// Initialize the PIN_LED_GREEN digital pin as an output. // Initialize the PIN_LED2 digital pin as an output.
pinMode( PIN_LED_GREEN, OUTPUT ) ; pinMode( PIN_LED2, OUTPUT ) ;
digitalWrite( PIN_LED_GREEN, HIGH ) ; digitalWrite( PIN_LED2, HIGH ) ;
Serial.begin( 19200 ) ; Serial.begin( 19200 ) ;
} }
@ -21,10 +21,10 @@ void setup( void )
void loop( void ) void loop( void )
{ {
digitalWrite( PIN_LED, HIGH ) ; // set the LED on digitalWrite( PIN_LED, HIGH ) ; // set the LED on
digitalWrite( PIN_LED_GREEN, LOW ) ; // set the red LED off digitalWrite( PIN_LED2, LOW ) ; // set the red LED off
delay( 1000 ) ; // wait for a second delay( 1000 ) ; // wait for a second
digitalWrite( PIN_LED, LOW ) ; // set the LED off digitalWrite( PIN_LED, LOW ) ; // set the LED off
digitalWrite( PIN_LED_GREEN, HIGH ) ; // set the red LED on digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on
delay( 1000 ) ; // wait for a second delay( 1000 ) ; // wait for a second
// Serial.write( '*' ) ; // send an initial char // Serial.write( '*' ) ; // send an initial char

View File

@ -210,10 +210,20 @@ typedef struct {
/* -------- PMC_PCK[3] : (PMC Offset: 0x0040) Programmable Clock 0 Register -------- */ /* -------- PMC_PCK[3] : (PMC Offset: 0x0040) Programmable Clock 0 Register -------- */
#define PMC_PCK_CSS_Pos 0 #define PMC_PCK_CSS_Pos 0
#define PMC_PCK_CSS_Msk (0x7u << PMC_PCK_CSS_Pos) /**< \brief (PMC_PCK[3]) Master Clock Source Selection */ #define PMC_PCK_CSS_Msk (0x7u << PMC_PCK_CSS_Pos) /**< \brief (PMC_PCK[3]) Master Clock Source Selection */
#define PMC_PCK_CSS(value) ((PMC_PCK_CSS_Msk & ((value) << PMC_PCK_CSS_Pos))) #define PMC_PCK_CSS_SLOW_CLK (0x0u << 0) /**< \brief (PMC_PCK[3]) Slow Clock is selected */
#define PMC_PCK_CSS_MAIN_CLK (0x1u << 0) /**< \brief (PMC_PCK[3]) Main Clock is selected */
#define PMC_PCK_CSS_PLLA_CLK (0x2u << 0) /**< \brief (PMC_PCK[3]) PLLA Clock is selected */
#define PMC_PCK_CSS_PLLB_CLK (0x3u << 0) /**< \brief (PMC_PCK[3]) PLLB Clock is selected */
#define PMC_PCK_CSS_MCK (0x4u << 0) /**< \brief (PMC_PCK[3]) Master Clock is selected */
#define PMC_PCK_PRES_Pos 4 #define PMC_PCK_PRES_Pos 4
#define PMC_PCK_PRES_Msk (0x7u << PMC_PCK_PRES_Pos) /**< \brief (PMC_PCK[3]) Programmable Clock Prescaler */ #define PMC_PCK_PRES_Msk (0x7u << PMC_PCK_PRES_Pos) /**< \brief (PMC_PCK[3]) Processor Clock Prescaler */
#define PMC_PCK_PRES(value) ((PMC_PCK_PRES_Msk & ((value) << PMC_PCK_PRES_Pos))) #define PMC_PCK_PRES_CLK (0x0u << 4) /**< \brief (PMC_PCK[3]) Selected clock */
#define PMC_PCK_PRES_CLK_2 (0x1u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 2 */
#define PMC_PCK_PRES_CLK_4 (0x2u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 4 */
#define PMC_PCK_PRES_CLK_8 (0x3u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 8 */
#define PMC_PCK_PRES_CLK_16 (0x4u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 16 */
#define PMC_PCK_PRES_CLK_32 (0x5u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 32 */
#define PMC_PCK_PRES_CLK_64 (0x6u << 4) /**< \brief (PMC_PCK[3]) Selected clock divided by 64 */
/* -------- PMC_IER : (PMC Offset: 0x0060) Interrupt Enable Register -------- */ /* -------- PMC_IER : (PMC Offset: 0x0060) Interrupt Enable Register -------- */
#define PMC_IER_MOSCXTS (0x1u << 0) /**< \brief (PMC_IER) Main Crystal Oscillator Status Interrupt Enable */ #define PMC_IER_MOSCXTS (0x1u << 0) /**< \brief (PMC_IER) Main Crystal Oscillator Status Interrupt Enable */
#define PMC_IER_LOCKA (0x1u << 1) /**< \brief (PMC_IER) PLL A Lock Interrupt Enable */ #define PMC_IER_LOCKA (0x1u << 1) /**< \brief (PMC_IER) PLL A Lock Interrupt Enable */

View File

@ -25,13 +25,13 @@ extern "C" {
/**INDENT-ON**/ /**INDENT-ON**/
/* @endcond */ /* @endcond */
/* Clock settings (48MHz) */ /* Clock settings (96MHz) */
#define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST(0x8)) #define BOARD_OSCOUNT (CKGR_MOR_MOSCXTST(0x8))
#define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \ #define BOARD_PLLAR (CKGR_PLLAR_STUCKTO1 \
| CKGR_PLLAR_MULA(0x7) \ | CKGR_PLLAR_MULA(0x7) \
| CKGR_PLLAR_PLLACOUNT(0x3f) \ | CKGR_PLLAR_PLLACOUNT(0x3f) \
| CKGR_PLLAR_DIVA(0x1)) | CKGR_PLLAR_DIVA(0x1))
#define BOARD_MCKR (PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK) #define BOARD_MCKR (PMC_MCKR_PRES_CLK | PMC_MCKR_CSS_PLLA_CLK)
/* Clock Definitions */ /* Clock Definitions */
#define XTAL32 ( 32768UL) /* 32k crystal frequency */ #define XTAL32 ( 32768UL) /* 32k crystal frequency */

View File

@ -18,7 +18,7 @@
*/ */
typedef enum _EPioType typedef enum _EPioType
{ {
PIO_NOT_A_PIN, /* The pin is controlled by the associated signal of peripheral A. */ PIO_NOT_A_PIN, /* Not under control of a peripheral. */
PIO_PERIPH_A, /* The pin is controlled by the associated signal of peripheral A. */ PIO_PERIPH_A, /* The pin is controlled by the associated signal of peripheral A. */
PIO_PERIPH_B, /* The pin is controlled by the associated signal of peripheral B. */ PIO_PERIPH_B, /* The pin is controlled by the associated signal of peripheral B. */
#if (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_) #if (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_)

View File

@ -152,9 +152,12 @@ RingBuffer rx_buffer2 ;
RingBuffer tx_buffer2 ; RingBuffer tx_buffer2 ;
RingBuffer rx_buffer3 ; RingBuffer rx_buffer3 ;
RingBuffer tx_buffer3 ; RingBuffer tx_buffer3 ;
RingBuffer rx_buffer4 ;
RingBuffer tx_buffer4 ;
USARTClass Serial2( USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2 ) ; USARTClass Serial2( USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2 ) ;
USARTClass Serial3( USART1, USART1_IRQn, ID_USART1, &rx_buffer3, &tx_buffer3 ) ; USARTClass Serial3( USART1, USART1_IRQn, ID_USART1, &rx_buffer3, &tx_buffer3 ) ;
USARTClass Serial4( USART2, USART2_IRQn, ID_USART2, &rx_buffer4, &tx_buffer4 ) ;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -171,6 +174,11 @@ extern void USART1_IrqHandler( void )
Serial3.IrqHandler() ; Serial3.IrqHandler() ;
} }
extern void USART2_IrqHandler( void )
{
Serial4.IrqHandler() ;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -198,14 +206,9 @@ extern void init( void )
/* Disable watchdog, common to all SAM variants */ /* Disable watchdog, common to all SAM variants */
WDT_Disable( WDT ) ; WDT_Disable( WDT ) ;
// Initialize Serial port UART0, common to all SAM3 variants // Initialize Serial port UART, common to all SAM3 variants
PIO_Configure( g_APinDescription[PINS_UART].pPort, g_APinDescription[PINS_UART].ulPinType, PIO_Configure( g_APinDescription[PINS_UART].pPort, g_APinDescription[PINS_UART].ulPinType,
g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinAttribute ) ; g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinAttribute ) ;
// Switch off Power LED
PIO_Configure( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPinType,
g_APinDescription[PIN_LED_RED].ulPin, g_APinDescription[PIN_LED_RED].ulPinAttribute ) ;
PIO_Clear( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPin ) ;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -48,17 +48,23 @@
* Pins * Pins
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
#define PIN_LED_BLUE (0u) #define PIN_LED_13 (0u)
#define PIN_LED_GREEN (1u) #define PIN_LED_RXL (1u)
#define PIN_LED_RED (2u) #define PIN_LED_TXL (2u)
#define PIN_LED PIN_LED_BLUE #define PIN_LED PIN_LED_13
#define PIN_LED2 PIN_LED_RXL
#define PIN_LED3 PIN_LED_TXL
static const uint8_t SS = 23 ; static const uint8_t SS = 15 ;
static const uint8_t MOSI = 21 ; static const uint8_t MOSI = 13 ;
static const uint8_t MISO = 20 ; static const uint8_t MISO = 12 ;
static const uint8_t SCK = 22 ; static const uint8_t SCK = 14 ;
#define PINS_UART (6u) #define PINS_UART (5u)
#define PINS_USART0 (5u)
#define PINS_USART1 (5u)
#define PINS_USART2 (5u)
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
* Arduino objects - C++ only * Arduino objects - C++ only
@ -70,6 +76,7 @@ extern UARTClass Serial ;
extern USARTClass Serial2 ; extern USARTClass Serial2 ;
extern USARTClass Serial3 ; extern USARTClass Serial3 ;
extern USARTClass Serial4 ;
#endif #endif