STDOUT retarget

Sysprogs forums Forums VisualGDB STDOUT retarget

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #822
    darksilence
    Participant

    Hello =)
    I’m trying to retarget printf to USART1.

    I tryed to redefine function _write

    int _write(int file, char *ptr, int len) {
    while (! USART_GetFlagStatus (DEBUG_USART, USART_FLAG_TXE));
    USART_SendData(DEBUG_USART, (uint8_t) ptr[0]);
    return 0;
    }

    But linker showed me a message:

    
    
    Quote:
    c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/4.8.2/../../../../arm-eabi/lib/thumb/cortex_m4libc.a(lib_a-syscalls.o): In function `_write':
    1>q:gnuautonewlib-bu-2.23.1+gcc-4.8.2+gmp-4.2.4+mpfr-2.4.1+mpc-0.8+newlib-2.0.0-arm-eabiarm-eabithumbcortex_m4newliblibcsysarm................newlib-2.0.0newliblibcsysarmsyscalls.c(335): error VGDB1001: multiple definition of `_write'
    1> Debug/syscalls.o:C:WorkSVNbranchesReNewProjectVisualGDB../../../System/Config/syscalls.c:35: first defined here
    1>collect2.exe : error : ld returned 1 exit status

    How to make it work?

    Thnaks

    #3169
    support
    Keymaster

    Hi,

    In order to replace the newlib’s implementation of _write() with your own one you would need to recompile newlib itself. If you don’t want to do it, you can hook it dynamically:

    
    static int my_write(struct _reent *, _PTR, const char *buf, int len)
    {
    ...
    }
    
    int main()
    {
    stdout->_write = my_write;
    stdout->_flags |= __SNBF;
    printf("Hello...");
    }
    #3170
    darksilence
    Participant

    also how does standart lib work in this case. Does it allocate buffer for temp string? if it does, where can I set malloc function and MAX_Size of the temp string?

    #3171
    support
    Keymaster

    Hi,

    Stdlib uses the space past the ‘end’ symbol to allocate buffers. BTW, we have updated our toolchain to include newlib without the standard syscall implementations. This should make it easier to define your own functions like _write() and control how exactly the IO is performed. Have a look at this tutorial: http://visualgdb.com/tutorials/arm/stm32/uart/ (note that you will need VisualGDB 4.2 beta 1 to use the raw terminal and the memory explorer).

    If you want to hack the standard library further, you can get newlib sources, and rebuild it using MinGW and our toolchain:

    mkdir newlib-build && cd newlib-build
    ../newlib-2.0.0/configure --target=arm-eabi --prefix=/c/SysGCC/arm-eabi --disable-newlib-supplied-syscalls

    Note that the build may take up to a day to complete, as the libraries will be built for each supported core.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.