From a6f75b2ce5f4a6d7d625d1753b97c075fc069705 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 30 Jan 2020 17:45:53 +0100 Subject: Finally fixed LED driving code --- gm_platform/fw/main.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'gm_platform/fw/main.c') diff --git a/gm_platform/fw/main.c b/gm_platform/fw/main.c index 5741d7c..74f305b 100644 --- a/gm_platform/fw/main.c +++ b/gm_platform/fw/main.c @@ -21,17 +21,7 @@ volatile unsigned int sys_time_seconds = 0; - -void update_leds() { - -} - -volatile union { - struct { - unsigned int usb, ocxo, error, _nc1, _nc2, _nc3, pps, sd_card; - }; - unsigned int arr[8]; -} leds; +volatile union leds leds; int main(void) { RCC->CR |= RCC_CR_HSEON; @@ -79,22 +69,23 @@ int main(void) { SPI1->CR1 = SPI_CR1_SSM | SPI_CR1_SSI + | SPI_CR1_CPOL + | SPI_CR1_CPHA | (4<CR2 = (7<CR1 |= SPI_CR1_SPE; - NVIC_EnableIRQ(SPI1_IRQn); - NVIC_SetPriority(SPI1_IRQn, 2<<5); - TIM16->CR2 = 0; - TIM16->DIER = TIM_DIER_UIE; + TIM16->DIER = TIM_DIER_UIE | TIM_DIER_CC1IE; + TIM16->CCMR1 = 0; + TIM16->CCR1 = 32; TIM16->PSC = 48-1; /* 1us */ TIM16->ARR = 1000-1; /* 1ms */ TIM16->CR1 = TIM_CR1_CEN; NVIC_EnableIRQ(TIM16_IRQn); - NVIC_SetPriority(TIM16_IRQn, 2<<5); + NVIC_SetPriority(TIM16_IRQn, 3<<5); adc_configure_scope_mode(1000000); @@ -108,21 +99,13 @@ int main(void) { } } -void SPI1_IRQHandler(void) { - if (SPI1->SR & SPI_SR_TXE) { - /* LED_STB */ - GPIOA->BSRR = 1<<3; - SPI1->CR2 &= ~SPI_CR2_TXEIE; - } -} - void TIM16_IRQHandler(void) { static int leds_update_counter = 0; if (TIM16->SR & TIM_SR_UIF) { TIM16->SR &= ~TIM_SR_UIF; uint8_t bits = 0, mask = 1; - for (size_t i=0; iDR)) = bits; - SPI1->CR2 |= SPI_CR2_TXEIE; GPIOA->BRR = 1<<3; } + } else { + TIM16->SR &= ~TIM_SR_CC1IF; + GPIOA->BSRR = 1<<3; } } @@ -166,7 +151,7 @@ void SysTick_Handler(void) { if (n++ == 10) { n = 0; sys_time_seconds++; - leds.pps = 100; /* ms */ + leds.pps = 200; /* ms */ } } -- cgit