I am trying to use the SDADC and the DAC (both with 2 channels) with DMA on my custom STM32F373 board using ChibiOS 20.3.2.
In ChibiOS 20.3.2, both SDADC and DAC are configured to use the same DMA channels:
From ChibiOS-20.3.2/os/hal/ports/STM32/STM32F37x/stm32_registry.h
Code: Select all
/* DAC attributes.*/
#define STM32_HAS_DAC1_CH1 TRUE
#define STM32_DAC_DAC1_CH1_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
#define STM32_HAS_DAC1_CH2 TRUE
#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
#define STM32_HAS_DAC2_CH1 TRUE
#define STM32_DAC_DAC2_CH1_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
and from ChibiOS-20.3.2/os/hal/ports/STM32/STM32F37x/hal_adc_lld.c in void adc_lld_start(ADCDriver *adcp):
Code: Select all
#if STM32_ADC_USE_SDADC1
if (&SDADCD1 == adcp) {
adcp->dmastp = dmaStreamAllocI(STM32_DMA_STREAM_ID(2, 3),
STM32_ADC_SDADC1_DMA_IRQ_PRIORITY,
(stm32_dmaisr_t)adc_lld_serve_dma_interrupt,
(void *)adcp);
osalDbgAssert(adcp->dmastp != NULL, "unable to allocate stream");
dmaStreamSetPeripheral(adcp->dmastp, &SDADC1->JDATAR);
rccEnableSDADC1(true);
PWR->CR |= PWR_CR_SDADC1EN;
adcp->sdadc->CR2 = 0;
adcp->sdadc->CR1 = (adcp->config->cr1 | SDADC_ENFORCED_CR1_FLAGS) &
~SDADC_FORBIDDEN_CR1_FLAGS;
adcp->sdadc->CR2 = SDADC_CR2_ADON;
}
#endif /* STM32_ADC_USE_SDADC1 */
#if STM32_ADC_USE_SDADC2
if (&SDADCD2 == adcp) {
adcp->dmastp = dmaStreamAllocI(STM32_DMA_STREAM_ID(2, 4),
According to the reference manual, I should be able to change the ADC DMA from (2,3), (2,4) and (2,5) and (1,3), (1,4) and (1,5), but if I change the defines in stm32_registry.h to
Code: Select all
#define STM32_DAC_DAC1_CH1_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_DAC_DAC2_CH1_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
the DMA doesn't work anymore (dac_lld_serve_tx_interrupt doesn't get called...). I found the following comment in ChibiOS-20.3.2/os/hal/ports/STM32/LLD/DMAv1/notes.txt
Code: Select all
- For devices without CSELR register it is possible to select channels but
the SYSCFG CFGR register is not configured, the user has to configure it
before starting the DMA driver.
but I couldn't figure out what I have to add. Any hints what I can try to get this working?
BTW: Is there an easy way to figure out which version of a peripheral driver a certain chip is using? I mean how can one know if a STM32F4xx is using ADCv3 or ADCv4 or does a STM32F373 use DMAv1 or DMAv2? I think I figured it out for the STM32F373 that I am using, but it was somewhat difficult and I am wondering if there is a easy / recommended way to do this?