LNSC-2420-Firmware/src/clock.c

32 lines
791 B
C
Raw Normal View History

2021-06-11 23:55:10 +02:00
#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);
}