Skip to content

Commit

Permalink
Fix compile, and tweak wait for debugger work.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Nov 11, 2024
1 parent 493439f commit fdbec8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void DefaultIRQHandler( void )
#if FUNCONF_DEBUG_HARDFAULT
// Wait indefinitely for a debugger to attach.
while( !DidDebuggerAttach() );
printf( "DefaultIRQHandler MSTATUS:%08x MTVAL:%08x MCAUSE:%08x MEPC:%08x\n", (int)__get_MSTATUS(), (int)__get_MTVAL(), (int)__get_MCAUSE(), (int)__get_MEPC() );
printf( "DEAD MSTATUS:%08x MTVAL:%08x MCAUSE:%08x MEPC:%08x\n", (int)__get_MSTATUS(), (int)__get_MTVAL(), (int)__get_MCAUSE(), (int)__get_MEPC() );
#endif
// Infinite Loop
asm volatile( "1: j 1b" );
Expand Down Expand Up @@ -1682,7 +1682,7 @@ WEAK int putchar(int c)
void SetupDebugPrintf( void )
{
// Clear out the sending flag.
*DMDATA1 = 0x0;
*DMDATA1 = 0x00;
*DMDATA0 = 0x80;
}

Expand All @@ -1706,7 +1706,7 @@ int WaitForDebuggerToAttach( int timeout_ms )

// Wait for the sentinel to become zero.
while( !DidDebuggerAttach() ) {
if( (SYSTICKCNT - start) > timeout ) return 1;
if( timeout_ms && (SYSTICKCNT - start) > timeout ) return 1;
}

return 0;
Expand Down
4 changes: 4 additions & 0 deletions ch32v003fun/ch32v003fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -13991,10 +13991,14 @@ void SystemInit(void);
void SetupUART( int uartBRR );

// Returns 1 if timeout reached, 0 otherwise.
// If timeout_ms == 0, wait indefinitely.
// Use DidDebuggerAttach() For a zero-wait way of seeing if it attached.
int WaitForDebuggerToAttach( int timeout_ms );

// Returns 1 if a debugger has activated the debug module.
#if defined(__riscv) || defined(__riscv__) || defined( CH32V003FUN_BASE )
static int DidDebuggerAttach() { return !*DMSTATUS_SENTINEL; }
#endif

// Just a definition to the internal _write function.
int _write(int fd, const char *buf, int size);
Expand Down

0 comments on commit fdbec8a

Please sign in to comment.