diff --git a/src/clock.c b/src/clock.c new file mode 100644 index 0000000..59eac28 --- /dev/null +++ b/src/clock.c @@ -0,0 +1,31 @@ +#include + +#include "clock.h" + +void init_clock(void) +{ + /* Set STM32 to 48 MHz. */ + rcc_clock_setup_in_hse_8mhz_out_48mhz(); // generate 48 MHz from external 8 MHz crystal + //rcc_clock_setup_in_hsi_out_48mhz(); // generate ~48 MHz from internal RC oscillator + + // enable TIM1 for PWM generation + rcc_periph_clock_enable(RCC_TIM1); + + // enable GPIO clocks: + // Port A is needed for the charge pump, extension port and analog input + rcc_periph_clock_enable(RCC_GPIOA); + + // Port B is needed for the LEDs + rcc_periph_clock_enable(RCC_GPIOB); + + // USART1 is used for RS485 + rcc_periph_clock_enable(RCC_USART1); + + // ADC1 for analog measuremnts + rcc_periph_clock_enable(RCC_ADC1); + + // DMA1 is used for ADC data transfer + rcc_periph_clock_enable(RCC_DMA1); +} + + diff --git a/src/clock.h b/src/clock.h new file mode 100644 index 0000000..5229ddd --- /dev/null +++ b/src/clock.h @@ -0,0 +1,6 @@ +#ifndef CLOCK_H +#define CLOCK_H + +void init_clock(void); + +#endif // CLOCK_H diff --git a/src/main.c b/src/main.c index 6a22cb7..6b42a42 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,7 @@ #include #include +#include "clock.h" #include "led_chplex.h" #include "rs485.h" #include "charge_pump.h" @@ -21,36 +22,10 @@ #include "power_switch.h" #include "measurement.h" + volatile int wait_frame = 1; -static void init_clock(void) -{ - /* Set STM32 to 48 MHz. */ - rcc_clock_setup_in_hse_8mhz_out_48mhz(); // generate 48 MHz from external 8 MHz crystal - //rcc_clock_setup_in_hsi_out_48mhz(); // generate ~48 MHz from internal RC oscillator - - // enable TIM1 for PWM generation - rcc_periph_clock_enable(RCC_TIM1); - - // enable GPIO clocks: - // Port A is needed for the charge pump, extension port and analog input - rcc_periph_clock_enable(RCC_GPIOA); - - // Port B is needed for the LEDs - rcc_periph_clock_enable(RCC_GPIOB); - - // USART1 is used for RS485 - rcc_periph_clock_enable(RCC_USART1); - - // ADC1 for analog measuremnts - rcc_periph_clock_enable(RCC_ADC1); - - // DMA1 is used for ADC data transfer - rcc_periph_clock_enable(RCC_DMA1); -} - - /* Set up systick to fire freq times per second */ static void init_systick(int freq) {