Use SysTick instead of TIM3 for printing

This commit is contained in:
fruchti 2018-08-05 13:04:30 +02:00
parent d47ef99119
commit 8247add832
2 changed files with 40 additions and 48 deletions

View file

@ -1 +1 @@
233 323

View file

@ -24,11 +24,13 @@ static volatile State_t State = {State_Idle};
static void InitStepper(void) static void InitStepper(void)
{ {
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
// PA15 is used for stepper control, so JTAG has to be disabled // PA15 is used for stepper control, so JTAG has to be disabled
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1; AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;
GPIOA->BRR = (1 << PIN_STEPPER_AM) | (1 << PIN_STEPPER_AP)
| (1 << PIN_STEPPER_BM) | (1 << PIN_STEPPER_BP);
GPIOA->CRH = (GPIOA->CRH GPIOA->CRH = (GPIOA->CRH
& ~(0x0f << (4 * PIN_STEPPER_AM - 32)) & ~(0x0f << (4 * PIN_STEPPER_AM - 32))
& ~(0x0f << (4 * PIN_STEPPER_AP - 32)) & ~(0x0f << (4 * PIN_STEPPER_AP - 32))
@ -40,13 +42,8 @@ static void InitStepper(void)
| (0x01 << (4 * PIN_STEPPER_BP - 32)) // Output, max. 10 MHz | (0x01 << (4 * PIN_STEPPER_BP - 32)) // Output, max. 10 MHz
; ;
TIM3->PSC = 48000000 / 100 / LTP1245_MAX_DRIVE_FREQ - 1; // The SysTick is clocked by AHB / 8
TIM3->ARR = 100; SysTick_Config(48000000 / 8 / LTP1245_MAX_DRIVE_FREQ - 1);
TIM3->DIER = TIM_DIER_UIE;
TIM3->CR1 = TIM_CR1_CEN;
NVIC_SetPriority(TIM3_IRQn, 1);
NVIC_EnableIRQ(TIM3_IRQn);
} }
static void InitSensors(void) static void InitSensors(void)
@ -380,10 +377,8 @@ void AdvanceStateMachine(void)
State = State.fn(); State = State.fn();
} }
void TIM3_IRQHandler(void) void SysTick_Handler(void)
{ {
if(TIM3->SR & TIM_SR_UIF)
{
static int substep = 0; static int substep = 0;
static bool off; static bool off;
const int TABLE[] = {0, 1, 3, 2}; const int TABLE[] = {0, 1, 3, 2};
@ -425,9 +420,6 @@ void TIM3_IRQHandler(void)
} }
AdvanceStateMachine(); AdvanceStateMachine();
TIM3->SR &= ~TIM_SR_UIF;
}
} }
void ADC1_2_IRQHandler(void) void ADC1_2_IRQHandler(void)