How to make a simple Hello World with Start.Atmel?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I just created a project with Start.Atmel and I would like to print some text on the USB serial port of my SAMD21 Xplained Pro board.

 

The generated code called system_init() which calls
    USART_0_init();

    USART_1_init();

    USART_2_init();

I just added a simple printf, but it doesn't work. I did include a STDIO_REDIRECT in my design, so I would have expected it to be working out of the box or to have some indications on how to do it.

#include "atmel_start.h"
#include "atmel_start_pins.h"
#include "stdio_start.h"

int main(void)
{
    system_init();

    printf("hello, world.\n");

    /* Replace with your application code */
    while(1) { }

}

I also checked some examples like the 8khz oscillator demo which do print things on the screen, but I couldn't mix it with my start.atmel code.

 

Could someone point me to some code on how to do this?

Attachment(s): 

Last Edited: Thu. Feb 4, 2016 - 05:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

usually, Start creates example code that you can run from your main. Just search for _example or something similar in the solution and you should find some simple hello-world ish..

 

Looking at the project, in the file called stdio_start.c you have these two that you could call from main:

#include "atmel_start.h"
#include "stdio_start.h"

void STDIO_REDIRECT_0_init(void)
{
	usart_sync_enable(&USART_2);
	stdio_io_init(&USART_2.io);
}

void STDIO_REDIRECT_0_example(void)
{
	/* Print welcom message */
	printf("\r\nHello ATMEL World!\r\n");
}

 

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Meolsen, it worked!

 

My previous attempts failed because I thought that the output will magically come from the USB port thanks to the STDIO__REDIRECT component.

But I needed to set the USART to pin PA22/PA23 and select the right baud rate, this is not the kind of thing you have to worry about on simpler MCU where TX/RX are on static pins