Use STM32 LL API to enable clocks (e.g. for CRC)
Reason: We need to wait until the clock enable register is actually set before we can consider the clock running. This caused an issue with the CRC peripheral, which sometimes did not work correctly (always returned 0) right after startup. This commit switches to LL API, which includes a delay. Updating all occurences of direct clock enabling via registers and not only the CRC peripheral.
This commit is contained in:
+3
-10
@@ -20,6 +20,7 @@
|
||||
#include <device.h>
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(nvs, CONFIG_DATA_STORAGE_LOG_LEVEL);
|
||||
#include <stm32_ll_bus.h>
|
||||
|
||||
K_MUTEX_DEFINE(data_buf_lock);
|
||||
|
||||
@@ -30,11 +31,7 @@ extern ThingSet ts;
|
||||
|
||||
uint32_t _calc_crc(const uint8_t *buf, size_t len)
|
||||
{
|
||||
#if defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN;
|
||||
#else
|
||||
RCC->AHBENR |= RCC_AHBENR_CRCEN;
|
||||
#endif
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_CRC);
|
||||
|
||||
// we keep standard polynomial 0x04C11DB7 (same for STM32L0 and STM32F0)
|
||||
// and we don't care for endianness here
|
||||
@@ -51,11 +48,7 @@ uint32_t _calc_crc(const uint8_t *buf, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
RCC->AHB1ENR &= ~(RCC_AHB1ENR_CRCEN);
|
||||
#else
|
||||
RCC->AHBENR &= ~(RCC_AHBENR_CRCEN);
|
||||
#endif
|
||||
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
|
||||
|
||||
return CRC->DR;
|
||||
}
|
||||
|
||||
+8
-6
@@ -16,6 +16,7 @@
|
||||
#ifndef UNIT_TEST
|
||||
#include <soc.h>
|
||||
#include <pinmux/stm32/pinmux_stm32.h>
|
||||
#include <stm32_ll_bus.h>
|
||||
#endif
|
||||
|
||||
#if BOARD_HAS_DCDC
|
||||
@@ -53,8 +54,7 @@ static void tim_init_registers(int freq_kHz)
|
||||
{
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), TIMER_ADDR);
|
||||
|
||||
// Enable TIM3 clock
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
|
||||
// No prescaler --> timer frequency == SystemClock
|
||||
TIM3->PSC = 0;
|
||||
@@ -130,8 +130,11 @@ static void tim_init_registers(int freq_kHz)
|
||||
{
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), TIMER_ADDR);
|
||||
|
||||
// Enable TIM1 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
#ifdef LL_APB2_GRP1_PERIPH_TIM1
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
#else
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1);
|
||||
#endif
|
||||
|
||||
// No prescaler --> timer frequency == SystemClock
|
||||
TIM1->PSC = 0;
|
||||
@@ -233,8 +236,7 @@ static void tim_init_registers(int freq_kHz)
|
||||
{
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), TIMER_ADDR);
|
||||
|
||||
// Enable HRTIM1 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_HRTIM1EN;
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_HRTIM1);
|
||||
|
||||
// Enable periodic calibration of delay-locked loop (DLL) with lowest calibration period
|
||||
HRTIM1->sCommonRegs.DLLCR |= HRTIM_DLLCR_CALEN | HRTIM_DLLCR_CALRTE_0 | HRTIM_DLLCR_CALRTE_1;
|
||||
|
||||
+8
-9
@@ -19,6 +19,7 @@
|
||||
#include "mcu.h"
|
||||
|
||||
#include <stm32_ll_system.h>
|
||||
#include <stm32_ll_bus.h>
|
||||
|
||||
#if BOARD_HAS_LOAD_OUTPUT
|
||||
#define LOAD_GPIO DT_CHILD(DT_PATH(outputs), load)
|
||||
@@ -35,11 +36,9 @@ static const struct device *dev_usb;
|
||||
|
||||
static void lptim_init()
|
||||
{
|
||||
// Enable peripheral clock of GPIOB
|
||||
RCC->IOPENR |= RCC_IOPENR_IOPBEN;
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPTIM1);
|
||||
|
||||
// Enable LPTIM clock
|
||||
RCC->APB1ENR |= RCC_APB1ENR_LPTIM1EN;
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
// Select alternate function mode on PB2 (first bit _1 = 1, second bit _0 = 0)
|
||||
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODE2)) | GPIO_MODER_MODE2_1;
|
||||
@@ -96,12 +95,12 @@ void ADC1_COMP_IRQHandler(void *args)
|
||||
|
||||
void short_circuit_comp_init()
|
||||
{
|
||||
// set GPIO pin to analog
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
|
||||
GPIOB->MODER &= ~(GPIO_MODER_MODE4);
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
|
||||
// enable SYSCFG clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
// set GPIO pin to analog
|
||||
GPIOB->MODER &= ~(GPIO_MODER_MODE4);
|
||||
|
||||
// enable VREFINT buffer
|
||||
SYSCFG->CFGR3 |= SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP;
|
||||
|
||||
Reference in New Issue
Block a user