| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

Data Structures | Macros | Enumerations | Functions | Variables
retarget.c File Reference

NUC472/NUC442 Debug Port and Semihost Setting Source File. More...

`#include <stdio.h>`
`#include "NUC472_442.h"`
Include dependency graph for retarget.c:

Go to the source code of this file.

## Data Structures
struct | __FILE

## Macros
#define | DEBUG_PORT UART0

## Enumerations
enum | { r0 , r1 , r2 , r3 , r12 , lr , pc , psr }

## Functions
static void | stackDump (uint32_t stack[])
| Helper function to dump register while hard fault occurred. More...
void | Hard_Fault_Handler (uint32_t stack[])
| Hard fault handler. More...
__asm int32_t | HardFault_Handler (void)
| This HardFault handler is implemented to show r0, r1, r2, r3, r12, lr, pc, psr. More...
void | SendChar_ToUART (int ch)
| Write a char to UART. More...
void | SendChar (int ch)
| Write a char to debug console. More...
char | GetChar (void)
| Read a char from debug console. More...
int | kbhit (void)
| Check whether UART receive FIFO is empty or not. More...
int | IsDebugFifoEmpty (void)
| Check whether UART transmit FIFO is empty or not. More...
void | _ttywrch (int ch)
| C library retargetting. More...
int | fputc (int ch, FILE *stream)
| Write character to stream. More...
int | fgetc (FILE *stream)
| Get character from UART debug port or semihosting input. More...
int | ferror (FILE *stream)
| Check error indicator. More...

## Variables
FILE | __stdout
FILE | __stdin

## Detailed Description

NUC472/NUC442 Debug Port and Semihost Setting Source File.

Version
  V1.00

Revision
  12

Date
  15/10/30 3:33p

Note
  SPDX-License-Identifier: Apache-2.0 Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.

Definition in file retarget.c.

## Macro Definition Documentation

## ◆ DEBUG_PORT

#define DEBUG_PORT UART0

Definition at line 395 of file retarget.c.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
r0 |
r1 |
r2 |
r3 |
r12 |
lr |
pc |
psr |

Definition at line 51 of file retarget.c.

## Function Documentation

## ◆ _ttywrch()

void _ttywrch | ( | int | ch | ) |

C library retargetting.

Parameters

  ch | Character to send out

Returns
  None

Check if message finished (FIFO empty of debug port)

Definition at line 521 of file retarget.c.

Here is the call graph for this function:

## ◆ ferror()

int ferror | ( | FILE * | stream | ) |

Check error indicator.

Parameters

  [in] | stream | Pointer to a FILE object that identifies the stream.

Returns
  If the error indicator associated with the stream was set, the function returns a nonzero value. Otherwise, it returns a zero value.

Checks if the error indicator associated with stream is set, returning a value different from zero if it is. This indicator is generally set by a previous operation on the stream that failed.

Note
  The above descriptions are copied from http://www.cplusplus.com/reference/clibrary/cstdio/ferror/.

Definition at line 596 of file retarget.c.

## ◆ fgetc()

int fgetc | ( | FILE * | stream | ) |

Get character from UART debug port or semihosting input.

Parameters

  [in] | stream | Pointer to a FILE object that identifies the stream on which the operation is to be performed.

Returns
  The character read from UART debug port or semihosting

For get message from debug port or semihosting.

Definition at line 582 of file retarget.c.

Here is the call graph for this function:

## ◆ fputc()

int fputc | ( | int | ch,
|  | FILE * | stream
| ) |  |

Write character to stream.

Parameters

  [in] | ch | Character to be written. The character is passed as its int promotion.
  [in] | stream | Pointer to a FILE object that identifies the stream where the character is to be written.

Returns
  If there are no errors, the same character that has been written is returned. If an error occurs, EOF is returned and the error indicator is set (see ferror).

Writes a character to the stream and advances the position indicator.
The character is written at the current position of the stream as indicated
by the internal position indicator, which is then advanced one character.

Note
  The above descriptions are copied from http://www.cplusplus.com/reference/clibrary/cstdio/fputc/.

Definition at line 569 of file retarget.c.

Here is the call graph for this function:

## ◆ GetChar()

char GetChar | ( | void |  | ) |

Read a char from debug console.

Parameters

  None |

Returns
  Received character from debug console

Note
  This API waits until UART debug port or semihost input a character

Definition at line 449 of file retarget.c.

Here is the caller graph for this function:

## ◆ Hard_Fault_Handler()

void Hard_Fault_Handler | ( | uint32_t | stack[] | ) |

Hard fault handler.

Parameters

  [in] | stack | pointer points to the dumped registers in SRAM

Returns
  None

Note
  Replace while(1) at the end of this function with chip reset if WDT is not enabled for end product

Definition at line 76 of file retarget.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ HardFault_Handler()

__asm int32_t HardFault_Handler | ( | void |  | ) |

This HardFault handler is implemented to show r0, r1, r2, r3, r12, lr, pc, psr.

Parameters

  None |

Returns
  None

This function is implement to print r0, r1, r2, r3, r12, lr, pc, psr

Definition at line 375 of file retarget.c.

Here is the call graph for this function:

## ◆ IsDebugFifoEmpty()

int IsDebugFifoEmpty | ( | void |  | ) |

Check whether UART transmit FIFO is empty or not.

Parameters

  None |

Returns
  UART Tx FIFO empty status

Return values

  1 | UART Tx FIFO is empty
  0 | UART Tx FIFO is not empty

Definition at line 505 of file retarget.c.

## ◆ kbhit()

int kbhit | ( | void |  | ) |

Check whether UART receive FIFO is empty or not.

Parameters

  None |

Returns
  UART Rx FIFO empty status

Return values

  1 | Indicates at least one character is available in UART Rx FIFO
  0 | UART Rx FIFO is empty

Definition at line 489 of file retarget.c.

## ◆ SendChar()

void SendChar | ( | int | ch | ) |

Write a char to debug console.

Parameters

  ch | The character sent to debug console

Returns
  None

Definition at line 419 of file retarget.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ SendChar_ToUART()

void SendChar_ToUART | ( | int | ch | ) |

Write a char to UART.

Parameters

  ch | The character sent to UART.

Returns
  None

Definition at line 402 of file retarget.c.

Here is the caller graph for this function:

## ◆ stackDump()

static void stackDump | ( | uint32_t | stack[] | ) |
| static

Helper function to dump register while hard fault occurred.

Parameters

  [in] | stack | pointer points to the dumped registers in SRAM

Returns
  None

Definition at line 58 of file retarget.c.

Here is the caller graph for this function:

## Variable Documentation

## ◆ __stdin

FILE __stdin

Definition at line 49 of file retarget.c.

## ◆ __stdout

FILE __stdout

Definition at line 48 of file retarget.c.