diff options
Diffstat (limited to 'controller/fw/src/main.c')
-rw-r--r-- | controller/fw/src/main.c | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/controller/fw/src/main.c b/controller/fw/src/main.c index c03bcbb..fa5d50b 100644 --- a/controller/fw/src/main.c +++ b/controller/fw/src/main.c @@ -3,6 +3,7 @@ #include <stdint.h> #include <assert.h> #include <string.h> +#include <math.h> #include <stm32f407xx.h> @@ -159,50 +160,52 @@ void spi_flash_test(void) { static unsigned int measurement_errors = 0; static struct dsss_demod_state demod_state; static uint32_t freq_sample_ts = 0; -static uint32_t debug_last_freq = 0; +static float debug_last_freq = 0; int main(void) { - /* DEBUG */ - /* MCO2 */ +#if DEBUG + /* PLL clock on MCO2 (pin C9) */ RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; GPIOC->MODER &= ~GPIO_MODER_MODER9_Msk; GPIOC->MODER |= (2<<GPIO_MODER_MODER9_Pos); GPIOC->AFR[1] &= ~GPIO_AFRH_AFSEL9_Msk; GPIOC->OSPEEDR |= (3<<GPIO_OSPEEDR_OSPEED9_Pos); /* SCK */ RCC->CFGR |= (6<<RCC_CFGR_MCO2PRE_Pos) | (3<<RCC_CFGR_MCO2_Pos); - /* END DEBUG */ +#endif + + if (((SCB->CPACR>>20) & 0xf) != 0xf) { + asm volatile ("bkpt"); + } clock_setup(); led_setup(); - /* spi_flash_setup(); adc_init(); - */ - /* DEBUG */ - /* TIM1 CC1 */ +#if DEBUG + /* TIM1 CC1 (ADC trigger) on pin A8 */ GPIOA->MODER &= ~GPIO_MODER_MODER8_Msk; GPIOA->MODER |= (2<<GPIO_MODER_MODER8_Pos); GPIOA->AFR[1] &= ~GPIO_AFRH_AFSEL8_Msk; GPIOA->AFR[1] |= 1<<GPIO_AFRH_AFSEL8_Pos; - /* END DEBUG */ - int cnt = 0; - while (23) { - if (cnt++ == 100000) { - cnt = 0; - GPIOA->ODR ^= 1<<6; - } + GPIOA->MODER |= (1<<GPIO_MODER_MODER9_Pos) | (1<<GPIO_MODER_MODER10_Pos) | (1<<GPIO_MODER_MODER11_Pos) | + (1<<GPIO_MODER_MODER12_Pos) | (1<<GPIO_MODER_MODER15_Pos); +#endif + while (23) { if (adc_fft_buf_ready_idx != -1) { + GPIOA->BSRR = 1<<9; + adc_fft_buf_ready_idx = !adc_fft_buf_ready_idx; /* DEBUG */ memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2); + GPIOA->BSRR = 1<<9<<16; + GPIOA->BSRR = 1<<11; -#if 0 float out; if (adc_buf_measure_freq(adc_fft_buf[adc_fft_buf_ready_idx], &out)) { measurement_errors++; - debug_last_freq = -1; + debug_last_freq = NAN; } else { debug_last_freq = out; @@ -212,7 +215,7 @@ int main(void) dsss_demod_step(&demod_state, out, freq_sample_ts); */ } -#endif + GPIOA->BSRR = 1<<11<<16; freq_sample_ts++; /* TODO: also increase in case of freq measurement error? */ adc_fft_buf_ready_idx = -1; @@ -222,3 +225,39 @@ int main(void) return 0; } +void NMI_Handler(void) { + asm volatile ("bkpt"); +} + +void HardFault_Handler(void) { + asm volatile ("bkpt"); +} + +void MemManage_Handler(void) { + asm volatile ("bkpt"); +} + +void BusFault_Handler(void) { + asm volatile ("bkpt"); +} + +void UsageFault_Handler(void) { + asm volatile ("bkpt"); +} + +void SVC_Handler(void) { + asm volatile ("bkpt"); +} + +void DebugMon_Handler(void) { + asm volatile ("bkpt"); +} + +void PendSV_Handler(void) { + asm volatile ("bkpt"); +} + +void SysTick_Handler(void) { + asm volatile ("bkpt"); +} + |