DMA transfer

DMA transfer1. Learning objectivesDMA principle2. Hardware Construction3. Experimental steps1. Open the SYSCONFIG configuration tool2. ADC parameter configuration3. DMA parameter configuration4. Write the program5. Compile4. Program Analysis5. Experimental phenomenon

1. Learning objectives

  1. Understand the basic knowledge of DMA.
  2. Learn the basic use of DMA and display the transmitted ADC data on the serial port assistant.

DMA principle

DMA (Direct Memory Access) is a technology used in computer systems that allows peripherals to directly access memory without having to go through the CPU to complete data transmission. It enables data to be exchanged efficiently between peripherals (such as ADC, DAC, memory, etc.) and memory, reducing the burden on the CPU and improving the overall performance of the system.

Principle:

2. Hardware Construction

The DMA controller of MSPM0G3507 has the following features:

By looking at TI's data sheet, in addition to the common address addressing mode between memory and peripherals, the DMA function also provides two expansion modes: Fill Mode and Table Mode. DMA channels are divided into basic type and full-function type.

0

By looking at the data sheet, only the full-function type DMA channel supports repeated transfers, early interrupts, and extended modes. The basic function DMA channel supports basic data transfers and interrupts, but is sufficient to meet simple data transfer requirements.

The DMA of the MSPM0G3507 supports four transfer modes, and each channel can configure its transfer mode separately. For example, channel 0 can be configured as a single word or single byte transfer mode, while channel 1 is configured as a block transfer mode, and channel 2 uses a repeated block transfer mode. The transfer mode is configured independently of the addressing mode. Any addressing mode can be used with any transfer mode. Three types of data can be transferred, which can be selected by the .srcWidth and .destWidth control bits. The source and destination locations can be byte, short word, or word data. It also supports transfers in byte-to-byte, short word-to-short word, word-to-word, or any combination. As follows:

Based on these three modes, MSPM0G3507 provides 6 addressing modes,

Fixed address to fixed address:

img

Fixed address to block of address :

img

Block of address to fixed address:

img

Block of address to block of address:

img

Fill data to block of address:

img

Data table to specific address:

img

3. Experimental steps

In this case, ADC will be used to collect the voltage of the PA27 pin, and the data collected by ADC will be directly moved to the specified address through DMA.

1. Open the SYSCONFIG configuration tool

Open the blank project empty in the SDK in KEIL.

image-20241118204605335

Select and open, open the empty.syscfg file in the keil interface, When the empty.syscfg file is open, select Open the SYSCONFIG GUI interface in the Tools column.

image-20241118204833195

2. ADC parameter configuration

The ADC configuration here is the same as the ADC acquisition case.

Configure the resolution and interrupt of the ADC. This case does not use interrupts, so do not select anything here.

image-20241121185733896

3. DMA parameter configuration

image-20241121190016120

Parameter description:

Configure DMA Trigger: Whether to enable the DMA configuration function, select Enable here.

Enable DMA Trigger: Enable DMA trigger.

DMA Samples Count: DMA sample count. Set to 1.

Enable DMA Triggers: DMA trigger mode. Configured as MEM0 result loaded interrupt ADC result register 0 is loaded interrupt.

Address Mode: DMA addressing mode. Configured as Fixed addr. to Block addr. Fixed address to data block address.

Source Length: Data width of source address. Configured as Half Word (2 Bytes) Data width 2 bytes.

Destination Length: Data width configuration of destination address. Same as above.

Destination Address Direction: Destination address direction. Select Increment to enable increment of data block address.

Configure Transfer size: Whether to configure the amount of data to be transferred. Select Enable here.

Transfer Size: The amount of data to be transferred. Configured as 10, the amount of data transferred in one data block is 10 numbers.

Transfer Mode: DMA transfer mode. Configure to Repeat Single to repeat a single transfer.

Source Address Increment: Whether the source address is incremented. Not enabled.

Destination Address Increment: Whether the destination address is incremented. Not enabled.

Enable Channel Interrupt: Whether to enable DMA channel interrupt. Not enabled.

Click SAVE to save the configuration in SYSCONFIG, then close SYSCONFIG and return to keil.

image-20241119193346732

Select Yes to All in the pop-up window

image-20241119143728060

Similarly, we also need to confirm whether the ti_msp_dl_config.c and ti_msp_dl_config.h files are updated. Compile directly, and the compilation will automatically update to keil. If there is no update, we can also copy the file content in SYSCONFIG.

4. Write the program

In the empty.c file, write the following code

5. Compile

Click the Rebuild icon. The following prompt appears, indicating that the compilation is complete and there are no errors.

image-20241119150803274

image-20241119150902489

4. Program Analysis

This function filters by accumulating the data in the ADC_VALUE array and calculating the average value. This can reduce the noise of a single ADC sampling. number is the number of samples, usually set to 10 or more to improve the stability of the data.

Call SYSCFG_DL_init() function to initialize the system, clear and enable serial port interrupt for serial port data transmission. Set DMA source address to ADC0->ULLMEM.MEMRES[0], which stores ADC conversion results. Set DMA destination address to ADC_VALUE[0], and store DMA results in this array. Enable DMA channel and start ADC conversion. Get 10 ADC sampling results through adc_getValue(10) and perform mean filtering to return a stable ADC value. Convert ADC value to voltage value, assuming ADC has 12-bit resolution (4095 is the maximum value), and convert it to voltage value in the range of 0-3.3V.

5. Experimental phenomenon

After the program is downloaded, configure the serial port assistant as shown below, adjust the potentiometer knob, output voltage to PA27 pin, and after ADC loads data acquisition into ADC result register 0, DMA is triggered, and DMA will move data to memory variable ADC_VALUE. Data can be obtained by directly calling ADC_VALUE.

image-20241121194011058