Printf doesn't work in Start generated project

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

Build the EDBGUART demo for the E70 xpld.

 

Tried to insert a printf statement. included stdint.h and uinstd.h

 

Severity    Code    Description    Project    File    Line
Error        ld returned 1 exit status    E70EDBGUART0    collect2.exe    0
Error        undefined reference to `_write'    E70EDBGUART0    C:\Users\J.Stampfl\Documents\Atmel Studio\7.0\E70EDBGUART0\E70EDBGUART0\Debug\writer.c    1
Error        recipe for target 'E70EDBGUART0.elf' failed    E70EDBGUART0    C:\Users\J.Stampfl\Documents\Atmel Studio\7.0\E70EDBGUART0\E70EDBGUART0\Debug\Makefile    343
Error        undefined reference to `_read'    E70EDBGUART0    C:\Users\J.Stampfl\Documents\Atmel Studio\7.0\E70EDBGUART0\E70EDBGUART0\Debug\readr.c    1

 

This topic has a solution.
Last Edited: Sun. Feb 4, 2018 - 09:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The EDBG UART project from START uses the driver's io_read() and io_write() functions only.  To add printf() capability you need to add support for stdio redirect in the project.

 

Go back into Start via the menus and add the middleware:  Project->Reconfigure Atmel Start Project->Add software component->Middleware->Utility->stdio redirect.  This adds the _read() and _write() functions to [project folder]->stdio_redirect->gcc->read.c and write.c.  These functions eventually call io_read() and io_write() on your behalf.

 

Last Edited: Mon. Jan 29, 2018 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I already thought of looking for middleware.  Just didn't notice the "utilities" folder.  Now My program compiles. But printf("here\r\n"); doesn't print.

 


int main(void)
{
	uint8_t recv_char;

	atmel_start_init();

	usart_async_register_callback(&EDBG_COM, USART_ASYNC_TXC_CB, tx_cb_EDBG_COM);
	usart_async_register_callback(&EDBG_COM, USART_ASYNC_RXC_CB, rx_cb_EDBG_COM);
	usart_async_register_callback(&EDBG_COM, USART_ASYNC_ERROR_CB, err_cb_EDBG_COM);
	usart_async_enable(&EDBG_COM);

	io_write(&EDBG_COM.io, example_hello_world, 15);

	while (1) {
		if (data_arrived == 0) {
			continue;
		}
	printf("here\r\n");
		while (io_read(&EDBG_COM.io, &recv_char, 1) == 1) {
			while (io_write(&EDBG_COM.io, &recv_char, 1) != 1) {
			}
	
		}
		data_arrived = 0;

	}
}

 

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

Hello jstampfl,

 

 But printf("here\r\n"); doesn't print.

it does work for me, are you using different I/O descriptor for 

 

usart_sync_enable();

and 

stdio_io_init ();

in stdio_start.c file

Last Edited: Sat. Feb 3, 2018 - 09:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about showing your code?

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is my code : 

 

 

#include <atmel_start.h>

#include "stdio_start.h"

 

struct io_descriptor *io;

 

 

void TARGET_IO_example(void)

{

usart_sync_get_io_descriptor(&TARGET_IO, &io);

usart_sync_enable(&TARGET_IO);

 

}

 

int main(void)

{

/* Initializes MCU, drivers and middleware */

atmel_start_init();

TARGET_IO_example();

 

io_write(io, (uint8_t *)"Hello World!", 12);

printf("\r\nHello ATMEL World!\r\n");

 

/* Replace with your application code */

while (1) {

}

}

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

Thanks