ATMEL Studio 6.2, how to modify serial target from STDIO.h to specfic UART port, USART0 or USART1

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

I could not find material in Atmel that allow retarget (as in LPC, TI devices) serial message stream to specfic port using printf("") function.

 

I surprised the topic has very little discussed.

 

I use Arduino Due (SAM 3X) board and using ASF to configure the UART, USART0 and USART1.  

 

 

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

No idea about the SAM chips but with Mega/Xmega/Tiny chips you use fprintf to send to different channels.

 

#include <avr/io.h>
#include <stdio.h>
#include "com_ports_test_init.h"

#define PI 3.141593

int	main(void)
{
	com_ports_test_init();

	printf("Printing on com 0\r\n");				// Using stdout	956 bytes
	fprintf(com0, "Printing on com 0 with fprintf\r\n");		// 1086 bytes
	fprintf(com1, "Printing on com 1 with fprintf %d\r\n",12345);	// 2576 bytes
	fprintf(com2, "Printing on com 2 with fprintf %f\r\n",1.23456);	// 2664 bytes
	fprintf(com3, "Printing on com 3 with fprintf %f\r\n",PI);	// 2750 bytes

	for(;;);
}

 

You need of course to set up the various com streams, but it may just be all different with SAMs.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sat. Apr 25, 2015 - 09:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using ASF with the Xmega, there is a module called stdio_serial or something like that that allows you to specify the USART in a .h file.  Since the goal of the ASF is to abstract the specific hardware you are working with, I assume this is available for the SAM devices as well.  If not using ASF with the Xmega, there is a method for doing this in avr_libc.  I don't know if there is a sam_libc somewhere, but it would be searching for.  You are surely not the first person to try to do this.

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

If you're using newlib, check out:

http://forum.43oh.com/topic/8308...

tl/dr: use fopencookie() with user-provided read/write functions.

 

(Does ASF/AS6.x end up using newlib for ARM builds?)

 

ssize_t myWrite(void *cookie, const char *buf, size_t n)
{
  return Serial.write((uint8_t*)buf, n);
}

cookie_io_functions_t myVectors = { 0, myWrite, 0, 0 };

void setup() {                
  Serial.begin(115200);
  stdout = fopencookie((void *)0, "w", myVectors);
  setlinebuf(stdout);
  printf( "This is an fprintf demo\n");
}

 

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

Hello,

 

    I'd love to get the serial terminal to work in the Atmel Studio 6.2 debug simulator, on my ATmega328P projects.  I have that "Terminal for Atmel Studio" extension.

 

    But I don't see any file called  "com_ports_test_init.h" in my Atmel Studio installation.  Can you elaborate on what you are showing us here ?

 

    - Thanks

 

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

I don't see any file called  "com_ports_test_init.h" in my Atmel Studio installation.

That's because it's my file not studio smiley

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly