How to retarget printf() on an STM32F10x?

前端 未结 4 1167
迷失自我
迷失自我 2021-01-23 23:19

I use this code for retarget printf(), but it does not work

#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->         


        
4条回答
  •  不思量自难忘°
    2021-01-23 23:35

    Try hijacking the _write function like so:

    #define STDOUT_FILENO   1
    #define STDERR_FILENO   2
    
    int _write(int file, char *ptr, int len)
    {
        switch (file)
        {
        case STDOUT_FILENO: /*stdout*/
            // Send the string somewhere
            break;
        case STDERR_FILENO: /* stderr */
            // Send the string somewhere
            break;
        default:
            return -1;
        }
        return len;
    }
    

提交回复
热议问题