diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index 4af6ef54580b758f2c9d4c066214bff75a41fc1e..252899ea44da53018651248ea7e0ad5b4c998d8d 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -1015,7 +1015,6 @@ asm volatile( #endif ); - #if defined( FUNCONF_SYSTICK_USE_HCLK ) && FUNCONF_SYSTICK_USE_HCLK SysTick->CTLR = 5; #else diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index 572f5c7a5787cefc0360d2ce82a85b35baff4942..f7823c2ffe53f5ddc7626475e4c5fc0c2c371e60 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -11710,7 +11710,20 @@ typedef struct __IO uint64_t CMP; } SysTick_Type; -#elif defined(CH32V10x) || defined(CH32X03x) +#elif defined(CH32X03x) + +/* memory mapped structure for SysTick */ +typedef struct +{ + __IO uint32_t CTLR; + __IO uint32_t SR; + __IO uint32_t CNTL; + __IO uint32_t CNTH; + __IO uint32_t CMPL; + __IO uint32_t CMPH; +} SysTick_Type; + +#elif defined(CH32V10x) /* memory mapped structure for SysTick */ typedef struct diff --git a/examples_x035/debugprintfdemo/Makefile b/examples_x035/debugprintfdemo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8a29f56f4147e896e3985725b6516dce189c31f9 --- /dev/null +++ b/examples_x035/debugprintfdemo/Makefile @@ -0,0 +1,10 @@ +all : flash + +TARGET:=debugprintfdemo +TARGET_MCU:=CH32X035 + +include ../../ch32v003fun/ch32v003fun.mk + +flash : cv_flash +clean : cv_clean + diff --git a/examples_x035/debugprintfdemo/debugprintfdemo.c b/examples_x035/debugprintfdemo/debugprintfdemo.c new file mode 100644 index 0000000000000000000000000000000000000000..3c65c329c14c6a325949c4b1a539ad9d94e782ad --- /dev/null +++ b/examples_x035/debugprintfdemo/debugprintfdemo.c @@ -0,0 +1,37 @@ +/* Small example showing how to use the SWIO programming pin to + do printf through the debug interface */ + +#include "ch32v003fun.h" +#include <stdio.h> + +uint32_t count; + +int last = 0; +void handle_debug_input( int numbytes, uint8_t * data ) +{ + last = data[0]; + count += numbytes; +} + +int main() +{ + SystemInit(); + + funGpioInitAll(); + + funPinMode( PA0, GPIO_CFGLR_OUT_10Mhz_PP ); + + while(1) + { + GPIOA->BSHR = 1; // Turn on GPIOs + printf( "+%lu %lu\n", count++ ); + Delay_Ms(100); + int i; + for( i = 0; i < 10000; i++ ) + poll_input(); + GPIOA->BSHR = (1<<16); // Turn off GPIODs + printf( "-%lu[%c]\n", count++, last ); + Delay_Ms(100); + } +} + diff --git a/examples_x035/debugprintfdemo/funconfig.h b/examples_x035/debugprintfdemo/funconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..a8a70b30cc8ba3115935c2140704b1a6ab83ebd2 --- /dev/null +++ b/examples_x035/debugprintfdemo/funconfig.h @@ -0,0 +1,9 @@ +#ifndef _FUNCONFIG_H +#define _FUNCONFIG_H + +// Though this should be on by default we can extra force it on. +#define FUNCONF_USE_DEBUGPRINTF 1 +#define FUNCONF_DEBUGPRINTF_TIMEOUT (1<<31) // Wait for a very very long time. + +#endif +