본문 바로가기
Development/CooCox

[CoIDE]If you use printf function in the CoIDE???

by 루카오리 2014. 2. 5.

printf(namo printf) redirect to the UART under CoIDE 1.7.6

- by irinaKim

 

Download and install CoIDE V1.7.6: 

http://www.coocox.org/Tools/CoIDE-1.7.6.exe

Replace the file "/plugins/org. Coocox. Builder. Ui_1. 0.0.201212141638. Jar" under the CoIDE installation directory   with the documents in the attachment 
Download  GNU Tools for ARM Embedded Processors  Version 4.7

The download address is: 
https://launchpad.net/gcc-arm-embedded/+milestone/4.7-2012-q4-major


Procedures of setting  tool chains in CoIDE  are not detailed descripted here. Below take Cookie board  for example, I'll  introduce the process that  Newlib - nano printf redirect to the UART in CoIDE.

There are three steps in total:
1. Creat a new project and add printf statements
2. Select Newlib - nano, support print floating-point number
3. Redirect to printf

1.Creat a new project and add printf statements

 Creat a new M051 project ( How to creat a new project is not described  here)
 Check  the following components:

Add cookie_printf example to the project  in the UART component 


Open the cookie_printf.c file ,then add header file #include <stdio.h> and add a statement  in while(1)cycle like this:  printf("Nano Clib test:int=%d   float=%f\r\n",255,123.456); 


2. Select Newlib - nano, support print floating-point number

-> If you don't use the nano printf, you are pass to the next step(Redirect to printf)  



Click the configuration button to enter the configuration:

Enter the link page
Add the following files in Linked Library:
D:\Program Files\GNU Tools ARM Embedded\4.7 2012q4\arm-none-eabi\lib\armv6-m\libc_s.a
D:\Program Files\GNU Tools ARM Embedded\4.7 2012q4\arm-none-eabi\lib\armv6-m\libg_s.a
Note: cookie is M0 so armv6-m
 ARM Core
 multilib
Cortex-M0+
armv6-m
Cortex-M0
armv6-m
Cortex-M1
armv6-m
Cortex-M3
armv7-m
Cortex-M4 
armv7e-m

If you want to  support floating-point print, add   "- u; _printf_float
Note : The standard command is" - u _printf_float", But  some changes have to be done to match with CoIDE



3.  Redirect to printf

Open syscalls.c,edit code as follows:

/**************************************************************************//*****
 * @file     stdio.c
 * @brief    Implementation of newlib syscall
 ********************************************************************************/

#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>

#include "xhw_types.h"
#include "xhw_ints.h"
#include "xhw_memmap.h"
#include "xuart.h"

#undef errno
extern int errno;
extern int  _end;

caddr_t _sbrk ( int incr )
{
  static unsigned char *heap = NULL;
  unsigned char *prev_heap;

  if (heap == NULL) {
    heap = (unsigned char *)&_end;
  }
  prev_heap = heap;

  heap += incr;

  return (caddr_t) prev_heap;
}

int link(char *old, char *new) {
return -1;
}

int _close(int file)
{
  return -1;
}

int _fstat(int file, struct stat *st)
{
  st->st_mode = S_IFCHR;
  return 0;
}

int _isatty(int file)
{
  return 1;
}

int _lseek(int file, int ptr, int dir)
{
  return 0;
}

int _read(int file, char *ptr, int len)
{
  return 0;
}

int _write(int file, char *ptr, int len) {

/////////////////////////////////////////////////// 

///////////// Add by IrinaKim /////////////////////

int txCount;                        

(void) file;

for (txCount = 0; txCount < len; txCount++)
{
xUARTCharPut(xUART0_BASE,*ptr++);
}
///////////////////////////////////////
return len;
}

void abort(void)
{
  /* Abort called */
  while(1);
}
          
/* --------------------------------- End Of File ------------------------------ */

 Download the codes  with ColinkEx you will see serial print information shows as following:


The advantage of  using Newlib-nano can be easily seen from the Program Size 
 
Non-use floating point number:

 Use floating point number: