Cortex-M4 プラットフォームで正常に動作する newlib 4.9.3 2014q4 アプリケーションがあります。シリアル コンソールへのすべての出力は、iprintf
またはカスタムsend_str
関数のいずれかを使用します。はsend_str
、シリアル ペリフェラル tx バッファーにバイトを書き込むだけです ( my へのループ呼び出し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 zero'ing の後) で、バナーを出力します。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);
}
(nanoではなく)newlibだけを使用すると、両方の機能が機能します。
私がこれまで読んできたものはすべて、この 2 つを交換するためにアプリケーションを変更する必要はないことを示唆しています。これに例外はありますか?