This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Retargeting printf(), by writing custom fputc()

Hello!

I have been reading on how to retarget printf() so I can direct it to my USART Tx. I have never done retargeting before (not even on other platforms) so this is new to me.

Eventually I found this page on Keil:

http://www.keil.com/support/man/docs/ARMLIB/armlib_CJAIABCF.htm

which gives an example on how to write custom fputc() function.

Using ARM Cortex M3 F103 I wrote this in my main.c file:

int fputc(int ch, FILE *f)
{
        while( USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1, (uint8_t) ch);
        return ch;
}

Just to mention it, I have USART1 working in Tx mode.

I insert a printf() statement in my main:

/***  MAIN LOOP  ***/
while(1)
        {
                USART1_SendData(USART1_ReceiveData());
                LED(LED2, TOGGLE);
                LED(LED1, ON);
                printf("Hello");
        }

and flash my device. Open terminal as always, but nothing displays. (Usually I can echo my input and the LED2 toggles while LED1 is always on).

So I try to debug and can see that the debugger is stuck at this one line of assembly (in the disassembly window):

0x08001292 BEAB      BKPT     0xAB

In context this line belongs to _sys_open as shown below:

                 _sys_open:
0x08001282 B50E      PUSH     {r1-r3,lr}
0x08001284 E9CD0100  STRD     r0,r1,[sp,#0]
0x08001288 F000FAE0  BL.W     strlen (0x0800184C)
0x0800128C 9002      STR      r0,[sp,#0x08]
0x0800128E 4669      MOV      r1,sp
0x08001290 2001      MOVS     r0,#0x01
0x08001292 BEAB      BKPT     0xAB
0x08001294 BD0E      POP      {r1-r3,pc}

-Found a reference to _sys_open() on Keil:

infocenter.arm.com/.../index.jsp

-Trying to figure out what BKPT is:

infocenter.arm.com/.../index.jsp

which does not give me much as my assembly knowledge is rather poor.

--------------------------------------------------------------------

I also get this message (for why I dont know?) in my command window:

BS \\test2\StdPeriph_Lib/stm32f10x_usart.c\929

Which leads me to line 929 in stm32f10x_usart.c:

if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)

--------------------------------------------------------------------

Any help would much be appreciated!

0