diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index 327c5af7..f2776fc2 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -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" ); diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index 4fa76063..7ded648e 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -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. @@ -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 @@ -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 @@ -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 diff --git a/ch32v003fun/ch32v003fun.mk b/ch32v003fun/ch32v003fun.mk index 1ebc330a..de92615c 100644 --- a/ch32v003fun/ch32v003fun.mk +++ b/ch32v003fun/ch32v003fun.mk @@ -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