Moved clock setup to separate file
This commit is contained in:
parent
d2a95c4353
commit
c76918ae2a
31
src/clock.c
Normal file
31
src/clock.c
Normal 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
6
src/clock.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef CLOCK_H
|
||||||
|
#define CLOCK_H
|
||||||
|
|
||||||
|
void init_clock(void);
|
||||||
|
|
||||||
|
#endif // CLOCK_H
|
29
src/main.c
29
src/main.c
|
@ -14,6 +14,7 @@
|
||||||
#include <fxp.h>
|
#include <fxp.h>
|
||||||
#include <fxp_basic.h>
|
#include <fxp_basic.h>
|
||||||
|
|
||||||
|
#include "clock.h"
|
||||||
#include "led_chplex.h"
|
#include "led_chplex.h"
|
||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "charge_pump.h"
|
#include "charge_pump.h"
|
||||||
|
@ -21,36 +22,10 @@
|
||||||
#include "power_switch.h"
|
#include "power_switch.h"
|
||||||
#include "measurement.h"
|
#include "measurement.h"
|
||||||
|
|
||||||
|
|
||||||
volatile int wait_frame = 1;
|
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 */
|
/* Set up systick to fire freq times per second */
|
||||||
static void init_systick(int freq)
|
static void init_systick(int freq)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue