Forum: Mikrocontroller und Digitale Elektronik CooCox printf auf andere UART umleiten


von Hans (Gast)


Lesenswert?

Gibt es eine Möglichkeit, printf auch mit anderen USARTS wie USART1 zu 
benutzen und falls ja, wie und wo stellt man das ein?


Danke und schöne Grüße

von Jens A. (nepi)


Lesenswert?

Die Ausgabe der einzelnen Zeichen ist in einer Funktion PutChar. Dort 
muß dann das entsprechende Register stehen.
Der Port muß entsprechend initialisiert sein und der Takt für die 
genuzten Baugruppen aktiv sein.
Welcher Contröller ist es denn?

von Hans (Gast)


Lesenswert?

Der STM32F407.

von Uhu (Gast)


Lesenswert?

PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(EVAL_COM3, (uint8_t) ch);

  /* Loop until the end of transmission */
  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  {}

  return ch;
}

Diese Funktion in main.c einbinden und anpassen ..

von Uhu (Gast)


Lesenswert?

Korrektur:


#ifdef _GNUC_
  /* With GCC/RAISONANCE, small printf (option LD 
Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* _GNUC_ */

PUTCHAR_PROTOTYPE                //printf UART umleiten
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART3, (uint8_t) ch);

  /* Loop until the end of transmission */
  while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET)
  {}

  return ch;
}


Gruß

von Hans (Gast)


Lesenswert?

Viele Dank funzt!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.