cancel
Showing results for 
Search instead for 
Did you mean: 

printf

ybitton
Associate II
Posted on March 08, 2011 at 16:45

Hi Guys,

I am using STM32 eval board on IAR.

 How can i use ''printf''?

 Is there a library i shuold include?

Thanks - Udi
3 REPLIES 3
Posted on March 09, 2011 at 04:09

Isn't it in DLIB?

General Option -> Library Configuration or Library Options

Seeing as you probably don't have a UART attached to your VL board, this might be a suitable cite.

printf via SWO

http://www.iar.com/website1/1.0.1.0/2839/1/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 09, 2011 at 15:54

Is there a way to send string messages over the SWO using the Atollic TrueSTUDIO tool?  Or, does this only work with IAR?  Maybe there is a ST tool that would let me see the strings even if I'm using TrueSTUDIO?

Having a way to send string messages over the USB connection would solve a big complaint that people have with the Discovery board. 

Posted on March 09, 2011 at 18:52

Jim, it is fairly straight forward to push data across the channel. It works like the DCC (Debug Communications Channel) on the older ARMs.

Keil supposedly supports it, but my brief experiment with the semi-hosting wasn't up and working quickly enough, so I wire-wrapped a serial-to-usb adapter onto the thing an moved on. It could be that the ST-LINK doesn't support it. I might experiment some more.

The problem is how to get a terminal at the PC end. You could try binding it to the character interface of Atollic.

From CORE_CM3.H in your trusty library

/* ##################################### Debug In/Output function ########################################### */

/** @addtogroup CMSIS_CM3_CoreDebugInterface CMSIS CM3 Core Debug Interface

  Core Debug Interface containing:

  - Core Debug Receive / Transmit Functions

  - Core Debug Defines

  - Core Debug Variables

*/

/*@{*/

extern volatile int ITM_RxBuffer;                    /*!< variable to receive characters                             */

#define             ITM_RXBUFFER_EMPTY    0x5AA55AA5 /*!< value identifying ITM_RxBuffer is ready for next character */

/**

 * @brief  Outputs a character via the ITM channel 0

 *

 * @param  ch   character to output

 * @return      character to output

 *

 * The function outputs a character via the ITM channel 0.

 * The function returns when no debugger is connected that has booked the output.

 * It is blocking when a debugger is connected, but the previous character send is not transmitted.

 */

static __INLINE uint32_t ITM_SendChar (uint32_t ch)

{

  if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)  &&      /* Trace enabled */

      (ITM->TCR & ITM_TCR_ITMENA_Msk)                  &&      /* ITM enabled */

      (ITM->TER & (1ul << 0)        )                    )     /* ITM Port #0 enabled */

  {

    while (ITM->PORT[0].u32 == 0);

    ITM->PORT[0].u8 = (uint8_t) ch;

  }

  return (ch);

}

/**

 * @brief  Inputs a character via variable ITM_RxBuffer

 *

 * @return      received character, -1 = no character received

 *

 * The function inputs a character via variable ITM_RxBuffer.

 * The function returns when no debugger is connected that has booked the output.

 * It is blocking when a debugger is connected, but the previous character send is not transmitted.

 */

static __INLINE int ITM_ReceiveChar (void) {

  int ch = -1;                               /* no character available */

  if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {

    ch = ITM_RxBuffer;

    ITM_RxBuffer = ITM_RXBUFFER_EMPTY;       /* ready for next character */

  }

  return (ch);

}

/**

 * @brief  Check if a character via variable ITM_RxBuffer is available

 *

 * @return      1 = character available, 0 = no character available

 *

 * The function checks  variable ITM_RxBuffer whether a character is available or not.

 * The function returns '1' if a character is available and '0' if no character is available.

 */

static __INLINE int ITM_CheckChar (void) {

  if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {

    return (0);                                 /* no character available */

  } else {

    return (1);                                 /*    character available */

  }

}

/*@}*/ /* end of group CMSIS_CM3_core_DebugInterface */

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..