Keil Logo

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().

  1. Copy the RETARGET.C template to the project folder.
  2. Include the copied file to the project.
  3. 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

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.