cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 6

David_Zhang
New Contributor II

hi  Cypress:

    when i use Psoc6 to printf  float , it shows noting  the code is below: it can output float date?

void My_Uart_Init(void)

{

    cy_en_scb_uart_status_t uart_status ;

   

    uart_status  = Cy_SCB_UART_Init(Uart_Printf_HW, &Uart_Printf_config, &Uart_Printf_context);

    if(uart_status != CY_SCB_UART_SUCCESS)

    {

        HandleError();

    }

    Cy_SCB_UART_Enable(Uart_Printf_HW);

}

int _write(int file, char *ptr, int len)

    {

        int nChars = 0;

        /* Suppress the compiler warning about an unused variable. */

        if (0 != file)

        {

        }

               

        nChars = Cy_SCB_UART_PutArray(Uart_Printf_HW, ptr, len);

          

        return (nChars);

    }

static void HandleError(void)

{

     /* Disable all interrupts */

    __disable_irq();

    while(1u)

    {

       

    }

}

Test Code:

float a = 1.234;

int main(void)

{

    __enable_irq();

   

    My_Uart_Init();

   

   

    for(;;)

    {

         printf("a = %f\r\n", a);

         CyDelay(500);

    }

}

输出解决:

pastedImage_2.png

0 Likes
1 Solution
LinglingG_46
Moderator
Moderator

​问题出现在:

你的工程中My_Printf.c 文件中关于在不同编译器下定义的printf()函数原型的定义出错了。

#if defined (__GNUC__)
/*******************************************************************************
* Function Name: _write
********************************************************************************
* Summary:
* NewLib C library is used to retarget printf to _write. printf is redirected to
* this function when GCC compiler is used to print data to terminal using UART.
*
* \param file
* This variable is not used.
* \param *ptr
* Pointer to the data which will be transfered through UART.
* \param len
* Length of the data to be transfered through UART.
*
* \return
* returns the number of characters transferred using UART.
* \ref int
*******************************************************************************/
   
    asm (".global _printf_float");

   int _write(int file, char *ptr, int len)
    {
        int nChars = 0;

        /* Suppress the compiler warning about an unused variable. */
        if (0 != file)
        {
        }
               
        nChars = Cy_SCB_UART_PutArray(Uart_Printf_HW, ptr, len);
          
        return (nChars);
       
      
       
    }
#elif defined(__ARMCC_VERSION)

在定义的 _write()函数之前加上     asm (".global _printf_float");

View solution in original post

0 Likes
1 Reply
LinglingG_46
Moderator
Moderator

​问题出现在:

你的工程中My_Printf.c 文件中关于在不同编译器下定义的printf()函数原型的定义出错了。

#if defined (__GNUC__)
/*******************************************************************************
* Function Name: _write
********************************************************************************
* Summary:
* NewLib C library is used to retarget printf to _write. printf is redirected to
* this function when GCC compiler is used to print data to terminal using UART.
*
* \param file
* This variable is not used.
* \param *ptr
* Pointer to the data which will be transfered through UART.
* \param len
* Length of the data to be transfered through UART.
*
* \return
* returns the number of characters transferred using UART.
* \ref int
*******************************************************************************/
   
    asm (".global _printf_float");

   int _write(int file, char *ptr, int len)
    {
        int nChars = 0;

        /* Suppress the compiler warning about an unused variable. */
        if (0 != file)
        {
        }
               
        nChars = Cy_SCB_UART_PutArray(Uart_Printf_HW, ptr, len);
          
        return (nChars);
       
      
       
    }
#elif defined(__ARMCC_VERSION)

在定义的 _write()函数之前加上     asm (".global _printf_float");

View solution in original post

0 Likes
Top labels