Added better debug function

This commit is contained in:
Logan G 2024-01-05 04:17:56 -07:00
parent 7cc32ba7f2
commit cffa7de486
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 43 additions and 5 deletions

View file

@ -28,7 +28,31 @@ static uint16_t p_ms = 0;
void Delay_Init(void) void Delay_Init(void)
{ {
p_us = SystemCoreClock / 8000000; p_us = SystemCoreClock / 8000000;
p_ms = (uint16_t)p_us * 1000; p_ms = p_us * 1000;
SysTick->CTLR &= ~0x8000001F;
SysTick->CNT = 0;
SysTick->CTLR |= (1 << 0);
}
uint64_t SysTick_Read(void)
{
uint64_t ticks;
SysTick->CTLR &= ~(1 << 0);
ticks = SysTick->CNT;
SysTick->CTLR |= (1 << 0);
return ticks;
}
uint64_t SysTick_Us(void)
{
return SysTick_Read() / p_us;
}
uint64_t SysTick_Ms(void)
{
return SysTick_Read() / p_ms;
} }
/********************************************************************* /*********************************************************************
@ -47,12 +71,18 @@ void Delay_Us(uint32_t n)
SysTick->SR &= ~(1 << 0); SysTick->SR &= ~(1 << 0);
i = (uint32_t)n * p_us; i = (uint32_t)n * p_us;
SysTick->CMP = SysTick_Read() + i;
while((SysTick->SR & (1 << 0)) != (1 << 0));
/*
SysTick->CMP = i; SysTick->CMP = i;
SysTick->CNT = 0; SysTick->CTLR |= (1 << 4);
SysTick->CTLR |=(1 << 0); SysTick->CTLR |= (1 << 5) | (1 << 0);
while((SysTick->SR & (1 << 0)) != (1 << 0)); while((SysTick->SR & (1 << 0)) != (1 << 0));
SysTick->CTLR &= ~(1 << 0); SysTick->CTLR &= ~(1 << 0);
*/
} }
/********************************************************************* /*********************************************************************
@ -71,12 +101,17 @@ void Delay_Ms(uint32_t n)
SysTick->SR &= ~(1 << 0); SysTick->SR &= ~(1 << 0);
i = (uint32_t)n * p_ms; i = (uint32_t)n * p_ms;
SysTick->CMP = SysTick_Read() + i;
while((SysTick->SR & (1 << 0)) != (1 << 0));
/*
SysTick->CMP = i; SysTick->CMP = i;
SysTick->CNT = 0; SysTick->CTLR |= (1 << 4);
SysTick->CTLR |=(1 << 0); SysTick->CTLR |= (1 << 5) | (1 << 0);
while((SysTick->SR & (1 << 0)) != (1 << 0)); while((SysTick->SR & (1 << 0)) != (1 << 0));
SysTick->CTLR &= ~(1 << 0); SysTick->CTLR &= ~(1 << 0);
*/
} }
/********************************************************************* /*********************************************************************

View file

@ -40,6 +40,9 @@
#endif #endif
void Delay_Init(void); void Delay_Init(void);
uint64_t SysTick_Read(void);
uint64_t SysTick_Us(void);
uint64_t SysTick_Ms(void);
void Delay_Us(uint32_t n); void Delay_Us(uint32_t n);
void Delay_Ms(uint32_t n); void Delay_Ms(uint32_t n);
void USART_Printf_Init(uint32_t baudrate); void USART_Printf_Init(uint32_t baudrate);