Moved clock setup to separate file

This commit is contained in:
Thomas Kolb 2021-06-11 23:55:10 +02:00
parent d2a95c4353
commit c76918ae2a
3 changed files with 39 additions and 27 deletions

31
src/clock.c Normal file
View File

@ -0,0 +1,31 @@
#include <libopencm3/stm32/rcc.h>
#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);
}

6
src/clock.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CLOCK_H
#define CLOCK_H
void init_clock(void);
#endif // CLOCK_H

View File

@ -14,6 +14,7 @@
#include <fxp.h>
#include <fxp_basic.h>
#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)
{