<!--<h1>Yarm D21 setup</h1>-->

##YARM D21 setup

<abstract>
Raccolta di appunti per il setup dell'ambiente di sviluppo per YARM con D21
</abstract>

<h2> bugs</h2>
Con YARM_verbose = 1 non esce da Txloop.

<h2>Setup nuovo progetto</h2>
File -> New -> Project </br>
Select GCC C ASF Board Project</br>
Select the desired Project directory and name and tick "Create directory for solution"</br>
On "Board Selection select "Select by Board"; Extension -> Atmel ASF(3.36.2); 
"BoardTypes" -> User -> User Board Template - ATSAMD21E18A; press OK</br>

To be able to print floating point numbers here are some Atmel notes:<br>
To add the software floating point support to the printf library in Atmel Studio project, do the following:
Open the project properties in Atmel Studio 
Go to Miscellaneous in Toolchain -> ARM/GNU Linker<br>
Add: 
<pre>
-lc -u _printf_float 
</pre>
in the linker flags.<br>
Rebuild the project<br><br> 

Upgrading Atmel Studio 7 creates a problem in the delay module in cycle mode.<br>
This is because the gcc version was upgraded to 5.3.1 and there incompatibilities with older ASFs.<br>
Newer versions of ASF have corrected the bug.<br>
This change will solve it if you have an older project and you try to recompile it under a newer Atmel Studio:
<pre>
In sam0/utils/compiler.h near line 958:

#   define OPTIMIZE_HIGH __attribute__((optimize(s)))

needs to be:

#   define OPTIMIZE_HIGH __attribute__((optimize("s")))

Note double quotes.
</pre>

Open ASF Wizard; Install the following modules:</br></br>

* Delay Routines (cycle)<br>
* ADC (polled)<br>
* Extint (callback)<br>
* PORT - GPIO Pin Control (driver)<br>
* RTC - (count_callback)<br>
* SERCOM I2C Master mode (polled)<br>
* SERCOM SPI (callback)<br>
* SERCOM USART (polled)<br>
* Standard serial I/O (driver)<br>
* System Power Management (driver)<br>
<br>

press"Apply"</br>

Insert the following file in the "src" directory of your project:
<ul>
<li><a href="./main_CM3_D21.c">main_CM3_D21.c download file</a></li>
</ul>
<br>
Add the downloaded file in the project right clicking the src folder of your design in the Solution Explorer, choosing "Add"->"Existing Item"
<br>
<br>
In the same way add the following files in the "src directory:
<ul>
<li><a href="./YARM_lib.c">YARM_lib.c download file</a></li>
<li><a href="./YARM_lib.h">YARM_lib.h download file</a></li>
</ul>
Remove and delete from the project the file main.c (added when you created the new project).
<br>
<br>


Open src->config->conf_board.h and, after #define CONF_BOARD_H insert the following lines:
<pre>
#define LED0_PIN                  PIN_PA10
#define LED0_ACTIVE               false
#define LED0_INACTIVE             !LED0_ACTIVE

#define LED_0_NAME                "LED0 (yellow)"
#define LED_0_PIN                 LED0_PIN
#define LED_0_ACTIVE              LED0_ACTIVE
#define LED_0_INACTIVE            LED0_INACTIVE
#define LED0_GPIO                 LED0_PIN
#define LED0                      LED0_PIN

/* USART ********************************************************** */
#define CONF_STDIO_USART          SERCOM3
#define CONF_STDIO_MUX_SETTING    USART_RX_1_TX_0_XCK_1
#define CONF_STDIO_PINMUX_PAD0    PINMUX_PA22C_SERCOM3_PAD0
#define CONF_STDIO_PINMUX_PAD1    PINMUX_PA23C_SERCOM3_PAD1
#define CONF_STDIO_PINMUX_PAD2    PINMUX_UNUSED
#define CONF_STDIO_PINMUX_PAD3    PINMUX_UNUSED
#define CONF_STDIO_BAUDRATE       115200

#define CONF_STDIO_PAD0_PIN PIN_PA22D_SERCOM5_PAD0
#define CONF_STDIO_PAD1_PIN PIN_PA23D_SERCOM5_PAD1

static struct usart_module usart_instance;
static void configure_usart(void);
/* /USART ********************************************************* */

/* RTC *****************************************/
void rtc_overflow_callback(void);
void configure_rtc_count(void);
void configure_rtc_callbacks(void);
struct rtc_module rtc_instance;
volatile uint32_t event_rtc;
/* /RTC *****************************************/
</pre>