Skip to content

Commit

Permalink
Merge pull request #386 from cnlohr/debug-flag
Browse files Browse the repository at this point in the history
Add "DEBUG" flag that can be set in Makefile
  • Loading branch information
eeucalyptus authored Sep 13, 2024
2 parents a825029 + e9128ba commit 486fd2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ extern uint32_t * _edata;
void DefaultIRQHandler( void )
{
// Infinite Loop
#if defined( DEBUG )
#if FUNCONF_DEBUG
printf( "DefaultIRQHandler MSTATUS:%08x MTVAL:%08x MCAUSE:%08x MEPC:%08x\n", (int)__get_MSTATUS(), (int)__get_MTVAL(), (int)__get_MCAUSE(), (int)__get_MEPC() );
#endif
asm volatile( "1: j 1b" );
Expand Down
9 changes: 5 additions & 4 deletions ch32v003fun/ch32v003fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#define FUNCONF_DEBUGPRINTF_TIMEOUT 160000 // Arbitrary time units
#define FUNCONF_ENABLE_HPE 1 // Enable hardware interrupt stack. Very good on QingKeV4, i.e. x035, v10x, v20x, v30x, but questionable on 003.
#define FUNCONF_USE_5V_VDD 0 // Enable this if you plan to use your part at 5V - affects USB and PD configration on the x035.
#define FUNCONF_DEBUG 0 // Log fatal errors with "printf"
*/

// Sanity check for when porting old code.
Expand Down Expand Up @@ -110,6 +111,10 @@
#endif
#endif

#if !defined( FUNCONF_DEBUG )
#define FUNCONF_DEBUG 0
#endif

#if defined( CH32X03x ) && FUNCONF_USE_PLL
#error No PLL on the X03x
#endif
Expand Down Expand Up @@ -13432,8 +13437,6 @@ static inline void __set_MCAUSE(uint32_t value)
__ASM volatile("csrw mcause, %0":: "r"(value));
}

#if defined(CH32V10x) || defined(CH32V20x) || defined(CH32V30x)

/*********************************************************************
* @fn __get_MTVAL
* @brief Return the Machine Trap Value Register
Expand All @@ -13457,8 +13460,6 @@ static inline void __set_MTVAL(uint32_t value)
__ASM volatile ("csrw mtval, %0" : : "r" (value) );
}

#endif

/*********************************************************************
* @fn __get_MVENDORID
* @brief Return Vendor ID Register
Expand Down
4 changes: 4 additions & 0 deletions ch32v003fun/ch32v003fun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ MINICHLINK?=$(CH32V003FUN)/../minichlink
WRITE_SECTION?=flash
SYSTEM_C?=$(CH32V003FUN)/ch32v003fun.c

ifeq ($(DEBUG),1)
EXTRA_CFLAGS+=-DFUNCONF_DEBUG=1
endif

CFLAGS?=-g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8
LDFLAGS+=-Wl,--print-memory-usage

Expand Down

0 comments on commit 486fd2a

Please sign in to comment.