Printf does not work

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
LuBe_4654241
Level 4
Level 4
50 sign-ins 25 replies posted 25 sign-ins

Hi,

the printf function does not send out the characters.

I added this function for redirect printf:


int __io_putchar(int ch)
{
    UART_PutChar(ch);
   return ch;
}

must I enable something ?

Best regards

 

0 Likes
1 Solution

Hi,

Hi, the problem was the heap size, I changed from 0x80 to 0x200, now it works well.

Thanks

Best regards

View solution in original post

10 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

LuBe,

Can you get a terminal output if you use  UART_PutChar(ch) directly?

If not, the problem may be that you haven't chosen the correct pin for the UART Tx.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
LuBe_4654241
Level 4
Level 4
50 sign-ins 25 replies posted 25 sign-ins

Hi, 

yes, the function UART_PutChar(ch) works well, but the printf does not work.

Best regards

0 Likes
SuSh_1535366
Level 5
Level 5
Distributor - Macnica (Japan)
10 solutions authored 10 likes given 10 likes received

Hello Lube,

Please refer:

https://japan.cypress.com/documentation/code-examples/ce224431-psoc-4-uart-printf 

You need to define the _write function for printf, not __io_putchar.

Shima

0 Likes

Hi,

I have tested your example with success, but if I insert the same function write(...) in my project no work:

the write() function is not called.

Best regards

 

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think it was _write() instead of write()...
I wonder if  my memo below can be some hint?

https://community.cypress.com/t5/Code-Examples/printf-and-float-rhapsody-aka-yet-another-printf-and-...

moto

0 Likes

Hi,

yes, I wrote write() but the implementation is this:

 

#if defined (__GNUC__)
   
    /* Add an explicit reference to the floating point printf library to allow
       use of floating point conversion specifier. */    
    asm (".global _printf_float");
 
    /* For GCC compiler revise _write() function for printf functionality */    
 int _write(int file, char *ptr, int len)
    {      
        /* Warning suppression for unused function parameter */
  file = file;
  
  int i;
        /* Character is sent via UART */
        for (i = 0; i < len; i++)
        {
            UART_PutChar(*(ptr++));
        }         
        return(len);
    }
#endif /* (__GNUC__) */

 

Best regards

 

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

From your previous message, UART_PutChar(ch) is working,

so UART_Start() should have been called and UART seems to be ready.

Then you wrote that "write()" is not called.

I wonder in which source file you have your "_write()" function?

When I tried, I placed may "_write()" in my main.c,

although it may not be beautiful.

moto

0 Likes
LuBe_4654241
Level 4
Level 4
50 sign-ins 25 replies posted 25 sign-ins

Hi, 

I wrote _write() in main.c. I have noticed that when I call printf the code entry in hard fault:

CY_NORETURN
CY_ISR(IntDefaultHandler)
{
    /***************************************************************************
    * We must not get here. If we do, a serious problem occurs, so go into
    * an infinite loop.
    ***************************************************************************/
    #if defined(__GNUC__)
        if (errno == ENOMEM)
        {
            #ifdef CY_BOOT_INT_DEFAULT_HANDLER_ENOMEM_EXCEPTION_CALLBACK
                CyBoot_IntDefaultHandler_Enomem_Exception_Callback();
            #endif /* CY_BOOT_INT_DEFAULT_HANDLER_ENOMEM_EXCEPTION_CALLBACK */
           
            while(1)
            {
                /* Out Of Heap Space
                 * This can be increased in the System tab of the Design Wide Resources.
                 */
            }
        }
        else
    #endif
        {
            #ifdef CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK
                CyBoot_IntDefaultHandler_Exception_EntryCallback();
            #endif /* CY_BOOT_INT_DEFAULT_HANDLER_EXCEPTION_ENTRY_CALLBACK */
            while(1)
            {
            }
        }
}
#if defined(__ARMCC_VERSION)
 
Best regards
0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Have you expanded the stack/heap space?

Would you try / play with my memo in my previous response?

It can be memory space problem or some unhandled interrupt is called (or hit)

By any chance can you post a project which can be used to reproduce your problem?

moto

0 Likes

Hi,

Hi, the problem was the heap size, I changed from 0x80 to 0x200, now it works well.

Thanks

Best regards