Hi,
I'm trying to read out an external 14 Bit ADC which is connected to 14 GPIO pins, of different ports. Can anyone tell me how to read in e.g. 100 samples? It's the first time I'm dealing with DMA and I'm a little bit confused by the DMA examples I have found so far and the usage of the corresponding functions.
I'm using ChibiOS version 16.1.2 and a STM32F429 customized board.
THX
External ADC & DMA
Moderator: RoccoMarco
Re: External ADC & DMA
First you need to check which DMA has access to GPIO, then you have to configure it: channel/stream, source (gpio register), destination (memory), trigger (can be software or a timer), data width (16bit).
This is pretty much what you need, except the direction has to be reversed: viewtopic.php?t=2419
In details:
http://www.st.com/content/ccc/resource/ ... 169730.pdf
This is pretty much what you need, except the direction has to be reversed: viewtopic.php?t=2419
In details:
http://www.st.com/content/ccc/resource/ ... 169730.pdf
Last edited by mobyfab on Fri Jan 20, 2017 11:47 am, edited 2 times in total.
Re: External ADC & DMA
Something like that (untested)
Code: Select all
#define STM32_TIM_CR2_CCDS (1U << 3)
static GPTConfig gptcfg =
{
200000, /* timer clock.*/
NULL /* Timer callback.*/
};
int main(void) {
uint16_t buffer[] = {0x000C,0x000C,0x000C};
halInit();
chSysInit();
gptStart(&GPTD2, &gptcfg);
GPTD2.tim->CR2 |= STM32_TIM_CR2_CCDS;
gptStartContinuous(&GPTD2, 25); // dT = 200,000 / 25 = 8,000Hz
// Allocate the stream
if (dmaStreamAllocate( STM32_DMA2_STREAM5, 0, NULL, NULL ))
chSysHalt();
// Set the source Address
dmaStreamSetPeripheral( STM32_DMA2_STREAM5, GPIOF->IDR );
// Set the destination address
dmaStreamSetMemory0( STM32_DMA2_STREAM5, buffer );
// set the size of the output buffer
dmaStreamSetTransactionSize( STM32_DMA2_STREAM5, sizeof(buffer)*sizeof(buffer[0]) );
// config 16-bit HWORD transfers, peripheral to memory,
// fixed source address, inc dest address
dmaStreamSetMode( STM32_DMA2_STREAM5,
STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD |
STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_P2M |
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC |
STM32_DMA_CR_CHSEL(6));
dmaStreamSetFIFO(STM32_DMA2_STREAM5, 0);
dmaStreamEnable(STM32_DMA2_STREAM5);
while (TRUE) {
chThdSleepMilliseconds(500);
}
}
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: External ADC & DMA
hi,
Having pins on different ports probably make DMA use not possible. You don't have a single "source" location.
Giovanni
Having pins on different ports probably make DMA use not possible. You don't have a single "source" location.
Giovanni
Re: External ADC & DMA
Indeed, I missed that.
You need to have them on a single port, or you need more DMA channels (one per port), and some logic to get the proper result. (which defies the use of DMA...)
You need to have them on a single port, or you need more DMA channels (one per port), and some logic to get the proper result. (which defies the use of DMA...)
Re: External ADC & DMA
Hi,
thank you for the replies.
@ HDKLog: a parallel to serial converter isn't an option. The ADC has a sample frequency of 30 MHz
.
I'm still confused. Especially how to configure the DMA. As mobyfab has mentioned, I have to check which DMA has access to GPIO. I need access to PORT B and E. But I can't find any listing. I have searched in the reference manual and the datasheet. But I can't find anything which DMA is responible for which PORT. Further the ADC has a data output clock which is connected to GPIOB 5, how can I make use of this clock?
Sorry for my, maybe stupid questions, but I'm really confused by code examples in the web.
thank you for the replies.
@ HDKLog: a parallel to serial converter isn't an option. The ADC has a sample frequency of 30 MHz
I'm still confused. Especially how to configure the DMA. As mobyfab has mentioned, I have to check which DMA has access to GPIO. I need access to PORT B and E. But I can't find any listing. I have searched in the reference manual and the datasheet. But I can't find anything which DMA is responible for which PORT. Further the ADC has a data output clock which is connected to GPIOB 5, how can I make use of this clock?
Sorry for my, maybe stupid questions, but I'm really confused by code examples in the web.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: External ADC & DMA
See "2.1 System Architecture" in the RM, there is the diagram with bus masters and slaves.
Giovanni
Giovanni
Re: External ADC & DMA
Hi Giovanni,
thanks for your reply. By having a look at figure 2 (page 62 in the RM) i can see just DMA2 has accsess to the peripherals (GPIO).
Looking at table 43 (page 310 in the RM) there are just TIM1 and TIM8 available for a DMA2 request.
Thus I have to connect my external trigger signal (provided from the ADC) to a PIN which has accsess to TIM1 or TIM8. Because PB15 has just access to TIM12, which can not be used for a DMA2 request (and TIM1_CH1N and TIM8_CH3Nare denote complementary outputs).
Is that correct, or have I still missed something?
BR
thanks for your reply. By having a look at figure 2 (page 62 in the RM) i can see just DMA2 has accsess to the peripherals (GPIO).
Looking at table 43 (page 310 in the RM) there are just TIM1 and TIM8 available for a DMA2 request.
Thus I have to connect my external trigger signal (provided from the ADC) to a PIN which has accsess to TIM1 or TIM8. Because PB15 has just access to TIM12, which can not be used for a DMA2 request (and TIM1_CH1N and TIM8_CH3Nare denote complementary outputs).
Is that correct, or have I still missed something?
BR