Skip to main content
Visitor II
October 8, 2018
Question

STM8S Printf retargeting doesn't like IAR Discard unused publics

  • October 8, 2018
  • 0 replies
  • 764 views

Hi all.

I'm trying to implement printf retargeting in my project, based on STM8S105 microcontroller.

I'm using IAR (3.10 & 2.20) and I'm utilizing printf retargeting example from ST. The problem is, if I try to compile the project with "Discard unused publics" option enabled, it stops working.

When I enable "Discard unused publics" option, I don't see any errors or warnings. I even decided to load original example from ST, and got the same results: with "Discard unused publics" option enabled retargeting stops working.

Can anyone give an Idea, what can cause such a problem?

Part of code, related to retargeting:

#ifdef _RAISONANCE_

#define PUTCHAR_PROTOTYPE int putchar (char c)

#define GETCHAR_PROTOTYPE int getchar (void)

#elif defined (_COSMIC_)

#define PUTCHAR_PROTOTYPE char putchar (char c)

#define GETCHAR_PROTOTYPE char getchar (void)

#else /* _IAR_ */

#define PUTCHAR_PROTOTYPE int extern putchar (int c)

#define GETCHAR_PROTOTYPE int getchar (void)

#endif /* _RAISONANCE_ */

/**

 * @brief Retargets the C library printf function to the UART.

 * @param c Character to send

 * @retval char Character sent

 */

PUTCHAR_PROTOTYPE

{

 /* Write a character to the UART */

 UART2_SendData8(c);

 /* Loop until the end of transmission */

 while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET);

 return (c);

}

/**

 * @brief Retargets the C library scanf function to the USART.

 * @param None

 * @retval char Character to Read

 */

GETCHAR_PROTOTYPE

{

#ifdef _COSMIC_

 char c = 0;

#else

 int c = 0;

#endif

 /* Loop until the Read data register flag is SET */

 while (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET);

  c = UART2_ReceiveData8();

 return (c);

}

    This topic has been closed for replies.