johnsonzzd 发表于 2013-10-27 21:34
求助楼主。折腾了一天,最后一步又卡住了。
c:/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm ...
是的,其实我这个教程只是抛砖引玉,好多细节我都没说。
printf我用的是atollic提供的tiny_printf.c,具体到printf,代码如下:
[pre lang="c" line="1"]/**
**===========================================================================
** Abstract: Loads data from the given locations and writes them to the
** standard output according to the format parameter.
** Returns: Number of bytes written
**
**===========================================================================
*/
int printf(const char *fmt, ...)
{
int length = 0;
va_list va;
va_start(va, fmt);
length = ts_formatlength(fmt, va);
va_end(va);
{
char buf[length];
va_start(va, fmt);
length = ts_formatstring(buf, fmt, va);
length = _write(1, buf, length);
va_end(va);
}
return length;
}
[/code]
里面的_write重定向到syscalls.c
[pre lang="c" line="1"]int _write(int file, char *ptr, int len)
{
int i;
for (i=0; i<len; i++)
{
__uart_putchar(*(ptr++));
}
return len;
}[/code]
__uart_putchar重定向到st提供的bsp函数
- /**
- * @brief Retargets the C library printf function to the USART.
- * @param None
- * @retval None
- */
- int __uart_putchar(int ch)
- {
- /* Place your implementation of fputc here */
- /* e.g. write a character to the USART */
- USART_SendData(EVAL_COM1, (uint8_t) ch);
- /* Loop until the end of transmission */
- while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
- {}
- return ch;
- }
复制代码
tiny_printf.c和syscalls.c网上搜搜看。
|