From e06eb556635c9a51b4af1973ad5f5f96dc6aac83 Mon Sep 17 00:00:00 2001 From: Eric Brombaugh <ebrombaugh1@cox.net> Date: Sun, 26 Mar 2023 20:07:11 -0700 Subject: [PATCH] Working! --- examples/systick_irq/systick.h | 13 +++++-------- examples/systick_irq/systick_irq.c | 22 ++++++++-------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/examples/systick_irq/systick.h b/examples/systick_irq/systick.h index e681d81..8aaa3ef 100644 --- a/examples/systick_irq/systick.h +++ b/examples/systick_irq/systick.h @@ -29,11 +29,11 @@ void systick_init(void) /* Clear any existing IRQ */ SysTick->SR &= ~SYSTICK_SR_CNTIF; -#if 0 +#if 1 /* Set the tick interval to 1ms for normal op */ SysTick->CMP = (SYSTEM_CORE_CLOCK/1000)-1; #else - /* Set the tick interval to 100ms for debug */ + /* Set the tick interval to 1s for debug */ SysTick->CMP = (SYSTEM_CORE_CLOCK)-1; #endif @@ -49,19 +49,16 @@ void systick_init(void) #if 1 /* * SysTick ISR just counts ticks + * note - the __attribute__((interrupt)) syntax is crucial! */ -void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); -//void SysTick_Handler(void) __attribute__((interrupt("interrupt"))); +void SysTick_Handler(void) __attribute__((interrupt)); void SysTick_Handler(void) { /* clear IRQ */ - SysTick->SR &= ~SYSTICK_SR_CNTIF; + SysTick->SR &= 0; /* update counter */ systick_cnt++; - - printf("systick_cnt = 0x%08X\n\r", systick_cnt); - } #endif diff --git a/examples/systick_irq/systick_irq.c b/examples/systick_irq/systick_irq.c index db9f4c4..589ed89 100644 --- a/examples/systick_irq/systick_irq.c +++ b/examples/systick_irq/systick_irq.c @@ -28,27 +28,21 @@ int main() systick_init(); printf("done.\n\r"); -#if 1 +#if 0 // Debugging - does ISR run & inc counter? // this section shows that IRQs during print will reset system, but during // inf while() do not. - //while(1) - //for(int i=0;i<20;i++) - //{ - //printf("i = %d ", i); - printf("CNT = 0x%08X ", SysTick->CNT); - printf("systick_cnt = 0x%08X\n\r", systick_cnt); - //} // does cnt inc? - //uint32_t pcnt = systick_cnt; + uint32_t pcnt = systick_cnt; while(1) { - //if(pcnt != systick_cnt) - //{ - // printf("systick_cnt = %d\n\r", systick_cnt); - // pcnt = systick_cnt; - //} + if(pcnt != systick_cnt) + { + printf("CNT = 0x%08X ", SysTick->CNT); + printf("systick_cnt = %d\n\r", systick_cnt); + pcnt = systick_cnt; + } } #else // Testing 1ms Systick -- GitLab