ICU driver and DMA ?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

ICU driver and DMA ?

Post by omcdr »

I have STM32F411 board. My input signal is at PA1 pin - TIM2_CH2. I want to run input capture feature and get samples to 128 width array with DMA in circular mode.

Is it possible to use ICU driver with DMA circular mode on STM32F4 platform ?
I have seen PWM-ICU example, but I don't know how to use it with DMA.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU driver and DMA ?

Post by Giovanni »

Hi,

It should be possible by configuring the DIER register in the ICUConfig structure.

See the STM32 Reference Manual for details.

Giovanni
omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Re: ICU driver and DMA ?

Post by omcdr »

My ICUConfig looks like:

Code: Select all

static ICUConfig icucfg = {
  ICU_INPUT_ACTIVE_HIGH,
  10000, 
  NULL,
  NULL,
  NULL,
  ICU_CHANNEL_2,
  TIM_DIER_CC2DE | TIM_DIER_TDE
};


Whether it is the correct configuration ?

And next I have arrray and dmaStreamAllocate, how tu enable DMA in circular mode (peripheral-to-memory)?

Code: Select all

  uint32_t samples[128];

  if (dmaStreamAllocate(STM32_DMA2_STREAM6, 0, NULL, NULL))
    chSysHalt("DMA already in use");
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU driver and DMA ?

Post by Giovanni »

Hi,

You can find an example of circular DMA in the ADC or I2S drivers

Giovanni
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: ICU driver and DMA ?

Post by alex31 »

Hello omcdr,

If you were able to achive ICU driver and DMA, it would be nice to post here a working snipset of your code, if it's possible for you.

It can help people not to reinvent wheel :-)

Alexandre
omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Re: ICU driver and DMA ?

Post by omcdr »

I don't have ICU with DMA.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: ICU driver and DMA ?

Post by alex31 »

Hi,

Finally, i took time to read TIM and DMA section of RM090, and using dma helper functions, was able to capture both width and period with DMA.

tips : need to use burst mode, which involve from TIM side, TIMx_DCR and TIMx_DMAR, explanations in RM090 are quite clear.

Since i am a teacher, and i plan to add DMA to my lectures, i think that right now, DMA API is a bit harsh.
(the class will be centered on this exercise : decoding an ADSB mode-S 112 bits frame) adsb mode s documentation

What about making DMA a first class citizen, and giving it a API like the other peripheral, with structure configuration, and a start, stop, startTransfert API ?

If this has a chance to get in ChibiOS in the future, i can work on it to propose a draft.

Albeit for teaching purpose, a simpler API could permit to chibios users to easily use DMA for peripheral that are not yet managed.

Alexandre
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU driver and DMA ?

Post by Giovanni »

Hi,

Problem is that DMA is very different on different MCUs, it would be hard to make a portable driver when you have to set very specific options.

Giovanni
Post Reply