dma modules

17

Upload: preston

Post on 24-Feb-2016

75 views

Category:

Documents


0 download

DESCRIPTION

DMA Modules. The STM32 has two DMA peripherals each of which has multiple inde - pendently configurable “channels” (7 for DMA1 and 5 for DMA2). A channel is roughly the hardware realization of a transaction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: DMA Modules
Page 2: DMA Modules

DMA Modules• The STM32 has two DMA peripherals each of which

has multiple inde- pendently configurable “channels” (7 for DMA1 and 5 for DMA2). A channel is roughly the hardware realization of a transaction.

• To initialize DMA be- tween a peripheral and memory it is necessary to configure the appropriate channel. For example, DMA1 channel 2 (3) can be used to receive (transmit) data from (to) SPI1.

Page 3: DMA Modules

DMA Settings

• Prior to utilizing the DMA peripherals, remember to enable their clocks

• Configuring a channel consists of setting appropriate parameters through a DMA_InitTypeDef structure

Page 4: DMA Modules

The parameters include the peripheral base address (e.g. ADC1->DR), the

memory address buffer, the transfer direction, the buffer size, etc. Once the

DMA channel is initialized, it must be enabled. The STM32 firmware provides

peripheral specific commands to enable a DMA transaction.

Page 5: DMA Modules

• DMA module must be activated in the module which uses DMA:

ADC_DMACmd(ADC1, ENABLE);ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);Or

The DMA channels provided by the STM32 are each associated with

specific peripherals (See reference manual for complete documentation).

For example DMA1 channel 1 supports ADC1, TIM2_CH3, and TIM4_CH1.

Page 6: DMA Modules

DAC Module• The DAC module is a 12-bit, voltage output digital-to-

analog converter. • The DAC can be configured in 8- or 12-bit mode and

may be used in conjunction with the DMA controller. • The DAC has two output channels, each with its own

converter– DAC1 (pin PA4) and DAC2 (pin PA5) • In dual DAC channel mode, conversions could be done

independently or simultaneously when both channels are grouped together for synchronous update operations. An

• input reference pin, Vref+(shared with ADC) is available for better resolution.

Page 7: DMA Modules

Each channel has separate control

logic which is configured through a

single control register (CR). Data to be

converted by channel x are written to

data holding register (DHRx). In

response to a trigger event, DHRx is

transferred to the data output

register (DORx) and, after a settling

time, the corresponding analog value

appears at the output.

Page 8: DMA Modules

DAC Settings• The clock sources must be activated and the DAC (PA4 or

PA5) pin must be configured as “analog ”.•

Page 9: DMA Modules

• Once a DAC is initialized, data may be written using the following commands

Page 10: DMA Modules

DAC Functions (CMSIS)

Page 11: DMA Modules
Page 12: DMA Modules

Pulse Width Modulation

• PWM signal• Duty Cycle, freq.• Sinosoidal signal• Applications:– Servo driver– SMPS– etc.

Page 13: DMA Modules

Timer PWM Settings

Page 14: DMA Modules

The pulse- width pw (0..999) can be set with the following command.

The pulse- width pw (0..999) can be set with the

following command.

Page 15: DMA Modules

Test_dma_adc

• Configure ADC1 and ADC2 in simultaneous mode, Set the DMA2 to transfer the ADC results to a mem. region

• Configure TIM2-> update at 50 KHz• Configure the TIM2 output trigger so that it occurs on update

events: TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);• Change the trigger in the ADC initialization code: ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_T2_TRGO;

• Configure the NVIC to enable interrupt channel DMA_IRQn with the highest priority

• Write a suitable interrupt handler.

Page 16: DMA Modules

Test_dac

• Enable DAC_Channel_1• Set TIM2 interrupt 150 KHz• Configure the NVIC to enable interrupt

channel TIM2_IRQn with the highest priority• Write a suitable interrupt handler.

Page 17: DMA Modules

Test_dac_speech

• Homework