I moved your topic to an appropriate forum category @satishmunot.
In the future, when creating a topic please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
tried your timer code and as stated it locks up
added some print statements and it appears to fail when configuring the Nested Vectored Interrupt Controller (NVIC)
I assume the attempt to configure the CH32 NVIC is clashing with the Arduino CH32 setup
have a look at Arduino Timer Interrupts for the CH32V003 WCH MCU which uses the CH32 HardwareTimer library function
however the document states Board Manager version 1.0.4 will not work with this sketch because it requires the HardwareTimer function.
this is a verion of the example with minor modifications (change the LED GPIO pin to PD4 and printing an * in loop() when in timer interrupt occurs)
also some documentation on how to install the HardwareTimer function.
// CH32V003 HardwareTimer.h library test
// original code from https://www.instructables.com/Arduino-Timer-Interrupts-for-the-CH32V003-WCH-MCU/
// NOTE: CH32 1.0.4 board manager does not include "HardwareTimer.h"
// 1. download https://github.com/openwch/arduino_core_ch32 and unzip
// 2. open C:\Users\<username>\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.4 and delete contents
// 3: copy contents of C:\Users\<username>\Downloads\arduino_core_ch32-main\arduino_core_ch32-main
/* e.g. should look like
PS C:\Users\xx> cd C:\Users\xx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.4
PS C:\Users\xx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.4> dir
Directory: C:\Users\xx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.4
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/02/2026 07:34 cores
d----- 10/02/2026 07:34 libraries
d----- 10/02/2026 07:34 system
d----- 10/02/2026 07:34 tools
d----- 10/02/2026 07:34 variants
-a---- 10/02/2026 05:33 7 .gitignore
-a---- 10/02/2026 05:33 156 .gitmodules
-a---- 10/02/2026 05:33 43574 boards.txt
-a---- 10/02/2026 05:33 202 package.json
-a---- 10/02/2026 05:33 9206 platform.txt
-a---- 10/02/2026 05:33 0 programmers.txt
-a---- 10/02/2026 05:33 4564 README.md
*/
// (c) 2024 Pablo Montoreano
/*******************************************************
simple Blink sketch using a timer
for WCH CH32V003
compile selecting CH32V00x board
to compile this sketch you will need a Board Manager version that includes
HardwareTimer (as of today 30/Sep/24 unpublished, I had to force install it from github)
no 3rd party libraries used
*********************************************************/
#include "HardwareTimer.h"
HardwareTimer myTimer(TIM2);
static const unsigned int myPort= PD4; // output port (this is the onboard LED port)
static volatile int myLED;
static bool interrupted=false; // flag set true on interrupt
// timer interrupt routine
void timerHandler(void) {
myTimer.pause();
myLED= (myLED == HIGH) ? LOW : HIGH; // blink LED
digitalWrite(myPort, myLED);
myTimer.setOverflow(1000000, MICROSEC_FORMAT);
myTimer.resume();
interrupted=true; // flag indicates interrupt
}
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("\n\nCH32V003 HardwareTimer.h library test");
pinMode(myPort, OUTPUT);
myLED= LOW;
digitalWrite(myPort, myLED); // start pulse for channel sep
myTimer.setOverflow(1000000, MICROSEC_FORMAT); // interrupt every second
myTimer.attachInterrupt(timerHandler);
myTimer.resume();
}
// on timer interrupt print *
void loop() {
if(interrupted) {
interrupted=false;
Serial.print('*');
}
}
LED blinks and Serial monitor outputs
CH32V003 HardwareTimer.h library test
******************************************
the CH32 is an interesting device but is lacking documentation and the CH32 MCU EVT Boards V1.0.4 is missing some functions