STM32 improved ADCv4 driver (H7) with variable sizes samples support.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14431 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-05-25 09:21:31 +00:00
parent 490802b3b4
commit 1e7edf58ea
12 changed files with 53 additions and 27 deletions

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -31,34 +31,37 @@
/*===========================================================================*/
#if STM32_ADC_DUAL_MODE == TRUE
#define ADC12_CCR_DUAL 0b00110 // TODO use definitions
#if STM32_ADC_COMPACT_SAMPLES == TRUE
#define ADC12_CCR_DUAL ADC_CCR_DUAL_REG_SIMULT
#if STM32_ADC_SAMPLES_SIZE == 8
/* Compact type dual mode, 2x8-bit.*/
#define ADC12_DMA_SIZE (STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_PSIZE_HWORD)
#define ADC3_BDMA_SIZE (STM32_BDMA_CR_MSIZE_BYTE | STM32_BDMA_CR_PSIZE_BYTE)
#define ADC_DMA_DAMDF ADC_CCR_DAMDF_BYTE
#else /* STM32_ADC_COMPACT_SAMPLES == FALSE */
#else /* STM32_ADC_SAMPLES_SIZE == 16 */
/* Large type dual mode, 2x16bit.*/
#define ADC12_DMA_SIZE (STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_PSIZE_WORD)
#define ADC3_BDMA_SIZE (STM32_BDMA_CR_MSIZE_HWORD | STM32_BDMA_CR_PSIZE_HWORD)
#define ADC_DMA_DAMDF ADC_CCR_DAMDF_HWORD
#endif /* !STM32_ADC_COMPACT_SAMPLES */
#endif /* STM32_ADC_SAMPLES_SIZE == 8 */
#else /* STM32_ADC_DUAL_MODE == FALSE */
#define ADC12_CCR_DUAL 0b00000 // TODO use definitions
#if STM32_ADC_COMPACT_SAMPLES
#define ADC12_CCR_DUAL ADC_CCR_DUAL_INDEPENDENT
#if STM32_ADC_SAMPLES_SIZE == 8
/* Compact type single mode, 8-bit.*/
#define ADC12_DMA_SIZE (STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_PSIZE_BYTE)
#define ADC3_BDMA_SIZE (STM32_BDMA_CR_MSIZE_BYTE | STM32_BDMA_CR_PSIZE_BYTE)
#define ADC_DMA_DAMDF ADC_CCR_DAMDF_DISABLED
#else /* STM32_ADC_COMPACT_SAMPLES == FALSE */
#elif STM32_ADC_SAMPLES_SIZE == 32
#define ADC12_DMA_SIZE (STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_PSIZE_WORD)
#define ADC3_BDMA_SIZE (STM32_BDMA_CR_MSIZE_WORD | STM32_BDMA_CR_PSIZE_WORD)
#define ADC_DMA_DAMDF ADC_CCR_DAMDF_DISABLED
#else /* STM32_ADC_SAMPLES_SIZE == 16 */
/* Large type single mode, 16-bit.*/
#define ADC12_DMA_SIZE (STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_PSIZE_HWORD)
#define ADC3_BDMA_SIZE (STM32_BDMA_CR_MSIZE_HWORD | STM32_BDMA_CR_PSIZE_HWORD)
#define ADC_DMA_DAMDF ADC_CCR_DAMDF_DISABLED
#endif /* STM32_ADC_COMPACT_SAMPLES == FALSE */
#endif /* STM32_ADC_SAMPLES_SIZE == 8 */
#endif /* STM32_ADC_DUAL_MODE == FALSE */
/*===========================================================================*/

View File

@ -197,12 +197,14 @@
#endif
/**
* @brief Makes the ADC samples type an 8bits one.
* @note 10, 12, 14 and 16 bits sampling mode must not be used when this
* option is enabled.
* @brief Specifies the ADC samples width.
* @note Must be 8, 16 or 32.
* @note 10, 12, 14 and 16 bits sampling modes must not be used when
* this option is set to 8.
* @note 32 is useful when oversampling is activated.
*/
#if !defined(STM32_ADC_COMPACT_SAMPLES) || defined(__DOXYGEN__)
#define STM32_ADC_COMPACT_SAMPLES FALSE
#if !defined(STM32_ADC_SAMPLES_SIZE) || defined(__DOXYGEN__)
#define STM32_ADC_SAMPLES_SIZE 16
#endif
/**
@ -372,6 +374,16 @@
#error "Invalid IRQ priority assigned to ADC3"
#endif
#if ((STM32_ADC_SAMPLES_SIZE != 8) && \
(STM32_ADC_SAMPLES_SIZE != 16) && \
(STM32_ADC_SAMPLES_SIZE != 32))
#error "STM32_ADC_SAMPLES_SIZE must be 8, 16 or 32"
#endif
#if (STM32_ADC_SAMPLES_SIZE != 32) && STM32_ADC_DUAL_MODE
#error "STM32_ADC_SAMPLES_SIZE = 32 not compatible with STM32_ADC_DUAL_MODE"
#endif
#if !defined(STM32_ENFORCE_H7_REV_XY)
/* ADC clock source checks.*/
#if (STM32_D1HPRE == STM32_D1HPRE_DIV1)
@ -505,10 +517,12 @@
/**
* @brief ADC sample data type.
*/
#if !STM32_ADC_COMPACT_SAMPLES || defined(__DOXYGEN__)
#if (STM32_ADC_SAMPLES_SIZE == 16) || defined(__DOXYGEN__)
typedef uint16_t adcsample_t;
#else
#elif (STM32_ADC_SAMPLES_SIZE == 8)
typedef uint8_t adcsample_t;
#elif (STM32_ADC_SAMPLES_SIZE == 32)
typedef uint32_t adcsample_t;
#endif
/**
@ -716,6 +730,15 @@ typedef union {
#define ADC_AWD23_MASK(n) (1U << (n)) /**< @brief AWD2/3 channels mask*/
/** @} */
/**
* @name Oversampling settings helper macros
* @{
*/
#define ADC_CFGR2_OVSS_N(n) ((n) << 5U)/**< @brief ovsr right shift */
#define ADC_CFGR2_OVSR_N(n) ((n) << 16U)/**< @brief oversampling ratio */
#define ADC_CFGR2_LSHIFT_N(n) ((n) << 28U)/**< @brief ovsr left shift */
/** @} */
/*===========================================================================*/
/* External declarations. */

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 TRUE
#define STM32_ADC_USE_ADC3 TRUE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 TRUE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 FALSE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -224,7 +224,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE FALSE
#define STM32_ADC_COMPACT_SAMPLES FALSE
#define STM32_ADC_SAMPLES_SIZE 16
#define STM32_ADC_USE_ADC12 TRUE
#define STM32_ADC_USE_ADC3 FALSE
#define STM32_ADC_ADC12_DMA_STREAM STM32_DMA_STREAM_ID_ANY

View File

@ -235,7 +235,7 @@
* ADC driver system settings.
*/
#define STM32_ADC_DUAL_MODE ${doc.STM32_ADC_DUAL_MODE!"FALSE"}
#define STM32_ADC_COMPACT_SAMPLES ${doc.STM32_ADC_COMPACT_SAMPLES!"FALSE"}
#define STM32_ADC_SAMPLES_SIZE ${doc.STM32_ADC_SAMPLES_SIZE!"16"}
#define STM32_ADC_USE_ADC12 ${doc.STM32_ADC_USE_ADC12!"TRUE"}
#define STM32_ADC_USE_ADC3 ${doc.STM32_ADC_USE_ADC3!"FALSE"}
#define STM32_ADC_ADC12_DMA_STREAM ${doc.STM32_ADC_ADC12_DMA_STREAM!"STM32_DMA_STREAM_ID_ANY"}