diff --git a/hardware/sam/cores/sam/validation/build_gcc/test.mk b/hardware/sam/cores/sam/validation/build_gcc/test.mk index c47cb25a5..e64349433 100644 --- a/hardware/sam/cores/sam/validation/build_gcc/test.mk +++ b/hardware/sam/cores/sam/validation/build_gcc/test.mk @@ -22,8 +22,8 @@ # putting default variant ifeq ("$(VARIANT)", "") #VARIANT=sam3s_ek -VARIANT=sam3u_ek -#VARIANT=arduino_due +#VARIANT=sam3u_ek +VARIANT=arduino_due endif ifeq ("$(VARIANT)", "sam3s_ek") diff --git a/hardware/sam/cores/sam/wiring_analog.c b/hardware/sam/cores/sam/wiring_analog.c index 825eb3176..da655f497 100644 --- a/hardware/sam/cores/sam/wiring_analog.c +++ b/hardware/sam/cores/sam/wiring_analog.c @@ -33,15 +33,12 @@ void analogReference( eAnalogReference ulMode ) uint32_t analogRead( uint32_t ulPin ) { - uint32_t ulValue ; + uint32_t ulValue=0 ; uint32_t ulChannel ; ulChannel=g_APinDescription[ulPin].ulAnalogChannel ; -#if defined sam3u_ek -#elif defined sam3s_ek -#elif defined arduino_due - +#if defined SAM3U4E switch ( ulChannel ) { // Handling ADC 10 bits channels @@ -53,10 +50,23 @@ uint32_t analogRead( uint32_t ulPin ) case ADC5 : case ADC6 : case ADC7 : + // Enable the corresponding channel adc_enable_channel( ADC, ulChannel ) ; + + // Start the ADC adc_start( ADC ) ; - adc_get_value( ADC, ulChannel ) ; - adc_stop( ADC ) ; + + // Wait for end of conversion + while ( adc_get_status( ADC ) & (1<ADC_CHSR & (1 << adc_ch); } +/** + * \brief Reads the ADC status. + * + * \param p_adc Pointer to an ADC instance. + * + * \retval ADC status register content. + */ +uint32_t adc_get_status(Adc *p_adc) +{ + return p_adc->ADC_SR; +} + /** * \brief Reads the ADC result data of the specified channel. * diff --git a/hardware/sam/system/libsam/source/adc12_sam3u.c b/hardware/sam/system/libsam/source/adc12_sam3u.c index c2730f59e..8da95532c 100644 --- a/hardware/sam/system/libsam/source/adc12_sam3u.c +++ b/hardware/sam/system/libsam/source/adc12_sam3u.c @@ -179,11 +179,23 @@ void adc12_disable_channel(Adc12b *p_adc, adc_channel_num_t adc_ch) * \retval 1 means the specified channel is enabled. * 0 means the specified channel is disabled. */ -uint32_t adc12_get_status(Adc12b *p_adc, adc_channel_num_t adc_ch) +uint32_t adc12_get_channel_status(Adc12b *p_adc, adc_channel_num_t adc_ch) { return p_adc->ADC12B_CHSR & (1 << adc_ch); } +/** + * \brief Reads the ADC status. + * + * \param p_adc Pointer to an ADC instance. + * + * \retval ADC status register content. + */ +uint32_t adc12_get_status(Adc12b *p_adc) +{ + return p_adc->ADC12B_SR; +} + /** * \brief Reads the ADC result data of the specified channel. * diff --git a/hardware/sam/system/libsam/source/adc_sam3snxa.c b/hardware/sam/system/libsam/source/adc_sam3snxa.c index b610c810f..f93b57304 100644 --- a/hardware/sam/system/libsam/source/adc_sam3snxa.c +++ b/hardware/sam/system/libsam/source/adc_sam3snxa.c @@ -270,11 +270,35 @@ void adc_disable_channel(Adc *p_adc, adc_channel_num_t adc_ch) * \retval 1 means the specified channel is enabled. * 0 means the specified channel is disabled. */ -uint32_t adc_get_status(Adc *p_adc, adc_channel_num_t adc_ch) +uint32_t adc_get_channnel_status(Adc *p_adc, adc_channel_num_t adc_ch) { return p_adc->ADC_CHSR & (1 << adc_ch); } +/** + * \brief Reads the ADC status. + * + * \param p_adc Pointer to an ADC instance. + * + * \retval ADC status register content. + */ +uint32_t adc_get_status(Adc *p_adc) +{ + return p_adc->ADC_ISR; +} + +/** + * \brief Reads the ADC overrun status. + * + * \param p_adc Pointer to an ADC instance. + * + * \retval ADC overrun status register content. + */ +uint32_t adc_get_overrun_status(Adc *p_adc) +{ + return p_adc->ADC_OVER; +} + /** * \brief Reads the ADC result data of the specified channel. * diff --git a/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/flash.ld b/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/flash.ld index 578452392..c79e630a5 100644 --- a/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/flash.ld +++ b/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/flash.ld @@ -40,12 +40,15 @@ MEMORY { flash0 (W!RX) : ORIGIN = 0x00080000, LENGTH = 0x00020000 /* Flash0, 128K */ flash1 (W!RX) : ORIGIN = 0x00100000, LENGTH = 0x00020000 /* Flash1, 128K */ - sram0 (W!RX) : ORIGIN = 0x20000100, LENGTH = 0x00007F00 /* Sram0, 32K */ + 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, 64K */ + ram (rwx) : ORIGIN = ORIGIN( sram1)-LENGTH( sram0), LENGTH = LENGTH( sram0)+LENGTH( sram1) /* sram, 48K */ } +/* The stack size used by the application. NOTE: you need to adjust */ +STACK_SIZE = 0x2000; + /* Section Definitions */ SECTIONS { @@ -136,7 +139,10 @@ SECTIONS .stack (NOLOAD): { . = ALIGN(8); - *(.stack .stack.*) + _sstack = .; + . = . + STACK_SIZE; + . = ALIGN(8); + _estack = .; } > sram1 . = ALIGN(4); diff --git a/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/sram.ld b/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/sram.ld index a4f921aaf..c8e21ad30 100644 --- a/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/sram.ld +++ b/hardware/sam/variants/sam3u_ek/linker_scripts/gcc/sram.ld @@ -40,12 +40,15 @@ MEMORY { flash0 (W!RX) : ORIGIN = 0x00080000, LENGTH = 0x00020000 /* Flash0, 128K */ flash1 (W!RX) : ORIGIN = 0x00100000, LENGTH = 0x00020000 /* Flash1, 128K */ - sram0 (W!RX) : ORIGIN = 0x20000100, LENGTH = 0x00007F00 /* Sram0, 32K */ + 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, 64K */ + ram (rwx) : ORIGIN = ORIGIN( sram1)-LENGTH( sram0), LENGTH = LENGTH( sram0)+LENGTH( sram1) /* sram, 48K */ } +/* The stack size used by the application. NOTE: you need to adjust */ +STACK_SIZE = 0x800; + /* Section Definitions */ SECTIONS { @@ -128,7 +131,10 @@ SECTIONS .stack (NOLOAD): { . = ALIGN(8); - *(.stack .stack.*) + _sstack = .; + . = . + STACK_SIZE; + . = ALIGN(8); + _estack = .; } > sram1 /* .ARM.exidx is sorted, so has to go in its own output section. */