Replace Zephyr ADC driver with direct LL access
Fixes IRQ conflict with COMP peripheral (#93)
This commit is contained in:
@@ -103,10 +103,6 @@
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&eeprom {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2020 Martin Jäger / Libre Solar
|
||||
*/
|
||||
|
||||
#define DT_ADC_1_BASE_ADDRESS DT_ST_STM32_ADC_50000000_BASE_ADDRESS
|
||||
#define DT_ADC_1_IRQ DT_ST_STM32_ADC_50000000_IRQ_0
|
||||
#define DT_ADC_1_IRQ_PRI DT_ST_STM32_ADC_50000000_IRQ_0_PRIORITY
|
||||
#define DT_ADC_1_NAME DT_ST_STM32_ADC_50000000_LABEL
|
||||
#define DT_ADC_1_CLOCK_BITS DT_ST_STM32_ADC_50000000_CLOCK_BITS_0
|
||||
#define DT_ADC_1_CLOCK_BUS DT_ST_STM32_ADC_50000000_CLOCK_BUS_0
|
||||
|
||||
#define DT_ADC_2_BASE_ADDRESS DT_ST_STM32_ADC_50000100_BASE_ADDRESS
|
||||
#define DT_ADC_2_IRQ DT_ST_STM32_ADC_50000100_IRQ_0
|
||||
#define DT_ADC_2_IRQ_PRI DT_ST_STM32_ADC_50000100_IRQ_0_PRIORITY
|
||||
#define DT_ADC_2_NAME DT_ST_STM32_ADC_50000100_LABEL
|
||||
#define DT_ADC_2_CLOCK_BITS DT_ST_STM32_ADC_50000100_CLOCK_BITS_0
|
||||
#define DT_ADC_2_CLOCK_BUS DT_ST_STM32_ADC_50000100_CLOCK_BUS_0
|
||||
@@ -11,37 +11,6 @@
|
||||
model = "Libre Solar MPPT 2420 HPX";
|
||||
compatible = "st,stm32g431";
|
||||
|
||||
soc {
|
||||
adc1: adc@50000000 {
|
||||
compatible = "st,stm32-adc";
|
||||
reg = <0x50000000 0x400>;
|
||||
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
|
||||
interrupts = <18 0>;
|
||||
status = "disabled";
|
||||
label = "ADC_1";
|
||||
#io-channel-cells = <1>;
|
||||
};
|
||||
|
||||
adc2: adc@50000100 {
|
||||
compatible = "st,stm32-adc";
|
||||
reg = <0x50000100 0x400>;
|
||||
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
|
||||
interrupts = <18 0>;
|
||||
status = "disabled";
|
||||
label = "ADC_2";
|
||||
#io-channel-cells = <1>;
|
||||
};
|
||||
|
||||
dac1: dac@50000800 {
|
||||
compatible = "st,stm32-dac";
|
||||
reg = <0x50000800 0x400>;
|
||||
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00010000>;
|
||||
status = "disabled";
|
||||
label = "DAC_1";
|
||||
#io-channel-cells = <1>;
|
||||
};
|
||||
};
|
||||
|
||||
pcb {
|
||||
compatible = "charge-controller";
|
||||
|
||||
@@ -157,14 +126,6 @@
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&adc2 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
/* for charge pump and PWM solar input */
|
||||
&timers3 {
|
||||
status = "okay";
|
||||
|
||||
@@ -114,10 +114,6 @@
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&can1 {
|
||||
bus-speed = <250000>;
|
||||
status = "okay";
|
||||
|
||||
@@ -105,10 +105,6 @@
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&eeprom {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
+20
-32
@@ -12,7 +12,6 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <drivers/adc.h>
|
||||
#include <drivers/gpio.h>
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
@@ -29,6 +28,7 @@
|
||||
#include <stm32f0xx_ll_bus.h>
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
#include <stm32g4xx_ll_system.h>
|
||||
#include <stm32g4xx_ll_adc.h>
|
||||
#include <stm32g4xx_ll_dac.h>
|
||||
#include <stm32g4xx_ll_dma.h>
|
||||
#include <stm32g4xx_ll_bus.h>
|
||||
@@ -119,57 +119,45 @@ static void dac_setup()
|
||||
|
||||
static void adc_init(ADC_TypeDef *adc)
|
||||
{
|
||||
#if !defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
struct device *dev_adc = device_get_binding(DT_ADC_1_NAME);
|
||||
if (dev_adc == 0) {
|
||||
printf("ADC device not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct adc_channel_cfg channel_cfg = {
|
||||
.gain = ADC_GAIN_1,
|
||||
.reference = ADC_REF_INTERNAL,
|
||||
LL_ADC_Disable(adc);
|
||||
#if defined(CONFIG_SOC_SERIES_STM32F0X)
|
||||
.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 240),
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1);
|
||||
LL_ADC_SetClock(adc, LL_ADC_CLOCK_SYNC_PCLK_DIV4);
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 161),
|
||||
#endif
|
||||
.channel_id = LL_ADC_CHANNEL_0,
|
||||
.differential = 0
|
||||
};
|
||||
|
||||
int ret = adc_channel_setup(dev_adc, &channel_cfg);
|
||||
if (ret) {
|
||||
printk("ADC channel setup error.. \n");
|
||||
}
|
||||
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
||||
LL_ADC_EnableInternalRegulator(adc);
|
||||
k_busy_wait(LL_ADC_DELAY_INTERNAL_REGUL_STAB_US);
|
||||
LL_ADC_SetCommonClock(__LL_ADC_COMMON_INSTANCE(adc), LL_ADC_CLOCK_SYNC_PCLK_DIV4);
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12);
|
||||
|
||||
// Prepare for ADC calibration
|
||||
LL_ADC_Disable(adc);
|
||||
LL_ADC_DisableDeepPowerDown(adc);
|
||||
LL_ADC_EnableInternalRegulator(adc);
|
||||
k_busy_wait(LL_ADC_DELAY_INTERNAL_REGUL_STAB_US);
|
||||
|
||||
LL_ADC_SetCommonClock(__LL_ADC_COMMON_INSTANCE(adc), LL_ADC_CLOCK_SYNC_PCLK_DIV4);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
LL_ADC_StartCalibration(adc, LL_ADC_SINGLE_ENDED);
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
LL_ADC_StartCalibration(adc);
|
||||
#endif
|
||||
while (LL_ADC_IsCalibrationOnGoing(adc)) {;}
|
||||
|
||||
if (LL_ADC_IsActiveFlag_ADRDY(adc)) {
|
||||
LL_ADC_ClearFlag_ADRDY(adc);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Now Initialize the ADCs
|
||||
// enable internal reference voltage and temperature
|
||||
// Enable internal reference voltage and temperature
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc),
|
||||
LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
#if defined(CONFIG_SOC_SERIES_STM32F0X)
|
||||
LL_ADC_REG_SetSequencerChannels(adc, ADC_CHSEL);
|
||||
|
||||
LL_ADC_SetSamplingTimeCommonChannels(adc, LL_ADC_SAMPLINGTIME_239CYCLES_5);
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
LL_ADC_REG_SetSequencerChannels(adc, ADC_CHSEL);
|
||||
LL_ADC_SetSamplingTimeCommonChannels(adc, LL_ADC_SAMPLINGTIME_160CYCLES_5);
|
||||
#else // Others including CONFIG_SOC_SERIES_STM32G4X
|
||||
const uint32_t *adc_seq = (adc == ADC1) ? adc_1_sequence : adc_2_sequence;
|
||||
int num_ch = (adc == ADC1) ? NUM_ADC_1_CH : NUM_ADC_2_CH;
|
||||
@@ -191,8 +179,8 @@ static void adc_init(ADC_TypeDef *adc)
|
||||
LL_ADC_REG_SetTriggerEdge(adc, LL_ADC_REG_TRIG_EXT_RISING);
|
||||
LL_ADC_REG_SetTriggerSource(adc, LL_ADC_REG_TRIG_EXT_TIM1_TRGO2);
|
||||
}
|
||||
LL_ADC_Enable(adc);
|
||||
#endif
|
||||
LL_ADC_Enable(adc);
|
||||
}
|
||||
|
||||
static void adc_setup()
|
||||
|
||||
@@ -9,8 +9,6 @@ CONFIG_SERIAL=y
|
||||
CONFIG_UART_1=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_1=y
|
||||
CONFIG_ADC=y
|
||||
CONFIG_ADC_1=y
|
||||
|
||||
# disable log by default to save memory for STM32F0 with little RAM
|
||||
CONFIG_LOG=y
|
||||
|
||||
Reference in New Issue
Block a user