切换到newlib-nano会导致应用程序停止运行

时间:2015-03-11 16:05:53

标签: c gcc newlib

我有一个newlib 4.9.3 2014q4应用程序在我的Cortex-M4平台上运行良好。串行控制台的所有输出都使用iprintf或自定义send_str功能。 send_str只是将字节写入串行外设tx缓冲区(循环调用fputc)。

int _write(int fd, char *buf, int nbytes)
{
    int i;

    for (i = 0; i < nbytes; i++) {
        if (*(buf + i) == '\n') {
            /* fd is incorrectly passed as arguments, as FILE is not used, but needed for build */
            fputc('\r', (FILE *) & fd);
        }
        /* fd is incorrectly passed as arguments, as FILE is not used, but needed for build */
        fputc(*(buf + i), (FILE *) & fd);
    }

    return nbytes;
}

int fputc(int ch, FILE * f)
{
    unsigned char tempch = ch;

    sendchar(&tempch);

    return ch;
}

void send_str(unsigned char* buff)
{

    while(*buff != 0){
        sendchar(buff);
        buff++;
    }
}

在我的应用程序的主要部分(在初始化数据重定位和bss零之后),我打印一个横幅。当我使用newlib-nano(--specs=nano.specs)时,如果我使用send_str,则此功能正常,但如果我使用iprintf则不行。

int main(int argc, char ** argv)
{
    int i = 0;
    char str[] = "Hello from Cortex-M4!\n";

    init_uart((void*)UART2_BASE_PTR, 115200);
    send_str(str);
}

int main(int argc, char ** argv)
{
    int i = 0;
    char str[] = "Hello from Cortex-M4!\n";

    init_uart((void*)UART2_BASE_PTR, 115200);
    iprintf("%s", str);
}

只使用newlib(非nano)这两个功能都有效。

我一直在阅读的所有内容都表明,不应要求对我的应用程序进行更改以在两者之间进行切换。这有例外吗?

0 个答案:

没有答案