From 373c0096c30b0eef24a3a6b5f1b7f3b0aa0cdcbc Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Sat, 28 Apr 2012 19:56:36 +0200 Subject: [PATCH 1/3] [SAM] Updating debug scripts --- .../debug_scripts/gcc/arduino_due_flash.gdb | 20 ++++---- .../debug_scripts/gcc/arduino_due_sram.gdb | 46 ++++++++++++------- .../debug_scripts/gcc/sam3x_ek_flash.gdb | 20 ++++---- .../debug_scripts/gcc/sam3x_ek_sram.gdb | 22 ++++++--- 4 files changed, 69 insertions(+), 39 deletions(-) diff --git a/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_flash.gdb b/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_flash.gdb index a0fb3fd20..4e8375b5f 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_flash.gdb +++ b/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_flash.gdb @@ -1,33 +1,37 @@ #******************************************************* # -# Connect to J-Link and debug application in flash. +# Connect to J-Link and debug application in flash on SAM3X. # -# define 'reset' command +# Define 'reset' command define reset # Connect to the J-Link gdb server target remote localhost:2331 + # Reset the chip to get to a known state monitor reset # Select flash device -monitor flash device = AT91SAM3U4E +monitor flash device = AT91SAM3X8E + # Enable flash download and flash breakpoints monitor flash download = 1 + # Load the program load -# Reset peripheral (RSTC_CR) -set *0x400e1200 = 0xA5000004 +# Reset peripheral (RSTC_CR) +set *0x400e1a00 = 0xA5000004 -# Initializing PC and stack pointer +# Initialize PC and stack pointer mon reg sp=(0x80000) -set *0x80004 = *0x80004 & 0xFFFFFFFE +#set *0x80004 = *0x80004 & 0xFFFFFFFE mon reg pc=(0x80004) + info reg break main -# end of 'reset' command +# End of 'reset' command end diff --git a/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_sram.gdb b/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_sram.gdb index c7cc015ba..15a1792a9 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_sram.gdb +++ b/hardware/arduino/sam/variants/arduino_due_x/debug_scripts/gcc/arduino_due_sram.gdb @@ -1,23 +1,37 @@ -#************************************************* +#******************************************************* # -# Connect to J-Link and debug application in sram on SAM3U +# Connect to J-Link and debug application in sram on SAM3X. # -# Note: -# First,users should do Step1 and Step2 according to your project, -# then do Step3. -# Step1: Connect to the J-Link gdb server -#target remote localhost:2331 -#mon reset +# Define 'reset' command +define reset -# Step2: Load file(eg. getting-started project) -#load bin/basic-dhrystone-project-at91sam3u-ek-at91sam3u4-sram.elf -#symbol-file bin/basic-dhrystone-project-at91sam3u-ek-at91sam3u4-sram.elf +# Connect to the J-Link gdb server +target remote localhost:2331 -# Step3: Initializing PC and stack pointer -# Perpheral reset RSTC_CR -set *0x400e1200 = 0xA5000004 -# Modify pc value to even before writing pc register +# Reset the chip to get to a known state +monitor reset + +# Select flash device +monitor flash device = AT91SAM3X8E + +# Enable flash download and flash breakpoints +monitor flash download = 1 + +# Load the program +load + +# Reset peripheral (RSTC_CR) +set *0x400e1a00 = 0xA5000004 + +# Initialize PC and stack pointer mon reg sp=(0x20000000) -set *0x20000004 = *0x20000004 & 0xFFFFFFFE +#set *0x20000004 = *0x20000004 & 0xFFFFFFFE mon reg pc=(0x20000004) + +info reg + +break main + +# End of 'reset' command +end diff --git a/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_flash.gdb b/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_flash.gdb index a0fb3fd20..caf3b3cee 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_flash.gdb +++ b/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_flash.gdb @@ -1,33 +1,37 @@ #******************************************************* # -# Connect to J-Link and debug application in flash. +# Connect to J-Link and debug application in flash on SAM3X. # -# define 'reset' command +# Define 'reset' command define reset # Connect to the J-Link gdb server target remote localhost:2331 + # Reset the chip to get to a known state monitor reset # Select flash device -monitor flash device = AT91SAM3U4E +monitor flash device = AT91SAM3X8H + # Enable flash download and flash breakpoints monitor flash download = 1 + # Load the program load -# Reset peripheral (RSTC_CR) -set *0x400e1200 = 0xA5000004 +# Reset peripheral (RSTC_CR) +set *0x400e1a00 = 0xA5000004 -# Initializing PC and stack pointer +# Initialize PC and stack pointer mon reg sp=(0x80000) -set *0x80004 = *0x80004 & 0xFFFFFFFE +#set *0x80004 = *0x80004 & 0xFFFFFFFE mon reg pc=(0x80004) + info reg break main -# end of 'reset' command +# End of 'reset' command end diff --git a/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_sram.gdb b/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_sram.gdb index 5fa44e23c..595b46b6c 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_sram.gdb +++ b/hardware/atmel/sam/variants/sam3x_ek/debug_scripts/gcc/sam3x_ek_sram.gdb @@ -1,29 +1,37 @@ #******************************************************* # -# Connect to J-Link and debug application in flash. +# Connect to J-Link and debug application in sram on SAM3X. # -# define 'reset' command +# Define 'reset' command define reset # Connect to the J-Link gdb server target remote localhost:2331 + # Reset the chip to get to a known state monitor reset +# Select flash device +monitor flash device = AT91SAM3X8H + +# Enable flash download and flash breakpoints +monitor flash download = 1 + # Load the program load -# Reset peripheral (RSTC_CR) -set *0x400e1200 = 0xA5000004 +# Reset peripheral (RSTC_CR) +set *0x400e1a00 = 0xA5000004 -# Initializing PC and stack pointer +# Initialize PC and stack pointer mon reg sp=(0x20000000) -set *0x20000004 = *0x20000004 & 0xFFFFFFFE +#set *0x20000004 = *0x20000004 & 0xFFFFFFFE mon reg pc=(0x20000004) + info reg break main -# end of 'reset' command +# End of 'reset' command end From fc82f1e556141a6737e391303b8f722df42d85f6 Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Sat, 28 Apr 2012 19:58:40 +0200 Subject: [PATCH 2/3] [SAM] Fixing SysTick handler issue --- hardware/arduino/sam/cores/sam/main.cpp | 9 +++++++++ hardware/arduino/sam/cores/sam/wiring.c | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/sam/cores/sam/main.cpp b/hardware/arduino/sam/cores/sam/main.cpp index 7888c4cb9..4c6b43a0d 100644 --- a/hardware/arduino/sam/cores/sam/main.cpp +++ b/hardware/arduino/sam/cores/sam/main.cpp @@ -19,6 +19,15 @@ #define ARDUINO_MAIN #include "Arduino.h" +/* + * Cortex-M3 Systick IT handler + */ +extern void SysTick_Handler( void ) +{ + // Increment tick count each ms + TimeTick_Increment() ; +} + /* * \brief Main entry point of Arduino application */ diff --git a/hardware/arduino/sam/cores/sam/wiring.c b/hardware/arduino/sam/cores/sam/wiring.c index e0d9dbbd8..4e88e2752 100644 --- a/hardware/arduino/sam/cores/sam/wiring.c +++ b/hardware/arduino/sam/cores/sam/wiring.c @@ -55,13 +55,13 @@ void delayMicroseconds( uint32_t dwUs ) } /* - * Cortex-M3 Systick IT handler + * Cortex-M3 Systick IT handler: MOVED TO MAIN DUE TO WEAK SYMBOL ISSUE NOT RESOLVED */ -extern void SysTick_Handler( void ) +/*extern void SysTick_Handler( void ) { // Increment tick count each ms TimeTick_Increment() ; -} +}*/ #if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ extern signed int putchar( signed int c ) ; From 1d994297521f5c69f2f4abaa78483033dd6d214a Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Sat, 28 Apr 2012 19:59:24 +0200 Subject: [PATCH 3/3] [SAM] Test app working on SAM3X-EK --- hardware/arduino/sam/cores/sam/Arduino.h | 6 +++--- .../arduino/sam/cores/sam/validation/test.cpp | 2 +- .../atmel/sam/variants/sam3x_ek/variant.cpp | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/hardware/arduino/sam/cores/sam/Arduino.h b/hardware/arduino/sam/cores/sam/Arduino.h index 970ac0ad0..a31492fb7 100644 --- a/hardware/arduino/sam/cores/sam/Arduino.h +++ b/hardware/arduino/sam/cores/sam/Arduino.h @@ -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 @@ -175,8 +175,8 @@ typedef struct _PinDescription EPioType ulPinType ; uint32_t ulPinConfiguration ; uint32_t ulPinAttribute ; - EAnalogChannel ulAnalogChannel ; /* Describe which Analog pin is linked to a MCU pin */ - EAnalogChannel ulADCChannelNumber ; /* We use the same enum than for ADC pins to describe the ADC channel in use on this pin */ + EAnalogChannel ulAnalogChannel ; /* Analog pin in the Arduino context (label on the board) */ + EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ EPWMChannel ulPWMChannel ; ETCChannel ulTCChannel ; } PinDescription ; diff --git a/hardware/arduino/sam/cores/sam/validation/test.cpp b/hardware/arduino/sam/cores/sam/validation/test.cpp index f3fab045a..f4f67e4b9 100644 --- a/hardware/arduino/sam/cores/sam/validation/test.cpp +++ b/hardware/arduino/sam/cores/sam/validation/test.cpp @@ -85,7 +85,7 @@ void loop( void ) // Serial1.write( "test1\n" ) ; // send a string // Serial1.write( "test2" ) ; // send another string - Serial1.print("Analog ins: "); + Serial1.print("Analog pins: "); for (int i=A0; i<=MAX_ANALOG; i++) { int a = analogRead(i); Serial1.print(a, DEC); diff --git a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp index 285d178f5..b1c03af63 100644 --- a/hardware/atmel/sam/variants/sam3x_ek/variant.cpp +++ b/hardware/atmel/sam/variants/sam3x_ek/variant.cpp @@ -70,7 +70,7 @@ extern const PinDescription g_APinDescription[]= // 10 - Analog pins // ---------------------- - { PIOA, PIO_PA3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC7, NO_PWM, NO_TC }, // AD0 + { PIOA, PIO_PA3, ID_PIOA, PIO_INPUT, PIO_DEFAULT, PIN_ATTR_ANALOG, ADC0, ADC1, 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 } ; @@ -109,9 +109,6 @@ void USART0_Handler( void ) extern "C" { #endif -// Should be made in a better way... -extern void analogOutputInit(void); - /** * */ @@ -148,6 +145,18 @@ extern void init( void ) g_APinDescription[PIN_LED_RED].ulPinConfiguration ) ; PIO_Clear( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPin ) ; + + // Initialize 10bit Analog Controller + pmc_enable_periph_clk( ID_ADC ) ; + adc_init( ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST ) ; + adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); + adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. + adc_disable_interrupt( ADC, 0xFFFFFFFF ) ; // Disable all ADC interrupts. + adc_disable_all_channel( ADC ) ; + + // Initialize analogOutput module + analogOutputInit(); + } #ifdef __cplusplus }