天天看點

Synery E2Studio重定向printf和IAR For Renesas實作Printf

Synergy平台跟Keil和IAR重映射方式并不一樣,使用E2Studio IDE時需要

1、Project/Properties/C/C++ Build/Setting/Tool Setting/Cross ARM C Linker/General 使用 “-nostdlib” compiler option 

2、Project/Properties/C/C++ Build/Setting/Tool Setting/Cross ARM C Linker/Miscellaneous 去掉 “-specs=rdimon.specs” linker option 

Synery E2Studio重定向printf和IAR For Renesas實作Printf
Synery E2Studio重定向printf和IAR For Renesas實作Printf

然後添加自己的 _write函數

int _write (int fd, char *ptr, int len)

{

  g_usb_terminal.p_api->write(g_usb_terminal.p_ctrl, ptr, len, TX_WAIT_FOREVER);

  return len;

}

IAR IDE沒有調試成功。

可以通過以下方式實作:

1、g_uart2在HAL中

注意:必須使用信号量。

void Puts(uint8_t *str)

{

    static uint8_t ucTmp, ucSize;

    uint8_t i = 0;

    while(*str != '\0')

    {

        ucTmp = *str;

        //g_sf_comms0.p_api->write(g_sf_comms0.p_ctrl, &Txt, 1, 0xFFFF);

        g_uart2.p_api->write(g_uart2.p_ctrl, str, 1);

        tx_semaphore_get(&g_uart_semaphore, TX_WAIT_FOREVER);//設定信号量

        str++;

        ucSize++;

    }

}

void cb_uart2(uart_callback_args_t *p_args)

{

    if (2U == p_args->channel)

    {

        switch (p_args->event)

        {

            case    UART_EVENT_TX_COMPLETE:

                tx_semaphore_put(&g_uart_semaphore);

                break;

            default:

                break;

        }

    }

}

2、g_uart0在FW架構中

void Printf(uint8_t *str)

{

    uint16_t i = 0;

    while(str[i++] != 0)

    {

        Txt = str[i-1];

        guiSize++;

        i++;

    }

    g_sf_comms0.p_api->write(g_sf_comms0.p_ctrl, str, i, TX_WAIT_FOREVER);

    for(i = 0; i < 50; i++)

    {

        str[i] = 0;

    }

    guiSize = 0;

}

sprintf(Uart0ThreadLogBuffer,"\r\n Uart0Thread Line Num: %d",__LINE__);

Printf(Uart0ThreadLogBuffer);

sprintf(Uart0ThreadLogBuffer,"\r\n Uart0Thread Line Num: %d",__LINE__); 

g_sf_comms0.p_api->write(g_sf_comms0.p_ctrl, Uart0ThreadLogBuffer,strlen(Uart0ThreadLogBuffer)+1, TX_WAIT_FOREVER);

繼續閱讀