M480 BSP V3.05.006
The Board Support Package for M480 Series
Macros | Enumerations | Functions | Variables
retarget.c File Reference

M480 Series Debug Port and Semihost Setting Source File. More...

#include <stdio.h>
#include "NuMicro.h"

Go to the source code of this 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...
 
static void SendChar_ToUART (int ch)
 Routine to send a char. More...
 
static void SendChar (int ch)
 Routine to send a char. More...
 
static char GetChar (void)
 Routine to get a char. More...
 
int kbhit (void)
 Check any char input from UART. More...
 
int IsDebugFifoEmpty (void)
 Check if debug message finished. 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

M480 Series Debug Port and Semihost Setting Source File.

Version
V3.00

SPDX-License-Identifier: Apache-2.0

Definition in file retarget.c.

Macro Definition Documentation

◆ DEBUG_PORT

#define DEBUG_PORT   UART0

Definition at line 30 of file retarget.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
r0 
r1 
r2 
r3 
r12 
lr 
pc 
psr 

Definition at line 41 of file retarget.c.

Function Documentation

◆ _ttywrch()

void _ttywrch ( int  ch)

C library retargetting.

Parameters
[in]chCharacter to send to debug port.
Returns
None

Check if message finished (FIFO empty of debug port)

Definition at line 637 of file retarget.c.

◆ ferror()

int ferror ( FILE *  stream)

Check error indicator.

Parameters
[in]streamPointer 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 732 of file retarget.c.

◆ fgetc()

int fgetc ( FILE *  stream)

Get character from UART debug port or semihosting input.

Parameters
[in]streamPointer 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 712 of file retarget.c.

◆ fputc()

int fputc ( int  ch,
FILE *  stream 
)

Write character to stream.

Parameters
[in]chCharacter to be written. The character is passed as its int promotion.
[in]streamPointer 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 662 of file retarget.c.

◆ GetChar()

static char GetChar ( void  )
static

Routine to get a char.

Parameters
None
Returns
Get value from UART debug port or semihost

Wait UART debug port or semihost to input a char.

Definition at line 551 of file retarget.c.

◆ Hard_Fault_Handler()

void Hard_Fault_Handler ( uint32_t  stack[])

Hard fault handler.

Parameters
[in]stackpointer points to the dumped registers in SRAM
Returns
None

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

Definition at line 67 of file retarget.c.

◆ 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

The function extracts the location of stack frame and passes it to Hard_Fault_Handler function as a pointer

Definition at line 401 of file retarget.c.

◆ IsDebugFifoEmpty()

int IsDebugFifoEmpty ( void  )

Check if debug message finished.

Parameters
None
Return values
1Message is finished
0Message is transmitting.

Check if message finished (FIFO empty of debug port)

Definition at line 618 of file retarget.c.

◆ kbhit()

int kbhit ( void  )

Check any char input from UART.

Parameters
None
Return values
1No any char input
0Have some char input

Check UART RSR RX EMPTY or not to determine if any char input from UART

Definition at line 599 of file retarget.c.

◆ SendChar()

static void SendChar ( int  ch)
static

Routine to send a char.

Parameters
[in]chCharacter to send to debug port.
Returns
Send value from UART debug port or semihost

Send a target char to UART debug port or semihost.

Definition at line 511 of file retarget.c.

◆ SendChar_ToUART()

static void SendChar_ToUART ( int  ch)
static

Routine to send a char.

Parameters
[in]chCharacter to send to debug port.
Returns
Send value from UART debug port

Send a target char to UART debug port .

Definition at line 432 of file retarget.c.

◆ stackDump()

static void stackDump ( uint32_t  stack[])
static

Helper function to dump register while hard fault occurred.

Parameters
[in]stackpointer points to the dumped registers in SRAM
Returns
None

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

Definition at line 49 of file retarget.c.

Variable Documentation

◆ __stdin

FILE __stdin

Definition at line 38 of file retarget.c.

◆ __stdout

FILE __stdout

Definition at line 37 of file retarget.c.