diff options
-rw-r--r-- | os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c | 20 | ||||
-rw-r--r-- | os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h | 27 | ||||
-rw-r--r-- | readme.txt | 1 | ||||
-rw-r--r-- | testhal/STM32/STM32F4xx/ADC/main.c | 4 | ||||
-rw-r--r-- | testhal/STM32/STM32F7xx/GPT-ADC/main.c | 2 |
5 files changed, 50 insertions, 4 deletions
diff --git a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c index b69fb3172..ab3fbf462 100644 --- a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c +++ b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c @@ -124,7 +124,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) { if (ADCD1.grpp != NULL)
_adc_isr_error_code(&ADCD1, ADC_ERR_OVERFLOW);
}
- /* TODO: Add here analog watchdog handling.*/
+ if (sr & ADC_SR_AWD) {
+ if (ADCD1.grpp != NULL) {
+ _adc_isr_error_code(&ADCD1, ADC_ERR_WATCHDOG);
+ }
+ }
#if defined(STM32_ADC_ADC1_IRQ_HOOK)
STM32_ADC_ADC1_IRQ_HOOK
#endif
@@ -141,7 +145,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) { if (ADCD2.grpp != NULL)
_adc_isr_error_code(&ADCD2, ADC_ERR_OVERFLOW);
}
- /* TODO: Add here analog watchdog handling.*/
+ if (sr & ADC_SR_AWD) {
+ if (ADCD2.grpp != NULL) {
+ _adc_isr_error_code(&ADCD2, ADC_ERR_WATCHDOG);
+ }
+ }
#if defined(STM32_ADC_ADC2_IRQ_HOOK)
STM32_ADC_ADC2_IRQ_HOOK
#endif
@@ -158,7 +166,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) { if (ADCD3.grpp != NULL)
_adc_isr_error_code(&ADCD3, ADC_ERR_OVERFLOW);
}
- /* TODO: Add here analog watchdog handling.*/
+ if (sr & ADC_SR_AWD) {
+ if (ADCD3.grpp != NULL) {
+ _adc_isr_error_code(&ADCD3, ADC_ERR_WATCHDOG);
+ }
+ }
#if defined(STM32_ADC_ADC3_IRQ_HOOK)
STM32_ADC_ADC3_IRQ_HOOK
#endif
@@ -350,6 +362,8 @@ void adc_lld_start_conversion(ADCDriver *adcp) { adcp->adc->SR = 0;
adcp->adc->SMPR1 = grpp->smpr1;
adcp->adc->SMPR2 = grpp->smpr2;
+ adcp->adc->HTR = grpp->htr;
+ adcp->adc->LTR = grpp->ltr;
adcp->adc->SQR1 = grpp->sqr1 | ADC_SQR1_NUM_CH(grpp->num_channels);
adcp->adc->SQR2 = grpp->sqr2;
adcp->adc->SQR3 = grpp->sqr3;
diff --git a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h index ecdd5ba0e..3fe808a8e 100644 --- a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h +++ b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h @@ -313,7 +313,8 @@ typedef uint16_t adc_channels_num_t; */
typedef enum {
ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */
- ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */
+ ADC_ERR_OVERFLOW = 1, /**< ADC overflow condition. */
+ ADC_ERR_WATCHDOG = 2 /**< ADC watchdog condition. */
} adcerror_t;
/**
@@ -392,6 +393,16 @@ typedef struct { */
uint32_t smpr2;
/**
+ * @brief ADC watchdog high threshold register.
+ * @details This field defines the high threshold of the analog watchdog.
+ */
+ uint16_t htr;
+ /**
+ * @brief ADC watchdog low threshold register.
+ * @details This field defines the low threshold of the analog watchdog.
+ */
+ uint16_t ltr;
+ /**
* @brief ADC SQR1 register initialization data.
* @details Conversion group sequence 13...16 + sequence length.
*/
@@ -531,6 +542,20 @@ struct ADCDriver { #define ADC_SMPR1_SMP_VBAT(n) ((n) << 24) /**< @brief VBAT sampling time. */
/** @} */
+/**
+ * @name Threshold settings helper macros
+ * @{
+ */
+/**
+ * @brief High threshold limitation.
+ */
+#define ADC_HTR(n) ((n > ADC_HTR_HT) ? ADC_HTR_HT : n)
+/**
+ * @brief Low threshold limitation.
+ */
+#define ADC_LTR(n) ((n > ADC_LTR_LT) ? ADC_LTR_LT : n)
+/** @} */
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
diff --git a/readme.txt b/readme.txt index 78f05549e..f39a1e970 100644 --- a/readme.txt +++ b/readme.txt @@ -91,6 +91,7 @@ *****************************************************************************
*** Next ***
+- NEW: Added analog watchdog functionality to STM32 ADCv2 driver.
- NEW: Added a termination check to the shell.
- NEW: Updated CMSIS to version 5.3.0.
- NEW: Now chconf.h files have preprocessor checks around each definition,
diff --git a/testhal/STM32/STM32F4xx/ADC/main.c b/testhal/STM32/STM32F4xx/ADC/main.c index 23608af6e..8477a0ab1 100644 --- a/testhal/STM32/STM32F4xx/ADC/main.c +++ b/testhal/STM32/STM32F4xx/ADC/main.c @@ -61,6 +61,8 @@ static const ADCConversionGroup adcgrpcfg1 = { ADC_CR2_SWSTART, /* CR2 */
ADC_SMPR1_SMP_AN11(ADC_SAMPLE_3),
0, /* SMPR2 */
+ 0, /* HTR */
+ 0, /* LTR */
0, /* SQR1 */
0, /* SQR2 */
ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
@@ -81,6 +83,8 @@ static const ADCConversionGroup adcgrpcfg2 = { ADC_SMPR1_SMP_AN12(ADC_SAMPLE_56) | ADC_SMPR1_SMP_AN11(ADC_SAMPLE_56) |
ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144) | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_144),
0, /* SMPR2 */
+ 0, /* HTR */
+ 0, /* LTR */
0, /* SQR1 */
ADC_SQR2_SQ8_N(ADC_CHANNEL_SENSOR) | ADC_SQR2_SQ7_N(ADC_CHANNEL_VREFINT),
ADC_SQR3_SQ6_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ5_N(ADC_CHANNEL_IN11) |
diff --git a/testhal/STM32/STM32F7xx/GPT-ADC/main.c b/testhal/STM32/STM32F7xx/GPT-ADC/main.c index 031b32f06..92a7da91c 100644 --- a/testhal/STM32/STM32F7xx/GPT-ADC/main.c +++ b/testhal/STM32/STM32F7xx/GPT-ADC/main.c @@ -103,6 +103,8 @@ static const ADCConversionGroup adcgrpcfg1 = { ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144) |
ADC_SMPR1_SMP_VREF(ADC_SAMPLE_144), /* SMPR1 */
0, /* SMPR2 */
+ 0, /* HTR */
+ 0, /* LTR */
0, /* SQR1 */
0, /* SQR2 */
ADC_SQR3_SQ2_N(ADC_CHANNEL_SENSOR) |
|