Atmel Studio & adding ASF to a project for SAM V71 - Page 1
Forum section: electronics / general

author: mix29
author_rank: Newbie
timestamp: November 22, 2016, 02:49:59 am
content: Hi, I am trying to get a simple application running on an Atmel SAM V71I stumbled upon these excellent demos by Alex Taradov:https://github.com/ataradov/mcu-starter-projectsand the one for the V71 works beautfiully.However, I wanted to add ASF to the project. I followed the steps in this doc:https://startingelectronics.org/software/atmel/asf-arm-tutorial/adding-asf-to-project/but I get a whole load of errors when I try to recompile.Code:SeverityCodeDescriptionProjectFileLineWarningpassing argument 1 of 'uart_puts' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\main.c165Messagethis is the location of the previous definitiondemoc:\program files (x86)\atmel\studio\7.0\toolchain\arm\arm-gnu-toolchain\arm-none-eabi\include\sys\cdefs.h372Messagethis is the location of the previous definitiondemoc:\program files (x86)\atmel\studio\7.0\toolchain\arm\arm-gnu-toolchain\arm-none-eabi\include\sys\cdefs.h372Errorrecipe for target 'src/ASF/common/services/clock/samv71/sysclk.o' faileddemoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\Release\Makefile221Errorimplicit declaration of function 'SystemCoreClockUpdate' [-Werror=implicit-function-declaration]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\common\services\clock\samv71\sysclk.c82Warningnested extern declaration of 'SystemCoreClockUpdate' [-Wnested-externs]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\common\services\clock\samv71\sysclk.c82Errorimplicit declaration of function 'system_init_flash' [-Werror=implicit-function-declaration]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\common\services\clock\samv71\sysclk.c173Warningnested extern declaration of 'system_init_flash' [-Wnested-externs]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\common\services\clock\samv71\sysclk.c173Warning"__always_inline" redefineddemoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\sam\utils\compiler.h162Warning"__always_inline" redefineddemoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\ASF\sam\utils\compiler.h162Warningno previous prototype for 'irq_handler_tc0' [-Wmissing-prototypes]demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\main.c56Messageexpected 'char *' but argument is of type 'const char *'demoC:\Users\Mix29\Downloads\mcu-starter-projects-master\mcu-starter-projects-master\samv71\astudio\src\main.c103I guess adding ASF to a project isn't always straightforward?

author: ataradov
author_rank: Super Contributor
timestamp: November 22, 2016, 02:56:56 am
content: If you want to use ASF, then start with ASF. It can be either simple and bare-metal, or bloated and with ASF. You can't easily mix and match.

author: mix29
author_rank: Newbie
timestamp: November 22, 2016, 03:01:33 am
content: Thanks so much Alex. If I start a new ASF project, how do i go about adding your demo code to it? I am particularly interested in the UART code (just want a Hello World to work!)

author: ataradov
author_rank: Super Contributor
timestamp: November 22, 2016, 03:05:24 am
content: Copy and paste UART parts. You will obviously need to make sure that MCU is running at 300 MHz that my baudrate calculations expect. If you match the frequencies, then it all should just work.But I don't really see the point of doing that. ASF has its own UART drivers.

author: mix29
author_rank: Newbie
timestamp: November 22, 2016, 03:13:13 am
content: Thanks Alex. I have added UART and STDIO to the new ASF project. Can you advise on what to do next? Sorry, I am a complete newbie.

author: ataradov
author_rank: Super Contributor
timestamp: November 22, 2016, 04:19:30 am
content: What exactly have you added to what project? You need to be more specific.ASF includes a ton of sample projects, you may want to start with one of those.V71 is a pretty complex device for beginners.

author: mix29
author_rank: Newbie
timestamp: November 22, 2016, 05:23:43 am
content: Thanks for the tip. There is an example ASF project called SERIAL_EXAMPLE but it is not available for the v71. I am looking at the one for the SAM4L8 and am trying to make it work for the v71Step1=====I looked at the ASF wizard for the example and found that it had the following:WDT - Watchdog Timer (driver)USART - Serial interface (service)IOPORT - General purpose I/O service (service)The SAM4L8 example uses the following main.cCode:int main(void){uint8_t tx_len = 24;uint8_t tx_buf[] = "\n\rHello Atmel world ! : ";uint8_t rx_buf[] = "0";// USART options.static usart_serial_options_t USART_SERIAL_OPTIONS ={.baudrate = USART_SERIAL_EXAMPLE_BAUDRATE,.charlength = USART_SERIAL_CHAR_LENGTH,.paritytype = USART_SERIAL_PARITY,.stopbits = USART_SERIAL_STOP_BIT};sysclk_init();// Initialize the board.// The board-specific conf_board.h file contains the// configuration of the board initialization.board_init();// Initialize Serial Interface using Stdio Libraryusart_serial_init(USART_SERIAL_EXAMPLE,&USART_SERIAL_OPTIONS);// Print welcome messageusart_serial_write_packet(USART_SERIAL_EXAMPLE, tx_buf, tx_len);// Get and echo a character forever, specific '\r' processing.while (true) {usart_serial_read_packet(USART_SERIAL_EXAMPLE, rx_buf, 1);if (rx_buf == '\r') {usart_serial_write_packet(USART_SERIAL_EXAMPLE,tx_buf, tx_len);} else {usart_serial_write_packet(USART_SERIAL_EXAMPLE,rx_buf, 1);}}}I have added the ASF modules and included the contents of the main.c in my ProjectI also modified conf_uart_serial.h to have the following:Code:#ifndef CONF_USART_SERIAL_H#define CONF_USART_SERIAL_H/** USART Interface */#define USART_SERIAL_EXAMPLE COM_PORT_USART/** Baudrate setting */#define USART_SERIAL_EXAMPLE_BAUDRATE 115200/** Character length setting */#define USART_SERIAL_CHAR_LENGTH US_MR_CHRL_8_BIT/** Parity setting */#define USART_SERIAL_PARITY US_MR_PAR_NO/** Stop bits setting */#define USART_SERIAL_STOP_BIT US_MR_NBSTOP_1_BIT#endif/* CONF_USART_SERIAL_H_INCLUDED */Step 2:====In the sam/boards/sam4l8_xplained_pro/sam4l8_xplained_pro.h there is:Code://! \name USART connections to GPIO for Virtual Com Port// @{#define COM_PORT_USART USART1#define COM_PORT_USART_ID ID_USART1#define COM_PORT_RX_PIN PIN_PC26A_USART1_RXD#define COM_PORT_RX_GPIO GPIO_PC26A_USART1_RXD#define COM_PORT_RX_MUX MUX_PC26A_USART1_RXD#define COM_PORT_TX_PIN PIN_PC27A_USART1_TXD#define COM_PORT_TX_GPIO GPIO_PC27A_USART1_TXD#define COM_PORT_TX_MUX MUX_PC27A_USART1_TXDIn the sam/boards/samv71_xplained_ultra/samv71_xplained_ultra.h there is:Code:/*----------------------------------------------------------------------------*/#define CONSOLE_UART USART1#define CONSOLE_UART_ID ID_USART1/** USART1 pins definitions, PA21,PB4. */#define USART1_RXD_GPIO PIO_PA21_IDX#define USART1_RXD_FLAGS IOPORT_MODE_MUX_A#define USART1_TXD_GPIO PIO_PB4_IDX#define USART1_TXD_FLAGS IOPORT_MODE_MUX_D/** USART0 pins definitions, PB0,PB1. */#define USART0_RXD_GPIO PIO_PB0_IDX#define USART0_RXD_FLAGS IOPORT_MODE_MUX_C#define USART0_TXD_GPIO PIO_PB1_IDX#define USART0_TXD_FLAGS IOPORT_MODE_MUX_C#define PIN_USART0_SCK_IDX (PIO_PB13_IDX)#define PIN_USART0_SCK_FLAGS (IOPORT_MODE_MUX_C)/** USART0 pin CTS */#define PIN_USART0_CTS_IDX (PIO_PB2_IDX)#define PIN_USART0_CTS_FLAGS (IOPORT_MODE_MUX_C)/** USART0 pin RTS */#define PIN_USART0_RTS_IDX (PIO_PB3_IDX)#define PIN_USART0_RTS_FLAGS (IOPORT_MODE_MUX_C)So I further modified COM_PORT_USART in conf_uart_serial.h to be CONSOLE_UART (They look very different and I really don't know what I am doing here...) .Finally I added the following to conf_board.h to match the example too:Code:/** Enable Com Port. */#define CONF_BOARD_COM_PORTIt all compiles, but I still don't get anything coming through (I am using Putty and connecting to the EDBG COM port at 115200 etc.So I am a bit stuck. Thanks very much for any tips!

author: ataradov
author_rank: Super Contributor
timestamp: November 22, 2016, 06:13:36 am
content: I'm not really a fan of ASF. Exactly for the reason above. Way too much stuff to modify to make simple things work.So in this case, I can only give generic advice:1. Check your clock configuration.2. Check that program runs at all. This board has a full-blown debugger, so that should not be a problem.3. Check with the scope that UART actually sends anything. It may be a case of simple baudrate mismatch.4. Check what UART is doing with the debugger.It is also possible that some other examples will have UART output. In fact, I think most of them use UART for debug output.

author: mix29
author_rank: Newbie
timestamp: November 22, 2016, 06:41:14 am
content: Thanks Alex, they are very good suggestions, I will try them right away.I have to say, I miss the Arduino:Code:Serial.begin(9600);Serial.println("Hello world");