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:
Martin Jäger
2021-03-16 17:51:15 +01:00
parent 5e02ab2292
commit 3b68bc1bcc
3 changed files with 19 additions and 25 deletions
+3 -10
View File
@@ -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;
}