|
发表于 2014-3-10 16:28:09
|
显示全部楼层
补充点资料。
Library Retarget File
http://www.keil.com/support/man/docs/gsac/gsac_retargetcortex.htm
Library Retarget File
Home » Create Application » Configure Cortex-M Target » Library Retarget File
Semihosting is not supported by MDK-ARM. Use the retargeting functionality of MDK-ARM instead. To prevent the linker from selecting libraries functions that use semihosting, MDK-ARM includes retarget files that redefine low-level I/O routines.
A RETARGET.C template file, located in the folder ..\ARM\Startup, implements the functionality required to adapt character I/O functions such as printf() and scanf().
Copy the RETARGET.C template to the project folder.
Include the copied file to the project (described in Create Source File).
Edit the file and make your changes. You may use the following code as a template and adapt it to your needs.
/*----------------------------------------------------------------------------
* Name: Retarget.c
* Purpose: 'Retarget' layer for target-dependent low level functions
* Note(s):
*----------------------------------------------------------------------------
* This file is part of the µVision/ARM development tools.
* This software may only be used under the terms of a valid, current,
* end user licence from KEIL for a compatible version of KEIL software
* development tools. Nothing else gives you the right to use this software.
*
* This software is supplied "AS IS" without warranties of any kind.
*
* Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
extern int sendchar (int c);
extern int getkey (void);
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int c, FILE *f) {
return (sendchar(c));
}
int fgetc(FILE *f) {
return (getkey());
}
int ferror(FILE *f) {
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int c) {
sendchar(c);
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}
Note
Refer to Tailoring the C library to a new execution environment for information about library retargeting.
Refer to Redefining target-dependent system I/O functions in the C library.
Refer to Redefining low-level library functions to enable direct use of high-level library functions in the C library
Refer to What is semihosting?
|
|