void  App_SerPrintf (CPU_CHAR  *p_fmt,
                     ...)
{
    CPU_CHAR    str[80u + 1u];
    CPU_SIZE_T  len;
    SERIAL_ERR  err;
    va_list     vArgs;


    va_start(vArgs, p_fmt);

    vsprintf((char       *)str,
             (char const *)p_fmt,
                           vArgs);

    va_end(vArgs);

    len = Str_Len(str);

    Serial_Wr((SERIAL_IF_NBR   )App_SerTraceIF_Nbr,
              (void           *)&str[0u],
              (CPU_SIZE_T      )len,
              (CPU_INT32U      )0u,
              (SERIAL_ERR     *)&err);

}
/*****************************************************
	Function name:	Serial_puts( unsigned char *str )
	Return 		: nil
	Argument	: unsigned char data
	purpose:	Displays a STRING  in hyper terminal
********************************************************************

******/
void Serial_puts( unsigned char *str )
	{
		while(*str)
		{
			Serial_Wr(*str++);
		}

	}
/*******************************************************************

********
* Function: Serial_putUBYTE
* Purpose:  Function to display an 8 bit unsigned number on 

hyperterminal
* Parameters: number
*             number should be unsigned   
*             Range supported 0 to 255
*             No Error checking done pass the input correctly
*             e.g if number is 0xff it will be displayed as 255 on 

hyperterminal
********************************************************************

**************/
void Serial_putUBYTE ( unsigned char number )
{
  unsigned char dig3,dig2,dig1;
  
  // Get the MSB
  dig3 = number / 100;
  number = number % 100;

  // Get the 2 LSB's
  dig2 = number / 10;
  dig1 = number % 10; 
  if(dig3!=0) 						//if the the msb is not zero then the number contains 3 digit 
  	{
  		Serial_Wr(toAscii(dig3));
  		Serial_Wr(toAscii(dig2));
  	}
  else if(dig2!=0)	  				// if the number contains only 2 digit
  	{
		Serial_Wr(toAscii(dig2));
  		
	}
  Serial_Wr(toAscii(dig1));	  			// lsb 
  }
CPU_BOOLEAN  App_SerialInit (void)
{
    SERIAL_ERR     err;
#if (APP_SERIAL_CFG_TRACE_EN == DEF_ENABLED)
    SERIAL_IF_CFG  uart_cfg;
#endif

    Serial_Init();                                             /* Initial Serial module                                */

    Serial_DevDrvAdd((CPU_CHAR       *)"USART3",               /* Add serial interface/device.                         */
                     (SERIAL_DEV_CFG *)&SerialDevCfg_STM32_USART3,
                     (CPU_SIZE_T      ) 52u,
                     (CPU_SIZE_T      ) 52u,
                     (SERIAL_ERR     *)&err);

    if (err != SERIAL_ERR_NONE) {
        return (DEF_FAIL);
    }

#if (APP_SERIAL_CFG_TRACE_EN == DEF_ENABLED)
    uart_cfg.Baudrate = SERIAL_BAUDRATE_115200;
    uart_cfg.DataBits = SERIAL_DATABITS_8;
    uart_cfg.StopBits = SERIAL_STOPBITS_1;
    uart_cfg.Parity   = SERIAL_PARITY_NONE;
    uart_cfg.FlowCtrl = SERIAL_FLOW_CTRL_NONE;


    App_SerTraceIF_Nbr = Serial_Open((CPU_CHAR      *)APP_SERIAL_CFG_TRACE_PORT_NAME,
                                     (SERIAL_IF_CFG *)&uart_cfg,
                                     (SERIAL_ERR    *)&err);
    if (err != SERIAL_ERR_NONE) {
        return (DEF_FAIL);
    }

    Serial_SetLineDrv((SERIAL_IF_NBR        ) App_SerTraceIF_Nbr,
                      (SERIAL_LINE_DRV_API *)&SerialLine_TTY ,
                      (SERIAL_ERR          *)&err);

    Serial_Wr((SERIAL_IF_NBR   )App_SerTraceIF_Nbr,
              (void           *)"\n\n",
              (CPU_SIZE_T      )2u,
              (CPU_INT32U      )0u,
              (SERIAL_ERR     *)&err);

    if (err != SERIAL_ERR_NONE) {
        return (DEF_FAIL);
    }
#endif
    return (DEF_OK);
}
void  App_SerStrWr (CPU_CHAR  *p_str)
{
    CPU_SIZE_T  len;
    SERIAL_ERR  err;


    if (p_str == (CPU_CHAR *)0u) {
        return;
    }

    len = Str_Len(p_str);

    Serial_Wr((SERIAL_IF_NBR   )App_SerTraceIF_Nbr,
              (void           *)p_str,
              (CPU_SIZE_T      )len,
              (CPU_INT32U      )0u,
              (SERIAL_ERR     *)&err);
}
void Serial_putUINT16 ( unsigned int number )
{
  unsigned char dig5,dig4,dig3,dig2,dig1;
  
  // Get the Digit5
  dig5 = number / 10000;
  number = number % 10000;

  // Get Digit4
  dig4 = number / 1000;
  number = number % 1000;

  // Get Digit3
  dig3 = number / 100;
  number = number % 100;

  // Get Digit2 and Digit1
  dig2 = number / 10;
  dig1 = number % 10;

  if(dig5 != 0)
	{  
		Serial_Wr(toAscii(dig5));
		Serial_Wr(toAscii(dig4));
		Serial_Wr(toAscii(dig3));
  		Serial_Wr(toAscii(dig2));
	}
	else if(dig4 != 0)
	{
		Serial_Wr(toAscii(dig4));
		Serial_Wr(toAscii(dig3));
  		Serial_Wr(toAscii(dig2));
	}
	else if(dig3!=0)
  	{
  		Serial_Wr(toAscii(dig3));
  		Serial_Wr(toAscii(dig2));
  		//Serial_Wr(toAscii(dig1));
  	}
  	else if(dig2!=0)
  	{
		Serial_Wr(toAscii(dig2));
  		
	}
  Serial_Wr(toAscii(dig1));

 
}