From e034de5ea9c553651ccb09620d8447f3f25c0cda Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Sat, 28 Apr 2012 17:36:57 +0200 Subject: [PATCH] [SAM] Added SAM3X_EK support for USB debug --- .../arduino/sam/cores/sam/build_gcc/Makefile | 6 +-- .../sam/build_gcc/libarduino_sam3x_ek.mk | 2 +- .../cores/sam/validation/build_gcc/test.mk | 19 +++---- .../arduino/sam/cores/sam/validation/test.cpp | 10 +++- .../arduino/sam/cores/sam/wiring_analog.c | 2 +- .../debug_scripts/gcc/arduino_due_flash.gdb | 2 + .../sam/variants/arduino_due_x/variant.h | 6 +-- .../sam3x_ek/build_gcc/libvariant_sam3x_ek.mk | 10 ++-- .../sam3x_ek/linker_scripts/gcc/flash.ld | 54 +++++++++---------- .../atmel/sam/variants/sam3x_ek/variant.cpp | 25 +++++---- .../atmel/sam/variants/sam3x_ek/variant.h | 29 ++++++++-- 11 files changed, 97 insertions(+), 68 deletions(-) diff --git a/hardware/arduino/sam/cores/sam/build_gcc/Makefile b/hardware/arduino/sam/cores/sam/build_gcc/Makefile index 517f509ad..53d2db633 100644 --- a/hardware/arduino/sam/cores/sam/build_gcc/Makefile +++ b/hardware/arduino/sam/cores/sam/build_gcc/Makefile @@ -1,6 +1,6 @@ ifeq ("$(VARIANTS)", "") -VARIANTS = arduino_due_x arduino_due_u -#VARIANTS = sam3u_ek sam3s_ek sam3x_ek +VARIANTS = arduino_due_x arduino_due_u sam3x_ek +#VARIANTS = sam3u_ek sam3s_ek endif SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables @@ -11,7 +11,7 @@ SUBMAKE_OPTIONS=--no-builtin-rules --no-builtin-variables all: $(VARIANTS) -.PHONY: sam3s_ek +.PHONY: sam3s_ek sam3s_ek: @echo --- Making sam3s_ek @$(MAKE) DEBUG=1 $(SUBMAKE_OPTIONS) -f libarduino_sam3s_ek.mk diff --git a/hardware/arduino/sam/cores/sam/build_gcc/libarduino_sam3x_ek.mk b/hardware/arduino/sam/cores/sam/build_gcc/libarduino_sam3x_ek.mk index 7eabc0c37..81b688172 100644 --- a/hardware/arduino/sam/cores/sam/build_gcc/libarduino_sam3x_ek.mk +++ b/hardware/arduino/sam/cores/sam/build_gcc/libarduino_sam3x_ek.mk @@ -39,7 +39,7 @@ CMSIS_ROOT_PATH = $(SYSTEM_PATH)/CMSIS CMSIS_ARM_PATH=$(CMSIS_ROOT_PATH)/CMSIS/Include CMSIS_ATMEL_PATH=$(CMSIS_ROOT_PATH)/Device/ATMEL CMSIS_CHIP_PATH=$(CMSIS_ROOT_PATH)/Device/ATMEL/$(CHIP_SERIE) -VARIANT_PATH = ../../../variants/$(VARIANT) +VARIANT_PATH = ../../../../../atmel/sam/variants/$(VARIANT) #------------------------------------------------------------------------------- # Files diff --git a/hardware/arduino/sam/cores/sam/validation/build_gcc/test.mk b/hardware/arduino/sam/cores/sam/validation/build_gcc/test.mk index 283c19206..f4c08a79f 100644 --- a/hardware/arduino/sam/cores/sam/validation/build_gcc/test.mk +++ b/hardware/arduino/sam/cores/sam/validation/build_gcc/test.mk @@ -8,7 +8,7 @@ # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public @@ -23,18 +23,19 @@ ifeq ("$(VARIANT)", "") #VARIANT=sam3s_ek #VARIANT=sam3u_ek -VARIANT=arduino_due_x +VARIANT=sam3x_ek +#VARIANT=arduino_due_x endif ifeq ("$(VARIANT)", "sam3s_ek") CHIP=__SAM3S4C__ -VARIANT_PATH = ../../../../atmel/sam/variants/$(VARIANT) +VARIANT_PATH = ../../../../../../atmel/sam/variants/$(VARIANT) else ifeq ("$(VARIANT)", "sam3u_ek") CHIP=__SAM3U4E__ -VARIANT_PATH = ../../../../atmel/sam/variants/$(VARIANT) +VARIANT_PATH = ../../../../../../atmel/sam/variants/$(VARIANT) else ifeq ("$(VARIANT)", "sam3x_ek") CHIP=__SAM3X8H__ -VARIANT_PATH = ../../../../atmel/sam/variants/$(VARIANT) +VARIANT_PATH = ../../../../../../atmel/sam/variants/$(VARIANT) else ifeq ("$(VARIANT)", "arduino_due_u") CHIP=__SAM3U4E__ VARIANT_PATH = ../../../../variants/$(VARIANT) @@ -153,7 +154,7 @@ test: create_output libsam_$(CHIP_NAME)_$(TOOLCHAIN)_$(LIBS_POSTFIX).a libarduin .PHONY: create_output create_output: - @echo --- Preparing $(VARIANT) files in $(OUTPUT_PATH) $(OUTPUT_BIN) + @echo --- Preparing $(VARIANT) files in $(OUTPUT_PATH) $(OUTPUT_BIN) # @echo ------------------------- # @echo *$(INCLUDES) # @echo ------------------------- @@ -190,11 +191,11 @@ $(OUTPUT_BIN): $(addprefix $(OUTPUT_PATH)/, $(C_OBJ)) $(addprefix $(OUTPUT_PATH) clean: @echo --- Cleaning test files -@$(RM) $(OUTPUT_PATH) 1>NUL 2>&1 - + # -$(RM) $(OUTPUT_PATH)/test.o -# -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).elf +# -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).elf # -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).elf.txt -# -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).bin +# -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).bin # -$(RM) $(OUTPUT_PATH)/$(OUTPUT_BIN).map debug: test diff --git a/hardware/arduino/sam/cores/sam/validation/test.cpp b/hardware/arduino/sam/cores/sam/validation/test.cpp index 5e581f88a..f3fab045a 100644 --- a/hardware/arduino/sam/cores/sam/validation/test.cpp +++ b/hardware/arduino/sam/cores/sam/validation/test.cpp @@ -8,7 +8,7 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public @@ -18,6 +18,12 @@ #include "variant.h" +#ifdef _VARIANT_SAM3X_EK_ +#define MAX_ANALOG A0 +#elif _VARIANT_ARDUINO_DUE_X_ +#define MAX_ANALOG A10 +#endif + void setup( void ) { // Initialize the digital pin as an output. @@ -80,7 +86,7 @@ void loop( void ) // Serial1.write( "test2" ) ; // send another string Serial1.print("Analog ins: "); - for (int i=A0; i "$(OUTPUT_BIN)/$@.txt" + "$(AR)" -v -r "$(OUTPUT_BIN)/$@" $^ + "$(NM)" "$(OUTPUT_BIN)/$@" > "$(OUTPUT_BIN)/$@.txt" .PHONY: clean diff --git a/hardware/atmel/sam/variants/sam3x_ek/linker_scripts/gcc/flash.ld b/hardware/atmel/sam/variants/sam3x_ek/linker_scripts/gcc/flash.ld index c79e630a5..8d652b606 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/linker_scripts/gcc/flash.ld +++ b/hardware/atmel/sam/variants/sam3x_ek/linker_scripts/gcc/flash.ld @@ -1,12 +1,12 @@ /* ---------------------------------------------------------------------------- - * ATMEL Microcontroller Software Support + * SAM Software Package License * ---------------------------------------------------------------------------- - * Copyright (c) 2009, Atmel Corporation + * Copyright (c) 2012, Atmel Corporation * * All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * modification, are permitted provided that the following condition is met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the disclaimer below. @@ -27,10 +27,6 @@ * ---------------------------------------------------------------------------- */ -/*------------------------------------------------------------------------------ - * Linker script for running in internal FLASH on the SAM3U4 - *----------------------------------------------------------------------------*/ - OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) SEARCH_DIR(.) @@ -38,22 +34,20 @@ SEARCH_DIR(.) /* Memory Spaces Definitions */ MEMORY { - flash0 (W!RX) : ORIGIN = 0x00080000, LENGTH = 0x00020000 /* Flash0, 128K */ - flash1 (W!RX) : ORIGIN = 0x00100000, LENGTH = 0x00020000 /* Flash1, 128K */ - sram0 (W!RX) : ORIGIN = 0x20000000, LENGTH = 0x00008000 /* Sram0, 32K */ - sram1 (W!RX) : ORIGIN = 0x20080000, LENGTH = 0x00004000 /* Sram1, 16K */ - rom (rx) : ORIGIN = ORIGIN(flash1)-LENGTH(flash0), LENGTH = LENGTH(flash0)+LENGTH(flash1) /* Flash, 256K */ - ram (rwx) : ORIGIN = ORIGIN( sram1)-LENGTH( sram0), LENGTH = LENGTH( sram0)+LENGTH( sram1) /* sram, 48K */ + rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K */ + sram0 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 /* sram0, 64K */ + sram1 (rwx) : ORIGIN = 0x20080000, LENGTH = 0x00008000 /* sram1, 32K */ + ram (rwx) : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */ } /* The stack size used by the application. NOTE: you need to adjust */ -STACK_SIZE = 0x2000; +STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 0x2000 ; -/* Section Definitions */ -SECTIONS -{ - .text : - { +/* Section Definitions */ +SECTIONS +{ + .text : + { . = ALIGN(4); _sfixed = .; KEEP(*(.vectors .vectors.*)) @@ -99,17 +93,17 @@ SECTIONS . = ALIGN(4); _efixed = .; /* End of text section */ - } > flash0 + } > rom /* .ARM.exidx is sorted, so has to go in its own output section. */ PROVIDE_HIDDEN (__exidx_start = .); .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > flash0 + } > rom PROVIDE_HIDDEN (__exidx_end = .); - . = ALIGN(4); + . = ALIGN(4); _etext = .; .relocate : AT (_etext) @@ -120,11 +114,11 @@ SECTIONS *(.data .data.*); . = ALIGN(4); _erelocate = .; - } > sram0 + } > ram - /* .bss section which is used for uninitialized data */ + /* .bss section which is used for uninitialized data */ .bss (NOLOAD) : - { + { . = ALIGN(4); _sbss = . ; _szero = .; @@ -133,18 +127,18 @@ SECTIONS . = ALIGN(4); _ebss = . ; _ezero = .; - } > sram0 + } > ram /* stack section */ .stack (NOLOAD): { . = ALIGN(8); - _sstack = .; + _sstack = .; . = . + STACK_SIZE; . = ALIGN(8); _estack = .; - } > sram1 + } > ram - . = ALIGN(4); - _end = . ; + . = ALIGN(4); + _end = . ; } diff --git a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp index c1fc7ef63..285d178f5 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp +++ b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp @@ -51,22 +51,27 @@ extern const PinDescription g_APinDescription[]= // 0/1 - UART (Serial) { PIOA, PIO_PA8A_URXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // URXD { PIOA, PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // UTXD - + // 2/5 - LEDS { PIOB, PIO_PB13, ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // USER_LED1 { PIOB, PIO_PB12, ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // USER_LED2 { PIOA, PIO_PA12, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // USER_LED3 { PIOA, PIO_PA13, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // POWER_LED - // USART0 (Serial2) + // 6/7 - USART0 (Serial2) { PIOA, PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // URXD { PIOA, PIO_PA11A_TXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // UTXD - // x .. x - "All pins" masks - // x - UART (Serial) all pins + // 8 - UART (Serial) all pins { PIOA, PIO_PA8A_URXD|PIO_PA9A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NO_PWM, NO_TC }, - // x - USART0 (Serial2) all pins + + // 9 - USART0 (Serial2) all pins { PIOA, PIO_PA11A_TXD0|PIO_PA10A_RXD0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NO_PWM, NO_TC }, + + // 10 - Analog pins + // ---------------------- + { PIOA, PIO_PA3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC7, NO_PWM, NO_TC }, // AD0 + { NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC } // END } ; @@ -75,12 +80,12 @@ extern const PinDescription g_APinDescription[]= */ RingBuffer rx_buffer1 ; -UARTClass Serial( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ; +UARTClass Serial1( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ; // IT handlers void UART_Handler(void) { - Serial.IrqHandler() ; + Serial1.IrqHandler() ; } // ---------------------------------------------------------------------------- @@ -137,11 +142,11 @@ extern void init( void ) g_APinDescription[PINS_USART0].ulPinConfiguration ) ; // Switch off Power LED - PIO_Configure( g_APinDescription[PIN_LED_RED].pPort, + 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].ulPin, g_APinDescription[PIN_LED_RED].ulPinConfiguration ) ; - + PIO_Clear( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPin ) ; } #ifdef __cplusplus diff --git a/hardware/atmel/sam/variants/sam3x_ek/variant.h b/hardware/atmel/sam/variants/sam3x_ek/variant.h index baae7d174..43f375778 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/variant.h +++ b/hardware/atmel/sam/variants/sam3x_ek/variant.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _VARIANT_SAM3U_EK_ -#define _VARIANT_SAM3U_EK_ +#ifndef _VARIANT_SAM3X_EK_ +#define _VARIANT_SAM3X_EK_ /*---------------------------------------------------------------------------- * Headers @@ -86,18 +86,39 @@ #define PINS_USART0 (9u) +/* + * Analog pins + */ +static const uint8_t A0 = 10; +/* + * PWM + */ +#define PWM_INTERFACE PWM +#define PWM_INTERFACE_ID ID_PWM +#define PWM_FREQUENCY 1000 +#define PWM_MAX_DUTY_CYCLE 255 +#define PWM_MIN_DUTY_CYCLE 0 + +/* + * TC + */ +#define TC_INTERFACE TC0 +#define TC_INTERFACE_ID ID_TC0 +#define TC_FREQUENCY 1000 +#define TC_MAX_DUTY_CYCLE 255 +#define TC_MIN_DUTY_CYCLE 0 /*---------------------------------------------------------------------------- * Arduino objects - C++ only *----------------------------------------------------------------------------*/ #ifdef __cplusplus -extern UARTClass Serial ; +extern UARTClass Serial1 ; extern USARTClass Serial2 ; #endif -#endif /* _VARIANT_SAM3U_EK_ */ +#endif /* _VARIANT_SAM3X_EK_ */