Set DFM17 clocks correctly to 24 MHz

pull/60/head
Mikael Nousiainen 2023-09-13 22:39:17 +03:00
rodzic b78fb95cbd
commit ec7f6c6969
6 zmienionych plików z 21 dodań i 12 usunięć

Wyświetl plik

@ -8,6 +8,11 @@
// Comment the following error to make the DFM17 development branch compile :)
#error "DFM17 radiosonde support is a work in progress. This code does not work yet!"
#if !defined(RS41) && !defined(DFM17)
#error "No hardware type specified. Please define RS41 or DFM17."
#endif
// Enable semihosting to receive debug logs during development
// See the README for details on how to set up debugging and debug logs with GDB
// NOTE: Semihosting has to be disabled when the RS41 radiosonde is not connected to an STM32 programmer dongle, otherwise the firmware will not run.

Wyświetl plik

@ -19,6 +19,7 @@ void data_timer_init(uint32_t baud_rate)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
// The data timer assumes a 24 MHz clock source
tim_init.TIM_Prescaler = 24 - 1; // tick every 1/1000000 s
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
tim_init.TIM_Period = (uint16_t) ((1000000 / baud_rate) - 1);

Wyświetl plik

@ -18,6 +18,7 @@ void delay_init()
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
// The delay timer assumes a 24 MHz clock source
tim_init.TIM_Prescaler = 24 - 1;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
tim_init.TIM_Period = 0;

Wyświetl plik

@ -52,7 +52,7 @@ void spi_init()
#endif
#ifdef DFM17
// TODO: Adjust SPI speed correctly, not sure what this should be
spi_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
spi_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
#endif
spi_init.SPI_FirstBit = SPI_FirstBit_MSB;
#ifdef RS41

Wyświetl plik

@ -40,7 +40,7 @@ static void rcc_init()
{
RCC_DeInit();
#ifdef RS41
// The RS41 hardware uses an external clock
// The RS41 hardware uses an external clock at 24 MHz
RCC_HSEConfig(RCC_HSE_ON);
ErrorStatus hse_status = RCC_WaitForHSEStartUp();
@ -52,9 +52,11 @@ static void rcc_init()
#ifdef DFM17
// The DFM17 hardware uses the internal clock
RCC_AdjustHSICalibrationValue(0x10U);
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_4);
// Set up a 24 MHz PLL for 24 MHz SYSCLK (8 MHz / 2) * 6 = 24 MHz
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);
RCC_HSICmd(ENABLE);
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
#endif
//SystemInit();
@ -64,15 +66,17 @@ static void rcc_init()
// TODO: Check what the delay timer TIM3 settings really should be and WTF the clock tick really is!?!?!?
RCC_HCLKConfig(RCC_SYSCLK_Div1); // Was: RCC_SYSCLK_Div4
RCC_PCLK2Config(RCC_HCLK_Div1); // Was: 4
RCC_PCLK1Config(RCC_HCLK_Div1); // Was: 2
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
#ifdef RS41
// Use the 24 MHz external clock as SYSCLK
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
while (RCC_GetSYSCLKSource() != 0x04);
#endif
#ifdef DFM17
// Use the 24 MHz PLL as SYSCLK
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != 0x08);

Wyświetl plik

@ -96,11 +96,11 @@ int main(void)
log_info("Pulse counter init\n");
pulse_counter_init(PULSE_COUNTER_PIN_MODE, PULSE_COUNTER_INTERRUPT_EDGE);
} else {
log_info("I2C init: clock speed %d kHz\n", I2C_BUS_CLOCK_SPEED / 1000);
#ifdef RS41
// dfm17 does not use i2c
// Only RS41 uses the I2C bus
log_info("I2C init: clock speed %d kHz\n", I2C_BUS_CLOCK_SPEED / 1000);
i2c_init(I2C_BUS_CLOCK_SPEED);
#endif //RS41
#endif
}
log_info("SPI init\n");
@ -121,9 +121,7 @@ int main(void)
#elif defined(DFM17)
log_info("Si4063 init\n");
si4063_init();
#else
Error. Must defined RS41 or DFM17
#endif
#endif
if (bmp280_enabled) {
for (int i = 0; i < 3; i++) {